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
96 #endif /* HAVE_UNISTD_H */
102 #include <gst/net/gstnet.h>
103 #include <gst/sdp/gstsdpmessage.h>
104 #include <gst/sdp/gstmikey.h>
105 #include <gst/rtp/rtp.h>
107 #include "gst/gst-i18n-plugin.h"
109 #include "gstrtspsrc.h"
111 GST_DEBUG_CATEGORY_STATIC (rtspsrc_debug);
112 #define GST_CAT_DEFAULT (rtspsrc_debug)
114 static GstStaticPadTemplate rtptemplate = GST_STATIC_PAD_TEMPLATE ("stream_%u",
117 GST_STATIC_CAPS ("application/x-rtp; application/x-rdt"));
119 /* templates used internally */
120 static GstStaticPadTemplate anysrctemplate =
121 GST_STATIC_PAD_TEMPLATE ("internalsrc_%u",
124 GST_STATIC_CAPS_ANY);
126 static GstStaticPadTemplate anysinktemplate =
127 GST_STATIC_PAD_TEMPLATE ("internalsink_%u",
130 GST_STATIC_CAPS_ANY);
134 SIGNAL_HANDLE_REQUEST,
136 SIGNAL_SELECT_STREAM,
138 SIGNAL_REQUEST_RTCP_KEY,
139 SIGNAL_ACCEPT_CERTIFICATE,
141 SIGNAL_PUSH_BACKCHANNEL_BUFFER,
142 SIGNAL_GET_PARAMETER,
143 SIGNAL_GET_PARAMETERS,
144 SIGNAL_SET_PARAMETER,
148 enum _GstRtspSrcRtcpSyncMode
155 enum _GstRtspSrcBufferMode
164 #define GST_TYPE_RTSP_SRC_BUFFER_MODE (gst_rtsp_src_buffer_mode_get_type())
166 gst_rtsp_src_buffer_mode_get_type (void)
168 static GType buffer_mode_type = 0;
169 static const GEnumValue buffer_modes[] = {
170 {BUFFER_MODE_NONE, "Only use RTP timestamps", "none"},
171 {BUFFER_MODE_SLAVE, "Slave receiver to sender clock", "slave"},
172 {BUFFER_MODE_BUFFER, "Do low/high watermark buffering", "buffer"},
173 {BUFFER_MODE_AUTO, "Choose mode depending on stream live", "auto"},
174 {BUFFER_MODE_SYNCED, "Synchronized sender and receiver clocks", "synced"},
178 if (!buffer_mode_type) {
180 g_enum_register_static ("GstRTSPSrcBufferMode", buffer_modes);
182 return buffer_mode_type;
185 enum _GstRtspSrcNtpTimeSource
188 NTP_TIME_SOURCE_UNIX,
189 NTP_TIME_SOURCE_RUNNING_TIME,
190 NTP_TIME_SOURCE_CLOCK_TIME
193 #define DEBUG_RTSP(__self,msg) gst_rtspsrc_print_rtsp_message (__self, msg)
194 #define DEBUG_SDP(__self,msg) gst_rtspsrc_print_sdp_message (__self, msg)
196 #define GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE (gst_rtsp_src_ntp_time_source_get_type())
198 gst_rtsp_src_ntp_time_source_get_type (void)
200 static GType ntp_time_source_type = 0;
201 static const GEnumValue ntp_time_source_values[] = {
202 {NTP_TIME_SOURCE_NTP, "NTP time based on realtime clock", "ntp"},
203 {NTP_TIME_SOURCE_UNIX, "UNIX time based on realtime clock", "unix"},
204 {NTP_TIME_SOURCE_RUNNING_TIME,
205 "Running time based on pipeline clock",
207 {NTP_TIME_SOURCE_CLOCK_TIME, "Pipeline clock time", "clock-time"},
211 if (!ntp_time_source_type) {
212 ntp_time_source_type =
213 g_enum_register_static ("GstRTSPSrcNtpTimeSource",
214 ntp_time_source_values);
216 return ntp_time_source_type;
219 enum _GstRtspBackchannel
225 #define GST_TYPE_RTSP_BACKCHANNEL (gst_rtsp_backchannel_get_type())
227 gst_rtsp_backchannel_get_type (void)
229 static GType backchannel_type = 0;
230 static const GEnumValue backchannel_values[] = {
231 {BACKCHANNEL_NONE, "No backchannel", "none"},
232 {BACKCHANNEL_ONVIF, "ONVIF audio backchannel", "onvif"},
236 if (G_UNLIKELY (backchannel_type == 0)) {
238 g_enum_register_static ("GstRTSPBackchannel", backchannel_values);
240 return backchannel_type;
243 #define BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL "www.onvif.org/ver20/backchannel"
245 #define DEFAULT_LOCATION NULL
246 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP
247 #define DEFAULT_DEBUG FALSE
248 #define DEFAULT_RETRY 20
249 #define DEFAULT_TIMEOUT 5000000
250 #define DEFAULT_UDP_BUFFER_SIZE 0x80000
251 #define DEFAULT_TCP_TIMEOUT 20000000
252 #define DEFAULT_LATENCY_MS 2000
253 #define DEFAULT_DROP_ON_LATENCY FALSE
254 #define DEFAULT_CONNECTION_SPEED 0
255 #define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY
256 #define DEFAULT_DO_RTCP TRUE
257 #define DEFAULT_DO_RTSP_KEEP_ALIVE TRUE
258 #define DEFAULT_PROXY NULL
259 #define DEFAULT_RTP_BLOCKSIZE 0
260 #define DEFAULT_USER_ID NULL
261 #define DEFAULT_USER_PW NULL
262 #define DEFAULT_BUFFER_MODE BUFFER_MODE_AUTO
263 #define DEFAULT_PORT_RANGE NULL
264 #define DEFAULT_SHORT_HEADER FALSE
265 #define DEFAULT_PROBATION 2
266 #define DEFAULT_UDP_RECONNECT TRUE
267 #define DEFAULT_MULTICAST_IFACE NULL
268 #define DEFAULT_NTP_SYNC FALSE
269 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
270 #define DEFAULT_TLS_VALIDATION_FLAGS G_TLS_CERTIFICATE_VALIDATE_ALL
271 #define DEFAULT_TLS_DATABASE NULL
272 #define DEFAULT_TLS_INTERACTION NULL
273 #define DEFAULT_DO_RETRANSMISSION TRUE
274 #define DEFAULT_NTP_TIME_SOURCE NTP_TIME_SOURCE_NTP
275 #define DEFAULT_USER_AGENT "GStreamer/" PACKAGE_VERSION
276 #define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
277 #define DEFAULT_RFC7273_SYNC FALSE
278 #define DEFAULT_MAX_TS_OFFSET_ADJUSTMENT G_GUINT64_CONSTANT(0)
279 #define DEFAULT_MAX_TS_OFFSET G_GINT64_CONSTANT(3000000000)
280 #define DEFAULT_VERSION GST_RTSP_VERSION_1_0
281 #define DEFAULT_BACKCHANNEL GST_RTSP_BACKCHANNEL_NONE
282 #define DEFAULT_TEARDOWN_TIMEOUT (100 * GST_MSECOND)
284 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
285 #define DEFAULT_START_POSITION 0
296 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
298 PROP_RESUME_POSITION,
302 PROP_DROP_ON_LATENCY,
303 PROP_CONNECTION_SPEED,
306 PROP_DO_RTSP_KEEP_ALIVE,
315 PROP_UDP_BUFFER_SIZE,
319 PROP_MULTICAST_IFACE,
321 PROP_USE_PIPELINE_CLOCK,
323 PROP_TLS_VALIDATION_FLAGS,
325 PROP_TLS_INTERACTION,
326 PROP_DO_RETRANSMISSION,
327 PROP_NTP_TIME_SOURCE,
329 PROP_MAX_RTCP_RTP_TIME_DIFF,
331 PROP_MAX_TS_OFFSET_ADJUSTMENT,
333 PROP_DEFAULT_VERSION,
335 PROP_TEARDOWN_TIMEOUT,
338 #define GST_TYPE_RTSP_NAT_METHOD (gst_rtsp_nat_method_get_type())
340 gst_rtsp_nat_method_get_type (void)
342 static GType rtsp_nat_method_type = 0;
343 static const GEnumValue rtsp_nat_method[] = {
344 {GST_RTSP_NAT_NONE, "None", "none"},
345 {GST_RTSP_NAT_DUMMY, "Send Dummy packets", "dummy"},
349 if (!rtsp_nat_method_type) {
350 rtsp_nat_method_type =
351 g_enum_register_static ("GstRTSPNatMethod", rtsp_nat_method);
353 return rtsp_nat_method_type;
356 #define RTSP_SRC_RESPONSE_ERROR(src, response_msg, err_cat, err_code, error_message) \
358 GST_ELEMENT_ERROR_WITH_DETAILS((src), err_cat, err_code, ("%s", error_message), \
359 ("%s (%d)", (response_msg)->type_data.response.reason, (response_msg)->type_data.response.code), \
360 ("rtsp-status-code", G_TYPE_UINT, (response_msg)->type_data.response.code, \
361 "rtsp-status-reason", G_TYPE_STRING, GST_STR_NULL((response_msg)->type_data.response.reason), NULL)); \
364 typedef struct _ParameterRequest
372 static void gst_rtspsrc_finalize (GObject * object);
374 static void gst_rtspsrc_set_property (GObject * object, guint prop_id,
375 const GValue * value, GParamSpec * pspec);
376 static void gst_rtspsrc_get_property (GObject * object, guint prop_id,
377 GValue * value, GParamSpec * pspec);
379 static GstClock *gst_rtspsrc_provide_clock (GstElement * element);
381 static void gst_rtspsrc_uri_handler_init (gpointer g_iface,
382 gpointer iface_data);
384 static gboolean gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy);
385 static void gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout);
387 static GstStateChangeReturn gst_rtspsrc_change_state (GstElement * element,
388 GstStateChange transition);
389 static gboolean gst_rtspsrc_send_event (GstElement * element, GstEvent * event);
390 static void gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message);
392 static gboolean gst_rtspsrc_setup_auth (GstRTSPSrc * src,
393 GstRTSPMessage * response);
395 static gboolean gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd,
397 static GstRTSPResult gst_rtspsrc_send_cb (GstRTSPExtension * ext,
398 GstRTSPMessage * request, GstRTSPMessage * response, GstRTSPSrc * src);
400 static GstRTSPResult gst_rtspsrc_open (GstRTSPSrc * src, gboolean async);
401 static GstRTSPResult gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment,
402 gboolean async, const gchar * seek_style);
403 static GstRTSPResult gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async);
404 static GstRTSPResult gst_rtspsrc_close (GstRTSPSrc * src, gboolean async,
405 gboolean only_close);
407 static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
408 const gchar * uri, GError ** error);
409 static gchar *gst_rtspsrc_uri_get_uri (GstURIHandler * handler);
411 static gboolean gst_rtspsrc_activate_streams (GstRTSPSrc * src);
412 static gboolean gst_rtspsrc_loop (GstRTSPSrc * src);
413 static gboolean gst_rtspsrc_stream_push_event (GstRTSPSrc * src,
414 GstRTSPStream * stream, GstEvent * event);
415 static gboolean gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event);
416 static void gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush);
417 static GstRTSPResult gst_rtsp_conninfo_close (GstRTSPSrc * src,
418 GstRTSPConnInfo * info, gboolean free);
420 gst_rtspsrc_print_rtsp_message (GstRTSPSrc * src, const GstRTSPMessage * msg);
422 gst_rtspsrc_print_sdp_message (GstRTSPSrc * src, const GstSDPMessage * msg);
425 gst_rtspsrc_get_parameter (GstRTSPSrc * src, ParameterRequest * req);
428 gst_rtspsrc_set_parameter (GstRTSPSrc * src, ParameterRequest * req);
430 static gboolean get_parameter (GstRTSPSrc * src, const gchar * parameter,
431 const gchar * content_type, GstPromise * promise);
433 static gboolean get_parameters (GstRTSPSrc * src, gchar ** parameters,
434 const gchar * content_type, GstPromise * promise);
436 static gboolean set_parameter (GstRTSPSrc * src, const gchar * name,
437 const gchar * value, const gchar * content_type, GstPromise * promise);
439 static GstFlowReturn gst_rtspsrc_push_backchannel_buffer (GstRTSPSrc * src,
440 guint id, GstSample * sample);
448 /* commands we send to out loop to notify it of events */
449 #define CMD_OPEN (1 << 0)
450 #define CMD_PLAY (1 << 1)
451 #define CMD_PAUSE (1 << 2)
452 #define CMD_CLOSE (1 << 3)
453 #define CMD_WAIT (1 << 4)
454 #define CMD_RECONNECT (1 << 5)
455 #define CMD_LOOP (1 << 6)
456 #define CMD_GET_PARAMETER (1 << 7)
457 #define CMD_SET_PARAMETER (1 << 8)
459 /* mask for all commands */
460 #define CMD_ALL ((CMD_SET_PARAMETER << 1) - 1)
462 #define GST_ELEMENT_PROGRESS(el, type, code, text) \
464 gchar *__txt = _gst_element_error_printf text; \
465 gst_element_post_message (GST_ELEMENT_CAST (el), \
466 gst_message_new_progress (GST_OBJECT_CAST (el), \
467 GST_PROGRESS_TYPE_ ##type, code, __txt)); \
471 static guint gst_rtspsrc_signals[LAST_SIGNAL] = { 0 };
473 #define gst_rtspsrc_parent_class parent_class
474 G_DEFINE_TYPE_WITH_CODE (GstRTSPSrc, gst_rtspsrc, GST_TYPE_BIN,
475 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_rtspsrc_uri_handler_init));
477 #ifndef GST_DISABLE_GST_DEBUG
478 static inline const char *
479 cmd_to_string (guint cmd)
496 case CMD_GET_PARAMETER:
497 return "GET_PARAMETER";
498 case CMD_SET_PARAMETER:
499 return "SET_PARAMETER";
506 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
508 gst_rtspsrc_post_error_message (GstRTSPSrc * src, GstRTSPSrcError error_id,
509 const gchar * error_string)
512 GstStructure *structure;
515 GST_ERROR_OBJECT (src, "[%d] %s", error_id, error_string);
517 structure = gst_structure_new ("streaming_error",
518 "error_id", G_TYPE_UINT, error_id,
519 "error_string", G_TYPE_STRING, error_string, NULL);
522 gst_message_new_custom (GST_MESSAGE_ERROR, GST_OBJECT (src), structure);
524 ret = gst_element_post_message (GST_ELEMENT (src), message);
526 GST_ERROR_OBJECT (src, "fail to post error message.");
533 default_select_stream (GstRTSPSrc * src, guint id, GstCaps * caps)
535 GST_DEBUG_OBJECT (src, "default handler");
540 select_stream_accum (GSignalInvocationHint * ihint,
541 GValue * return_accu, const GValue * handler_return, gpointer data)
545 myboolean = g_value_get_boolean (handler_return);
546 GST_DEBUG ("accum %d", myboolean);
547 g_value_set_boolean (return_accu, myboolean);
549 /* stop emission if FALSE */
554 default_before_send (GstRTSPSrc * src, GstRTSPMessage * msg)
556 GST_DEBUG_OBJECT (src, "default handler");
561 before_send_accum (GSignalInvocationHint * ihint,
562 GValue * return_accu, const GValue * handler_return, gpointer data)
566 myboolean = g_value_get_boolean (handler_return);
567 g_value_set_boolean (return_accu, myboolean);
569 /* prevent send if FALSE */
574 gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
576 GObjectClass *gobject_class;
577 GstElementClass *gstelement_class;
578 GstBinClass *gstbin_class;
580 gobject_class = (GObjectClass *) klass;
581 gstelement_class = (GstElementClass *) klass;
582 gstbin_class = (GstBinClass *) klass;
584 GST_DEBUG_CATEGORY_INIT (rtspsrc_debug, "rtspsrc", 0, "RTSP src");
586 gobject_class->set_property = gst_rtspsrc_set_property;
587 gobject_class->get_property = gst_rtspsrc_get_property;
589 gobject_class->finalize = gst_rtspsrc_finalize;
591 g_object_class_install_property (gobject_class, PROP_LOCATION,
592 g_param_spec_string ("location", "RTSP Location",
593 "Location of the RTSP url to read",
594 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
596 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
597 g_param_spec_flags ("protocols", "Protocols",
598 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
599 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
601 g_object_class_install_property (gobject_class, PROP_DEBUG,
602 g_param_spec_boolean ("debug", "Debug",
603 "Dump request and response messages to stdout"
604 "(DEPRECATED: Printed all RTSP message to gstreamer log as 'log' level)",
606 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
608 g_object_class_install_property (gobject_class, PROP_RETRY,
609 g_param_spec_uint ("retry", "Retry",
610 "Max number of retries when allocating RTP ports.",
611 0, G_MAXUINT16, DEFAULT_RETRY,
612 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
614 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
615 g_param_spec_uint64 ("timeout", "Timeout",
616 "Retry TCP transport after UDP timeout microseconds (0 = disabled)",
617 0, G_MAXUINT64, DEFAULT_TIMEOUT,
618 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
619 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
620 g_object_class_install_property (gobject_class, PROP_START_POSITION,
621 g_param_spec_uint64 ("pending-start-position", "set start position",
622 "Set start position before PLAYING request.",
623 0, G_MAXUINT64, DEFAULT_START_POSITION,
624 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
625 g_object_class_install_property (gobject_class, PROP_RESUME_POSITION,
626 g_param_spec_uint64 ("resume-position", "set resume position",
627 "Set resume position before PLAYING request after pause.",
628 0, G_MAXUINT64, DEFAULT_START_POSITION,
629 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
631 g_object_class_install_property (gobject_class, PROP_TCP_TIMEOUT,
632 g_param_spec_uint64 ("tcp-timeout", "TCP Timeout",
633 "Fail after timeout microseconds on TCP connections (0 = disabled)",
634 0, G_MAXUINT64, DEFAULT_TCP_TIMEOUT,
635 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
637 g_object_class_install_property (gobject_class, PROP_LATENCY,
638 g_param_spec_uint ("latency", "Buffer latency in ms",
639 "Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS,
640 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
642 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
643 g_param_spec_boolean ("drop-on-latency",
644 "Drop buffers when maximum latency is reached",
645 "Tells the jitterbuffer to never exceed the given latency in size",
646 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
648 g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
649 g_param_spec_uint64 ("connection-speed", "Connection Speed",
650 "Network connection speed in kbps (0 = unknown)",
651 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
652 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
654 g_object_class_install_property (gobject_class, PROP_NAT_METHOD,
655 g_param_spec_enum ("nat-method", "NAT Method",
656 "Method to use for traversing firewalls and NAT",
657 GST_TYPE_RTSP_NAT_METHOD, DEFAULT_NAT_METHOD,
658 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
661 * GstRTSPSrc:do-rtcp:
663 * Enable RTCP support. Some old server don't like RTCP and then this property
664 * needs to be set to FALSE.
666 g_object_class_install_property (gobject_class, PROP_DO_RTCP,
667 g_param_spec_boolean ("do-rtcp", "Do RTCP",
668 "Send RTCP packets, disable for old incompatible server.",
669 DEFAULT_DO_RTCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
672 * GstRTSPSrc:do-rtsp-keep-alive:
674 * Enable RTSP keep alive support. Some old server don't like RTSP
675 * keep alive and then this property needs to be set to FALSE.
677 g_object_class_install_property (gobject_class, PROP_DO_RTSP_KEEP_ALIVE,
678 g_param_spec_boolean ("do-rtsp-keep-alive", "Do RTSP Keep Alive",
679 "Send RTSP keep alive packets, disable for old incompatible server.",
680 DEFAULT_DO_RTSP_KEEP_ALIVE,
681 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
686 * Set the proxy parameters. This has to be a string of the format
687 * [http://][user:passwd@]host[:port].
689 g_object_class_install_property (gobject_class, PROP_PROXY,
690 g_param_spec_string ("proxy", "Proxy",
691 "Proxy settings for HTTP tunneling. Format: [http://][user:passwd@]host[:port]",
692 DEFAULT_PROXY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
694 * GstRTSPSrc:proxy-id:
696 * Sets the proxy URI user id for authentication. If the URI set via the
697 * "proxy" property contains a user-id already, that will take precedence.
701 g_object_class_install_property (gobject_class, PROP_PROXY_ID,
702 g_param_spec_string ("proxy-id", "proxy-id",
703 "HTTP proxy URI user id for authentication", "",
704 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
706 * GstRTSPSrc:proxy-pw:
708 * Sets the proxy URI password for authentication. If the URI set via the
709 * "proxy" property contains a password already, that will take precedence.
713 g_object_class_install_property (gobject_class, PROP_PROXY_PW,
714 g_param_spec_string ("proxy-pw", "proxy-pw",
715 "HTTP proxy URI user password for authentication", "",
716 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
719 * GstRTSPSrc:rtp-blocksize:
721 * RTP package size to suggest to server.
723 g_object_class_install_property (gobject_class, PROP_RTP_BLOCKSIZE,
724 g_param_spec_uint ("rtp-blocksize", "RTP Blocksize",
725 "RTP package size to suggest to server (0 = disabled)",
726 0, 65536, DEFAULT_RTP_BLOCKSIZE,
727 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
729 g_object_class_install_property (gobject_class,
731 g_param_spec_string ("user-id", "user-id",
732 "RTSP location URI user id for authentication", DEFAULT_USER_ID,
733 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
734 g_object_class_install_property (gobject_class, PROP_USER_PW,
735 g_param_spec_string ("user-pw", "user-pw",
736 "RTSP location URI user password for authentication", DEFAULT_USER_PW,
737 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
740 * GstRTSPSrc:buffer-mode:
742 * Control the buffering and timestamping mode used by the jitterbuffer.
744 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
745 g_param_spec_enum ("buffer-mode", "Buffer Mode",
746 "Control the buffering algorithm in use",
747 GST_TYPE_RTSP_SRC_BUFFER_MODE, DEFAULT_BUFFER_MODE,
748 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
751 * GstRTSPSrc:port-range:
753 * Configure the client port numbers that can be used to receive RTP and
756 g_object_class_install_property (gobject_class, PROP_PORT_RANGE,
757 g_param_spec_string ("port-range", "Port range",
758 "Client port range that can be used to receive RTP and RTCP data, "
759 "eg. 3000-3005 (NULL = no restrictions)", DEFAULT_PORT_RANGE,
760 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
763 * GstRTSPSrc:udp-buffer-size:
765 * Size of the kernel UDP receive buffer in bytes.
767 g_object_class_install_property (gobject_class, PROP_UDP_BUFFER_SIZE,
768 g_param_spec_int ("udp-buffer-size", "UDP Buffer Size",
769 "Size of the kernel UDP receive buffer in bytes, 0=default",
770 0, G_MAXINT, DEFAULT_UDP_BUFFER_SIZE,
771 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
774 * GstRTSPSrc:short-header:
776 * Only send the basic RTSP headers for broken encoders.
778 g_object_class_install_property (gobject_class, PROP_SHORT_HEADER,
779 g_param_spec_boolean ("short-header", "Short Header",
780 "Only send the basic RTSP headers for broken encoders",
781 DEFAULT_SHORT_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
783 g_object_class_install_property (gobject_class, PROP_PROBATION,
784 g_param_spec_uint ("probation", "Number of probations",
785 "Consecutive packet sequence numbers to accept the source",
786 0, G_MAXUINT, DEFAULT_PROBATION,
787 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
789 g_object_class_install_property (gobject_class, PROP_UDP_RECONNECT,
790 g_param_spec_boolean ("udp-reconnect", "Reconnect to the server",
791 "Reconnect to the server if RTSP connection is closed when doing UDP",
792 DEFAULT_UDP_RECONNECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
794 g_object_class_install_property (gobject_class, PROP_MULTICAST_IFACE,
795 g_param_spec_string ("multicast-iface", "Multicast Interface",
796 "The network interface on which to join the multicast group",
797 DEFAULT_MULTICAST_IFACE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
799 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
800 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
801 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
802 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
804 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
805 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
806 "Use the pipeline running-time to set the NTP time in the RTCP SR messages"
807 "(DEPRECATED: Use ntp-time-source property)",
808 DEFAULT_USE_PIPELINE_CLOCK,
809 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
811 g_object_class_install_property (gobject_class, PROP_SDES,
812 g_param_spec_boxed ("sdes", "SDES",
813 "The SDES items of this session",
814 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
817 * GstRTSPSrc::tls-validation-flags:
819 * TLS certificate validation flags used to validate server
824 g_object_class_install_property (gobject_class, PROP_TLS_VALIDATION_FLAGS,
825 g_param_spec_flags ("tls-validation-flags", "TLS validation flags",
826 "TLS certificate validation flags used to validate the server certificate",
827 G_TYPE_TLS_CERTIFICATE_FLAGS, DEFAULT_TLS_VALIDATION_FLAGS,
828 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
831 * GstRTSPSrc::tls-database:
833 * TLS database with anchor certificate authorities used to validate
834 * the server certificate.
838 g_object_class_install_property (gobject_class, PROP_TLS_DATABASE,
839 g_param_spec_object ("tls-database", "TLS database",
840 "TLS database with anchor certificate authorities used to validate the server certificate",
841 G_TYPE_TLS_DATABASE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
844 * GstRTSPSrc::tls-interaction:
846 * A #GTlsInteraction object to be used when the connection or certificate
847 * database need to interact with the user. This will be used to prompt the
848 * user for passwords where necessary.
852 g_object_class_install_property (gobject_class, PROP_TLS_INTERACTION,
853 g_param_spec_object ("tls-interaction", "TLS interaction",
854 "A GTlsInteraction object to promt the user for password or certificate",
855 G_TYPE_TLS_INTERACTION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
858 * GstRTSPSrc::do-retransmission:
860 * Attempt to ask the server to retransmit lost packets according to RFC4588.
862 * Note: currently only works with SSRC-multiplexed retransmission streams
866 g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
867 g_param_spec_boolean ("do-retransmission", "Retransmission",
868 "Ask the server to retransmit lost packets",
869 DEFAULT_DO_RETRANSMISSION,
870 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
873 * GstRTSPSrc::ntp-time-source:
875 * allows to select the time source that should be used
876 * for the NTP time in RTCP packets
880 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
881 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
882 "NTP time source for RTCP packets",
883 GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE, DEFAULT_NTP_TIME_SOURCE,
884 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
887 * GstRTSPSrc::user-agent:
889 * The string to set in the User-Agent header.
893 g_object_class_install_property (gobject_class, PROP_USER_AGENT,
894 g_param_spec_string ("user-agent", "User Agent",
895 "The User-Agent string to send to the server",
896 DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
898 g_object_class_install_property (gobject_class, PROP_MAX_RTCP_RTP_TIME_DIFF,
899 g_param_spec_int ("max-rtcp-rtp-time-diff", "Max RTCP RTP Time Diff",
900 "Maximum amount of time in ms that the RTP time in RTCP SRs "
901 "is allowed to be ahead (-1 disabled)", -1, G_MAXINT,
902 DEFAULT_MAX_RTCP_RTP_TIME_DIFF,
903 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
905 g_object_class_install_property (gobject_class, PROP_RFC7273_SYNC,
906 g_param_spec_boolean ("rfc7273-sync", "Sync on RFC7273 clock",
907 "Synchronize received streams to the RFC7273 clock "
908 "(requires clock and offset to be provided)", DEFAULT_RFC7273_SYNC,
909 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
912 * GstRTSPSrc:default-rtsp-version:
914 * The preferred RTSP version to use while negotiating the version with the server.
918 g_object_class_install_property (gobject_class, PROP_DEFAULT_VERSION,
919 g_param_spec_enum ("default-rtsp-version",
920 "The RTSP version to try first",
921 "The RTSP version that should be tried first when negotiating version.",
922 GST_TYPE_RTSP_VERSION, DEFAULT_VERSION,
923 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
926 * GstRTSPSrc:max-ts-offset-adjustment:
928 * Syncing time stamps to NTP time adds a time offset. This parameter
929 * specifies the maximum number of nanoseconds per frame that this time offset
930 * may be adjusted with. This is used to avoid sudden large changes to time
933 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET_ADJUSTMENT,
934 g_param_spec_uint64 ("max-ts-offset-adjustment",
935 "Max Timestamp Offset Adjustment",
936 "The maximum number of nanoseconds per frame that time stamp offsets "
937 "may be adjusted (0 = no limit).", 0, G_MAXUINT64,
938 DEFAULT_MAX_TS_OFFSET_ADJUSTMENT, G_PARAM_READWRITE |
939 G_PARAM_STATIC_STRINGS));
942 * GstRTSPSrc:max-ts-offset:
944 * Used to set an upper limit of how large a time offset may be. This
945 * is used to protect against unrealistic values as a result of either
946 * client,server or clock issues.
948 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET,
949 g_param_spec_int64 ("max-ts-offset", "Max TS Offset",
950 "The maximum absolute value of the time offset in (nanoseconds). "
951 "Note, if the ntp-sync parameter is set the default value is "
952 "changed to 0 (no limit)", 0, G_MAXINT64, DEFAULT_MAX_TS_OFFSET,
953 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
956 * GstRTSPSrc:backchannel
958 * Select a type of backchannel to setup with the RTSP server.
959 * Default value is "none". Allowed values are "none" and "onvif".
963 g_object_class_install_property (gobject_class, PROP_BACKCHANNEL,
964 g_param_spec_enum ("backchannel", "Backchannel type",
965 "The type of backchannel to setup. Default is 'none'.",
966 GST_TYPE_RTSP_BACKCHANNEL, BACKCHANNEL_NONE,
967 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
970 * GstRtspSrc:teardown-timeout
972 * When transitioning PAUSED-READY, allow up to timeout (in nanoseconds)
973 * delay in order to send teardown (0 = disabled)
977 g_object_class_install_property (gobject_class, PROP_TEARDOWN_TIMEOUT,
978 g_param_spec_uint64 ("teardown-timeout", "Teardown Timeout",
979 "When transitioning PAUSED-READY, allow up to timeout (in nanoseconds) "
980 "delay in order to send teardown (0 = disabled)",
981 0, G_MAXUINT64, DEFAULT_TEARDOWN_TIMEOUT,
982 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
985 * GstRTSPSrc::handle-request:
986 * @rtspsrc: a #GstRTSPSrc
987 * @request: a #GstRTSPMessage
988 * @response: a #GstRTSPMessage
990 * Handle a server request in @request and prepare @response.
992 * This signal is called from the streaming thread, you should therefore not
993 * do any state changes on @rtspsrc because this might deadlock. If you want
994 * to modify the state as a result of this signal, post a
995 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
1000 gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST] =
1001 g_signal_new ("handle-request", G_TYPE_FROM_CLASS (klass), 0,
1002 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2,
1003 G_TYPE_POINTER, G_TYPE_POINTER);
1006 * GstRTSPSrc::on-sdp:
1007 * @rtspsrc: a #GstRTSPSrc
1008 * @sdp: a #GstSDPMessage
1010 * Emitted when the client has retrieved the SDP and before it configures the
1011 * streams in the SDP. @sdp can be inspected and modified.
1013 * This signal is called from the streaming thread, you should therefore not
1014 * do any state changes on @rtspsrc because this might deadlock. If you want
1015 * to modify the state as a result of this signal, post a
1016 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
1017 * in some other way.
1021 gst_rtspsrc_signals[SIGNAL_ON_SDP] =
1022 g_signal_new ("on-sdp", G_TYPE_FROM_CLASS (klass), 0,
1023 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
1024 GST_TYPE_SDP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
1027 * GstRTSPSrc::select-stream:
1028 * @rtspsrc: a #GstRTSPSrc
1029 * @num: the stream number
1030 * @caps: the stream caps
1032 * Emitted before the client decides to configure the stream @num with
1035 * Returns: %TRUE when the stream should be selected, %FALSE when the stream
1040 gst_rtspsrc_signals[SIGNAL_SELECT_STREAM] =
1041 g_signal_new_class_handler ("select-stream", G_TYPE_FROM_CLASS (klass),
1042 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP,
1043 (GCallback) default_select_stream, select_stream_accum, NULL,
1044 g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 2, G_TYPE_UINT,
1047 * GstRTSPSrc::new-manager:
1048 * @rtspsrc: a #GstRTSPSrc
1049 * @manager: a #GstElement
1051 * Emitted after a new manager (like rtpbin) was created and the default
1052 * properties were configured.
1056 gst_rtspsrc_signals[SIGNAL_NEW_MANAGER] =
1057 g_signal_new_class_handler ("new-manager", G_TYPE_FROM_CLASS (klass),
1058 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP, 0, NULL, NULL,
1059 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
1062 * GstRTSPSrc::request-rtcp-key:
1063 * @rtspsrc: a #GstRTSPSrc
1064 * @num: the stream number
1066 * Signal emitted to get the crypto parameters relevant to the RTCP
1067 * stream. User should provide the key and the RTCP encryption ciphers
1068 * and authentication, and return them wrapped in a GstCaps.
1072 gst_rtspsrc_signals[SIGNAL_REQUEST_RTCP_KEY] =
1073 g_signal_new ("request-rtcp-key", G_TYPE_FROM_CLASS (klass),
1074 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, GST_TYPE_CAPS, 1, G_TYPE_UINT);
1077 * GstRTSPSrc::accept-certificate:
1078 * @rtspsrc: a #GstRTSPSrc
1079 * @peer_cert: the peer's #GTlsCertificate
1080 * @errors: the problems with @peer_cert
1081 * @user_data: user data set when the signal handler was connected.
1083 * This will directly map to #GTlsConnection 's "accept-certificate"
1084 * signal and be performed after the default checks of #GstRTSPConnection
1085 * (checking against the #GTlsDatabase with the given #GTlsCertificateFlags)
1086 * have failed. If no #GTlsDatabase is set on this connection, only this
1087 * signal will be emitted.
1091 gst_rtspsrc_signals[SIGNAL_ACCEPT_CERTIFICATE] =
1092 g_signal_new ("accept-certificate", G_TYPE_FROM_CLASS (klass),
1093 G_SIGNAL_RUN_LAST, 0, g_signal_accumulator_true_handled, NULL, NULL,
1094 G_TYPE_BOOLEAN, 3, G_TYPE_TLS_CONNECTION, G_TYPE_TLS_CERTIFICATE,
1095 G_TYPE_TLS_CERTIFICATE_FLAGS);
1098 * GstRTSPSrc::before-send
1099 * @rtspsrc: a #GstRTSPSrc
1100 * @num: the stream number
1102 * Emitted before each RTSP request is sent, in order to allow
1103 * the application to modify send parameters or to skip the message entirely.
1104 * This can be used, for example, to work with ONVIF Profile G servers,
1105 * which need a different/additional range, rate-control, and intra/x
1108 * Returns: %TRUE when the command should be sent, %FALSE when the
1109 * command should be dropped.
1113 gst_rtspsrc_signals[SIGNAL_BEFORE_SEND] =
1114 g_signal_new_class_handler ("before-send", G_TYPE_FROM_CLASS (klass),
1115 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP,
1116 (GCallback) default_before_send, before_send_accum, NULL,
1117 g_cclosure_marshal_generic, G_TYPE_BOOLEAN,
1118 1, GST_TYPE_RTSP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
1121 * GstRTSPSrc::push-backchannel-buffer:
1122 * @rtspsrc: a #GstRTSPSrc
1123 * @buffer: RTP buffer to send back
1127 gst_rtspsrc_signals[SIGNAL_PUSH_BACKCHANNEL_BUFFER] =
1128 g_signal_new ("push-backchannel-buffer", G_TYPE_FROM_CLASS (klass),
1129 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1130 push_backchannel_buffer), NULL, NULL, NULL, GST_TYPE_FLOW_RETURN, 2,
1131 G_TYPE_UINT, GST_TYPE_BUFFER);
1134 * GstRTSPSrc::get-parameter:
1135 * @rtspsrc: a #GstRTSPSrc
1136 * @parameter: the parameter name
1137 * @parameter: the content type
1138 * @parameter: a pointer to #GstPromise
1140 * Handle the GET_PARAMETER signal.
1142 * Returns: %TRUE when the command could be issued, %FALSE otherwise
1145 gst_rtspsrc_signals[SIGNAL_GET_PARAMETER] =
1146 g_signal_new ("get-parameter", G_TYPE_FROM_CLASS (klass),
1147 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1148 get_parameter), NULL, NULL, g_cclosure_marshal_generic,
1149 G_TYPE_BOOLEAN, 3, G_TYPE_STRING, G_TYPE_STRING, GST_TYPE_PROMISE);
1152 * GstRTSPSrc::get-parameters:
1153 * @rtspsrc: a #GstRTSPSrc
1154 * @parameter: a NULL-terminated array of parameters
1155 * @parameter: the content type
1156 * @parameter: a pointer to #GstPromise
1158 * Handle the GET_PARAMETERS signal.
1160 * Returns: %TRUE when the command could be issued, %FALSE otherwise
1163 gst_rtspsrc_signals[SIGNAL_GET_PARAMETERS] =
1164 g_signal_new ("get-parameters", G_TYPE_FROM_CLASS (klass),
1165 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1166 get_parameters), NULL, NULL, g_cclosure_marshal_generic,
1167 G_TYPE_BOOLEAN, 3, G_TYPE_STRV, G_TYPE_STRING, GST_TYPE_PROMISE);
1170 * GstRTSPSrc::set-parameter:
1171 * @rtspsrc: a #GstRTSPSrc
1172 * @parameter: the parameter name
1173 * @parameter: the parameter value
1174 * @parameter: the content type
1175 * @parameter: a pointer to #GstPromise
1177 * Handle the SET_PARAMETER signal.
1179 * Returns: %TRUE when the command could be issued, %FALSE otherwise
1182 gst_rtspsrc_signals[SIGNAL_SET_PARAMETER] =
1183 g_signal_new ("set-parameter", G_TYPE_FROM_CLASS (klass),
1184 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1185 set_parameter), NULL, NULL, g_cclosure_marshal_generic,
1186 G_TYPE_BOOLEAN, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1189 gstelement_class->send_event = gst_rtspsrc_send_event;
1190 gstelement_class->provide_clock = gst_rtspsrc_provide_clock;
1191 gstelement_class->change_state = gst_rtspsrc_change_state;
1193 gst_element_class_add_static_pad_template (gstelement_class, &rtptemplate);
1195 gst_element_class_set_static_metadata (gstelement_class,
1196 "RTSP packet receiver", "Source/Network",
1197 "Receive data over the network via RTSP (RFC 2326)",
1198 "Wim Taymans <wim@fluendo.com>, "
1199 "Thijs Vermeir <thijs.vermeir@barco.com>, "
1200 "Lutz Mueller <lutz@topfrose.de>");
1202 gstbin_class->handle_message = gst_rtspsrc_handle_message;
1204 klass->push_backchannel_buffer = gst_rtspsrc_push_backchannel_buffer;
1205 klass->get_parameter = GST_DEBUG_FUNCPTR (get_parameter);
1206 klass->get_parameters = GST_DEBUG_FUNCPTR (get_parameters);
1207 klass->set_parameter = GST_DEBUG_FUNCPTR (set_parameter);
1209 gst_rtsp_ext_list_init ();
1213 validate_set_get_parameter_name (const gchar * parameter_name)
1215 gchar *ptr = (gchar *) parameter_name;
1218 /* Don't allow '\r', '\n', \'t', ' ' etc in the parameter name */
1219 if (g_ascii_isspace (*ptr) || g_ascii_iscntrl (*ptr)) {
1220 GST_DEBUG ("invalid parameter name '%s'", parameter_name);
1229 validate_set_get_parameters (gchar ** parameter_names)
1231 while (*parameter_names) {
1232 if (!validate_set_get_parameter_name (*parameter_names)) {
1241 get_parameter (GstRTSPSrc * src, const gchar * parameter,
1242 const gchar * content_type, GstPromise * promise)
1244 gchar *parameters[] = { (gchar *) parameter, NULL };
1246 GST_LOG_OBJECT (src, "get_parameter: %s", GST_STR_NULL (parameter));
1248 if (parameter == NULL || parameter[0] == '\0' || promise == NULL) {
1249 GST_DEBUG ("invalid input");
1253 return get_parameters (src, parameters, content_type, promise);
1257 get_parameters (GstRTSPSrc * src, gchar ** parameters,
1258 const gchar * content_type, GstPromise * promise)
1260 ParameterRequest *req;
1262 GST_LOG_OBJECT (src, "get_parameters: %d", g_strv_length (parameters));
1264 if (parameters == NULL || promise == NULL) {
1265 GST_DEBUG ("invalid input");
1269 if (src->state == GST_RTSP_STATE_INVALID) {
1270 GST_DEBUG ("invalid state");
1274 if (!validate_set_get_parameters (parameters)) {
1278 req = g_new0 (ParameterRequest, 1);
1279 req->promise = gst_promise_ref (promise);
1280 req->cmd = CMD_GET_PARAMETER;
1281 /* Set the request body according to RFC 2326 or RFC 7826 */
1282 req->body = g_string_new (NULL);
1283 while (*parameters) {
1284 g_string_append_printf (req->body, "%s:\r\n", *parameters);
1288 req->content_type = g_strdup (content_type);
1290 GST_OBJECT_LOCK (src);
1291 g_queue_push_tail (&src->set_get_param_q, req);
1292 GST_OBJECT_UNLOCK (src);
1294 gst_rtspsrc_loop_send_cmd (src, CMD_GET_PARAMETER, CMD_LOOP);
1300 set_parameter (GstRTSPSrc * src, const gchar * name, const gchar * value,
1301 const gchar * content_type, GstPromise * promise)
1303 ParameterRequest *req;
1305 GST_LOG_OBJECT (src, "set_parameter: %s: %s", GST_STR_NULL (name),
1306 GST_STR_NULL (value));
1308 if (name == NULL || name[0] == '\0' || value == NULL || promise == NULL) {
1309 GST_DEBUG ("invalid input");
1313 if (src->state == GST_RTSP_STATE_INVALID) {
1314 GST_DEBUG ("invalid state");
1318 if (!validate_set_get_parameter_name (name)) {
1322 req = g_new0 (ParameterRequest, 1);
1323 req->cmd = CMD_SET_PARAMETER;
1324 req->promise = gst_promise_ref (promise);
1325 req->body = g_string_new (NULL);
1326 /* Set the request body according to RFC 2326 or RFC 7826 */
1327 g_string_append_printf (req->body, "%s: %s\r\n", name, value);
1329 req->content_type = g_strdup (content_type);
1331 GST_OBJECT_LOCK (src);
1332 g_queue_push_tail (&src->set_get_param_q, req);
1333 GST_OBJECT_UNLOCK (src);
1335 gst_rtspsrc_loop_send_cmd (src, CMD_SET_PARAMETER, CMD_LOOP);
1341 gst_rtspsrc_init (GstRTSPSrc * src)
1343 src->conninfo.location = g_strdup (DEFAULT_LOCATION);
1344 src->protocols = DEFAULT_PROTOCOLS;
1345 src->debug = DEFAULT_DEBUG;
1346 src->retry = DEFAULT_RETRY;
1347 src->udp_timeout = DEFAULT_TIMEOUT;
1348 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1349 src->start_position = DEFAULT_START_POSITION;
1350 src->is_audio_codec_supported = FALSE;
1351 src->is_video_codec_supported = FALSE;
1352 src->audio_codec = NULL;
1353 src->video_codec = NULL;
1354 src->video_frame_size = NULL;
1356 gst_rtspsrc_set_tcp_timeout (src, DEFAULT_TCP_TIMEOUT);
1357 src->latency = DEFAULT_LATENCY_MS;
1358 src->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
1359 src->connection_speed = DEFAULT_CONNECTION_SPEED;
1360 src->nat_method = DEFAULT_NAT_METHOD;
1361 src->do_rtcp = DEFAULT_DO_RTCP;
1362 src->do_rtsp_keep_alive = DEFAULT_DO_RTSP_KEEP_ALIVE;
1363 gst_rtspsrc_set_proxy (src, DEFAULT_PROXY);
1364 src->rtp_blocksize = DEFAULT_RTP_BLOCKSIZE;
1365 src->user_id = g_strdup (DEFAULT_USER_ID);
1366 src->user_pw = g_strdup (DEFAULT_USER_PW);
1367 src->buffer_mode = DEFAULT_BUFFER_MODE;
1368 src->client_port_range.min = 0;
1369 src->client_port_range.max = 0;
1370 src->udp_buffer_size = DEFAULT_UDP_BUFFER_SIZE;
1371 src->short_header = DEFAULT_SHORT_HEADER;
1372 src->probation = DEFAULT_PROBATION;
1373 src->udp_reconnect = DEFAULT_UDP_RECONNECT;
1374 src->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
1375 src->ntp_sync = DEFAULT_NTP_SYNC;
1376 src->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
1378 src->tls_validation_flags = DEFAULT_TLS_VALIDATION_FLAGS;
1379 src->tls_database = DEFAULT_TLS_DATABASE;
1380 src->tls_interaction = DEFAULT_TLS_INTERACTION;
1381 src->do_retransmission = DEFAULT_DO_RETRANSMISSION;
1382 src->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
1383 src->user_agent = g_strdup (DEFAULT_USER_AGENT);
1384 src->max_rtcp_rtp_time_diff = DEFAULT_MAX_RTCP_RTP_TIME_DIFF;
1385 src->rfc7273_sync = DEFAULT_RFC7273_SYNC;
1386 src->max_ts_offset_adjustment = DEFAULT_MAX_TS_OFFSET_ADJUSTMENT;
1387 src->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
1388 src->max_ts_offset_is_set = FALSE;
1389 src->default_version = DEFAULT_VERSION;
1390 src->version = GST_RTSP_VERSION_INVALID;
1391 src->teardown_timeout = DEFAULT_TEARDOWN_TIMEOUT;
1393 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1394 g_mutex_init (&(src)->pause_lock);
1395 g_cond_init (&(src)->open_end);
1397 /* get a list of all extensions */
1398 src->extensions = gst_rtsp_ext_list_get ();
1400 /* connect to send signal */
1401 gst_rtsp_ext_list_connect (src->extensions, "send",
1402 (GCallback) gst_rtspsrc_send_cb, src);
1404 /* protects the streaming thread in interleaved mode or the polling
1405 * thread in UDP mode. */
1406 g_rec_mutex_init (&src->stream_rec_lock);
1408 /* protects our state changes from multiple invocations */
1409 g_rec_mutex_init (&src->state_rec_lock);
1411 g_queue_init (&src->set_get_param_q);
1413 src->state = GST_RTSP_STATE_INVALID;
1415 g_mutex_init (&src->conninfo.send_lock);
1416 g_mutex_init (&src->conninfo.recv_lock);
1417 g_cond_init (&src->cmd_cond);
1419 GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
1420 gst_bin_set_suppressed_flags (GST_BIN (src),
1421 GST_ELEMENT_FLAG_SOURCE | GST_ELEMENT_FLAG_SINK);
1425 free_param_data (ParameterRequest * req)
1427 gst_promise_unref (req->promise);
1429 g_string_free (req->body, TRUE);
1430 g_free (req->content_type);
1435 free_param_queue (gpointer data)
1437 ParameterRequest *req = data;
1439 gst_promise_expire (req->promise);
1440 free_param_data (req);
1444 gst_rtspsrc_finalize (GObject * object)
1446 GstRTSPSrc *rtspsrc;
1448 rtspsrc = GST_RTSPSRC (object);
1450 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1451 rtspsrc->is_audio_codec_supported = FALSE;
1452 rtspsrc->is_video_codec_supported = FALSE;
1453 if (rtspsrc->audio_codec) {
1454 g_free (rtspsrc->audio_codec);
1455 rtspsrc->audio_codec = NULL;
1457 if (rtspsrc->video_codec) {
1458 g_free (rtspsrc->video_codec);
1459 rtspsrc->video_codec = NULL;
1461 if (rtspsrc->video_frame_size) {
1462 g_free (rtspsrc->video_frame_size);
1463 rtspsrc->video_frame_size = NULL;
1466 gst_rtsp_ext_list_free (rtspsrc->extensions);
1467 g_free (rtspsrc->conninfo.location);
1468 gst_rtsp_url_free (rtspsrc->conninfo.url);
1469 g_free (rtspsrc->conninfo.url_str);
1470 g_free (rtspsrc->user_id);
1471 g_free (rtspsrc->user_pw);
1472 g_free (rtspsrc->multi_iface);
1473 g_free (rtspsrc->user_agent);
1475 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1476 g_mutex_clear (&(rtspsrc)->pause_lock);
1477 g_cond_clear (&(rtspsrc)->open_end);
1481 gst_sdp_message_free (rtspsrc->sdp);
1482 rtspsrc->sdp = NULL;
1484 if (rtspsrc->provided_clock)
1485 gst_object_unref (rtspsrc->provided_clock);
1488 gst_structure_free (rtspsrc->sdes);
1490 if (rtspsrc->tls_database)
1491 g_object_unref (rtspsrc->tls_database);
1493 if (rtspsrc->tls_interaction)
1494 g_object_unref (rtspsrc->tls_interaction);
1497 g_rec_mutex_clear (&rtspsrc->stream_rec_lock);
1498 g_rec_mutex_clear (&rtspsrc->state_rec_lock);
1500 g_mutex_clear (&rtspsrc->conninfo.send_lock);
1501 g_mutex_clear (&rtspsrc->conninfo.recv_lock);
1502 g_cond_clear (&rtspsrc->cmd_cond);
1504 G_OBJECT_CLASS (parent_class)->finalize (object);
1508 gst_rtspsrc_provide_clock (GstElement * element)
1510 GstRTSPSrc *src = GST_RTSPSRC (element);
1513 if ((clock = src->provided_clock) != NULL)
1514 return gst_object_ref (clock);
1516 return GST_ELEMENT_CLASS (parent_class)->provide_clock (element);
1519 /* a proxy string of the format [user:passwd@]host[:port] */
1521 gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy)
1523 gchar *p, *at, *col;
1525 g_free (rtsp->proxy_user);
1526 rtsp->proxy_user = NULL;
1527 g_free (rtsp->proxy_passwd);
1528 rtsp->proxy_passwd = NULL;
1529 g_free (rtsp->proxy_host);
1530 rtsp->proxy_host = NULL;
1531 rtsp->proxy_port = 0;
1533 p = (gchar *) proxy;
1538 /* we allow http:// in front but ignore it */
1539 if (g_str_has_prefix (p, "http://"))
1542 at = strchr (p, '@');
1544 /* look for user:passwd */
1545 col = strchr (proxy, ':');
1546 if (col == NULL || col > at)
1549 rtsp->proxy_user = g_strndup (p, col - p);
1551 rtsp->proxy_passwd = g_strndup (col, at - col);
1556 if (rtsp->prop_proxy_id != NULL && *rtsp->prop_proxy_id != '\0')
1557 rtsp->proxy_user = g_strdup (rtsp->prop_proxy_id);
1558 if (rtsp->prop_proxy_pw != NULL && *rtsp->prop_proxy_pw != '\0')
1559 rtsp->proxy_passwd = g_strdup (rtsp->prop_proxy_pw);
1560 if (rtsp->proxy_user != NULL || rtsp->proxy_passwd != NULL) {
1561 GST_LOG_OBJECT (rtsp, "set proxy user/pw from properties: %s:%s",
1562 GST_STR_NULL (rtsp->proxy_user), GST_STR_NULL (rtsp->proxy_passwd));
1565 col = strchr (p, ':');
1568 /* everything before the colon is the hostname */
1569 rtsp->proxy_host = g_strndup (p, col - p);
1571 rtsp->proxy_port = strtoul (p, (char **) &p, 10);
1573 rtsp->proxy_host = g_strdup (p);
1574 rtsp->proxy_port = 8080;
1580 gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout)
1582 rtspsrc->tcp_timeout.tv_sec = timeout / G_USEC_PER_SEC;
1583 rtspsrc->tcp_timeout.tv_usec = timeout % G_USEC_PER_SEC;
1586 rtspsrc->ptcp_timeout = &rtspsrc->tcp_timeout;
1588 rtspsrc->ptcp_timeout = NULL;
1592 gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
1595 GstRTSPSrc *rtspsrc;
1597 rtspsrc = GST_RTSPSRC (object);
1601 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (rtspsrc),
1602 g_value_get_string (value), NULL);
1604 case PROP_PROTOCOLS:
1605 rtspsrc->protocols = g_value_get_flags (value);
1608 rtspsrc->debug = g_value_get_boolean (value);
1611 rtspsrc->retry = g_value_get_uint (value);
1614 rtspsrc->udp_timeout = g_value_get_uint64 (value);
1616 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1617 case PROP_START_POSITION:
1618 rtspsrc->start_position = g_value_get_uint64 (value);
1620 case PROP_RESUME_POSITION:
1621 rtspsrc->last_pos = g_value_get_uint64 (value);
1622 GST_DEBUG_OBJECT (rtspsrc, "src->last_pos value set to %" GST_TIME_FORMAT,
1623 GST_TIME_ARGS (rtspsrc->last_pos));
1626 case PROP_TCP_TIMEOUT:
1627 gst_rtspsrc_set_tcp_timeout (rtspsrc, g_value_get_uint64 (value));
1630 rtspsrc->latency = g_value_get_uint (value);
1632 case PROP_DROP_ON_LATENCY:
1633 rtspsrc->drop_on_latency = g_value_get_boolean (value);
1635 case PROP_CONNECTION_SPEED:
1636 rtspsrc->connection_speed = g_value_get_uint64 (value);
1638 case PROP_NAT_METHOD:
1639 rtspsrc->nat_method = g_value_get_enum (value);
1642 rtspsrc->do_rtcp = g_value_get_boolean (value);
1644 case PROP_DO_RTSP_KEEP_ALIVE:
1645 rtspsrc->do_rtsp_keep_alive = g_value_get_boolean (value);
1648 gst_rtspsrc_set_proxy (rtspsrc, g_value_get_string (value));
1651 g_free (rtspsrc->prop_proxy_id);
1652 rtspsrc->prop_proxy_id = g_value_dup_string (value);
1655 g_free (rtspsrc->prop_proxy_pw);
1656 rtspsrc->prop_proxy_pw = g_value_dup_string (value);
1658 case PROP_RTP_BLOCKSIZE:
1659 rtspsrc->rtp_blocksize = g_value_get_uint (value);
1662 g_free (rtspsrc->user_id);
1663 rtspsrc->user_id = g_value_dup_string (value);
1666 g_free (rtspsrc->user_pw);
1667 rtspsrc->user_pw = g_value_dup_string (value);
1669 case PROP_BUFFER_MODE:
1670 rtspsrc->buffer_mode = g_value_get_enum (value);
1672 case PROP_PORT_RANGE:
1676 str = g_value_get_string (value);
1677 if (str == NULL || sscanf (str, "%u-%u", &rtspsrc->client_port_range.min,
1678 &rtspsrc->client_port_range.max) != 2) {
1679 rtspsrc->client_port_range.min = 0;
1680 rtspsrc->client_port_range.max = 0;
1684 case PROP_UDP_BUFFER_SIZE:
1685 rtspsrc->udp_buffer_size = g_value_get_int (value);
1687 case PROP_SHORT_HEADER:
1688 rtspsrc->short_header = g_value_get_boolean (value);
1690 case PROP_PROBATION:
1691 rtspsrc->probation = g_value_get_uint (value);
1693 case PROP_UDP_RECONNECT:
1694 rtspsrc->udp_reconnect = g_value_get_boolean (value);
1696 case PROP_MULTICAST_IFACE:
1697 g_free (rtspsrc->multi_iface);
1699 if (g_value_get_string (value) == NULL)
1700 rtspsrc->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
1702 rtspsrc->multi_iface = g_value_dup_string (value);
1705 rtspsrc->ntp_sync = g_value_get_boolean (value);
1706 /* The default value of max_ts_offset depends on ntp_sync. If user
1707 * hasn't set it then change default value */
1708 if (!rtspsrc->max_ts_offset_is_set) {
1709 if (rtspsrc->ntp_sync) {
1710 rtspsrc->max_ts_offset = 0;
1712 rtspsrc->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
1716 case PROP_USE_PIPELINE_CLOCK:
1717 rtspsrc->use_pipeline_clock = g_value_get_boolean (value);
1720 rtspsrc->sdes = g_value_dup_boxed (value);
1722 case PROP_TLS_VALIDATION_FLAGS:
1723 rtspsrc->tls_validation_flags = g_value_get_flags (value);
1725 case PROP_TLS_DATABASE:
1726 g_clear_object (&rtspsrc->tls_database);
1727 rtspsrc->tls_database = g_value_dup_object (value);
1729 case PROP_TLS_INTERACTION:
1730 g_clear_object (&rtspsrc->tls_interaction);
1731 rtspsrc->tls_interaction = g_value_dup_object (value);
1733 case PROP_DO_RETRANSMISSION:
1734 rtspsrc->do_retransmission = g_value_get_boolean (value);
1736 case PROP_NTP_TIME_SOURCE:
1737 rtspsrc->ntp_time_source = g_value_get_enum (value);
1739 case PROP_USER_AGENT:
1740 g_free (rtspsrc->user_agent);
1741 rtspsrc->user_agent = g_value_dup_string (value);
1743 case PROP_MAX_RTCP_RTP_TIME_DIFF:
1744 rtspsrc->max_rtcp_rtp_time_diff = g_value_get_int (value);
1746 case PROP_RFC7273_SYNC:
1747 rtspsrc->rfc7273_sync = g_value_get_boolean (value);
1749 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
1750 rtspsrc->max_ts_offset_adjustment = g_value_get_uint64 (value);
1752 case PROP_MAX_TS_OFFSET:
1753 rtspsrc->max_ts_offset = g_value_get_int64 (value);
1754 rtspsrc->max_ts_offset_is_set = TRUE;
1756 case PROP_DEFAULT_VERSION:
1757 rtspsrc->default_version = g_value_get_enum (value);
1759 case PROP_BACKCHANNEL:
1760 rtspsrc->backchannel = g_value_get_enum (value);
1762 case PROP_TEARDOWN_TIMEOUT:
1763 rtspsrc->teardown_timeout = g_value_get_uint64 (value);
1766 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1772 gst_rtspsrc_get_property (GObject * object, guint prop_id, GValue * value,
1775 GstRTSPSrc *rtspsrc;
1777 rtspsrc = GST_RTSPSRC (object);
1781 g_value_set_string (value, rtspsrc->conninfo.location);
1783 case PROP_PROTOCOLS:
1784 g_value_set_flags (value, rtspsrc->protocols);
1787 g_value_set_boolean (value, rtspsrc->debug);
1790 g_value_set_uint (value, rtspsrc->retry);
1793 g_value_set_uint64 (value, rtspsrc->udp_timeout);
1795 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
1796 case PROP_START_POSITION:
1797 g_value_set_uint64 (value, rtspsrc->start_position);
1799 case PROP_RESUME_POSITION:
1800 g_value_set_uint64 (value, rtspsrc->last_pos);
1803 case PROP_TCP_TIMEOUT:
1807 timeout = ((guint64) rtspsrc->tcp_timeout.tv_sec) * G_USEC_PER_SEC +
1808 rtspsrc->tcp_timeout.tv_usec;
1809 g_value_set_uint64 (value, timeout);
1813 g_value_set_uint (value, rtspsrc->latency);
1815 case PROP_DROP_ON_LATENCY:
1816 g_value_set_boolean (value, rtspsrc->drop_on_latency);
1818 case PROP_CONNECTION_SPEED:
1819 g_value_set_uint64 (value, rtspsrc->connection_speed);
1821 case PROP_NAT_METHOD:
1822 g_value_set_enum (value, rtspsrc->nat_method);
1825 g_value_set_boolean (value, rtspsrc->do_rtcp);
1827 case PROP_DO_RTSP_KEEP_ALIVE:
1828 g_value_set_boolean (value, rtspsrc->do_rtsp_keep_alive);
1834 if (rtspsrc->proxy_host) {
1836 g_strdup_printf ("%s:%d", rtspsrc->proxy_host, rtspsrc->proxy_port);
1840 g_value_take_string (value, str);
1844 g_value_set_string (value, rtspsrc->prop_proxy_id);
1847 g_value_set_string (value, rtspsrc->prop_proxy_pw);
1849 case PROP_RTP_BLOCKSIZE:
1850 g_value_set_uint (value, rtspsrc->rtp_blocksize);
1853 g_value_set_string (value, rtspsrc->user_id);
1856 g_value_set_string (value, rtspsrc->user_pw);
1858 case PROP_BUFFER_MODE:
1859 g_value_set_enum (value, rtspsrc->buffer_mode);
1861 case PROP_PORT_RANGE:
1865 if (rtspsrc->client_port_range.min != 0) {
1866 str = g_strdup_printf ("%u-%u", rtspsrc->client_port_range.min,
1867 rtspsrc->client_port_range.max);
1871 g_value_take_string (value, str);
1874 case PROP_UDP_BUFFER_SIZE:
1875 g_value_set_int (value, rtspsrc->udp_buffer_size);
1877 case PROP_SHORT_HEADER:
1878 g_value_set_boolean (value, rtspsrc->short_header);
1880 case PROP_PROBATION:
1881 g_value_set_uint (value, rtspsrc->probation);
1883 case PROP_UDP_RECONNECT:
1884 g_value_set_boolean (value, rtspsrc->udp_reconnect);
1886 case PROP_MULTICAST_IFACE:
1887 g_value_set_string (value, rtspsrc->multi_iface);
1890 g_value_set_boolean (value, rtspsrc->ntp_sync);
1892 case PROP_USE_PIPELINE_CLOCK:
1893 g_value_set_boolean (value, rtspsrc->use_pipeline_clock);
1896 g_value_set_boxed (value, rtspsrc->sdes);
1898 case PROP_TLS_VALIDATION_FLAGS:
1899 g_value_set_flags (value, rtspsrc->tls_validation_flags);
1901 case PROP_TLS_DATABASE:
1902 g_value_set_object (value, rtspsrc->tls_database);
1904 case PROP_TLS_INTERACTION:
1905 g_value_set_object (value, rtspsrc->tls_interaction);
1907 case PROP_DO_RETRANSMISSION:
1908 g_value_set_boolean (value, rtspsrc->do_retransmission);
1910 case PROP_NTP_TIME_SOURCE:
1911 g_value_set_enum (value, rtspsrc->ntp_time_source);
1913 case PROP_USER_AGENT:
1914 g_value_set_string (value, rtspsrc->user_agent);
1916 case PROP_MAX_RTCP_RTP_TIME_DIFF:
1917 g_value_set_int (value, rtspsrc->max_rtcp_rtp_time_diff);
1919 case PROP_RFC7273_SYNC:
1920 g_value_set_boolean (value, rtspsrc->rfc7273_sync);
1922 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
1923 g_value_set_uint64 (value, rtspsrc->max_ts_offset_adjustment);
1925 case PROP_MAX_TS_OFFSET:
1926 g_value_set_int64 (value, rtspsrc->max_ts_offset);
1928 case PROP_DEFAULT_VERSION:
1929 g_value_set_enum (value, rtspsrc->default_version);
1931 case PROP_BACKCHANNEL:
1932 g_value_set_enum (value, rtspsrc->backchannel);
1934 case PROP_TEARDOWN_TIMEOUT:
1935 g_value_set_uint64 (value, rtspsrc->teardown_timeout);
1938 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1944 find_stream_by_id (GstRTSPStream * stream, gint * id)
1946 if (stream->id == *id)
1953 find_stream_by_channel (GstRTSPStream * stream, gint * channel)
1955 /* ignore unconfigured channels here (e.g., those that
1956 * were explicitly skipped during SETUP) */
1957 if ((stream->channelpad[0] != NULL) &&
1958 (stream->channel[0] == *channel || stream->channel[1] == *channel))
1965 find_stream_by_udpsrc (GstRTSPStream * stream, gconstpointer a)
1967 GstElement *src = (GstElement *) a;
1969 if (stream->udpsrc[0] == src)
1971 if (stream->udpsrc[1] == src)
1978 find_stream_by_setup (GstRTSPStream * stream, gconstpointer a)
1980 if (stream->conninfo.location) {
1981 /* check qualified setup_url */
1982 if (!strcmp (stream->conninfo.location, (gchar *) a))
1985 if (stream->control_url) {
1986 /* check original control_url */
1987 if (!strcmp (stream->control_url, (gchar *) a))
1990 /* check if qualified setup_url ends with string */
1991 if (g_str_has_suffix (stream->control_url, (gchar *) a))
1998 static GstRTSPStream *
1999 find_stream (GstRTSPSrc * src, gconstpointer data, gconstpointer func)
2003 /* find and get stream */
2004 if ((lstream = g_list_find_custom (src->streams, data, (GCompareFunc) func)))
2005 return (GstRTSPStream *) lstream->data;
2010 static const GstSDPBandwidth *
2011 gst_rtspsrc_get_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
2012 const GstSDPMedia * media, const gchar * type)
2016 /* first look in the media specific section */
2017 len = gst_sdp_media_bandwidths_len (media);
2018 for (i = 0; i < len; i++) {
2019 const GstSDPBandwidth *bw = gst_sdp_media_get_bandwidth (media, i);
2021 if (strcmp (bw->bwtype, type) == 0)
2024 /* then look in the message specific section */
2025 len = gst_sdp_message_bandwidths_len (sdp);
2026 for (i = 0; i < len; i++) {
2027 const GstSDPBandwidth *bw = gst_sdp_message_get_bandwidth (sdp, i);
2029 if (strcmp (bw->bwtype, type) == 0)
2036 gst_rtspsrc_collect_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
2037 const GstSDPMedia * media, GstRTSPStream * stream)
2039 const GstSDPBandwidth *bw;
2041 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_AS)))
2042 stream->as_bandwidth = bw->bandwidth;
2044 stream->as_bandwidth = -1;
2046 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RR)))
2047 stream->rr_bandwidth = bw->bandwidth;
2049 stream->rr_bandwidth = -1;
2051 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RS)))
2052 stream->rs_bandwidth = bw->bandwidth;
2054 stream->rs_bandwidth = -1;
2058 gst_rtspsrc_do_stream_connection (GstRTSPSrc * src, GstRTSPStream * stream,
2059 const GstSDPConnection * conn)
2061 if (conn->nettype == NULL || strcmp (conn->nettype, "IN") != 0)
2064 if (conn->addrtype == NULL)
2067 /* check for IPV6 */
2068 if (strcmp (conn->addrtype, "IP4") == 0)
2069 stream->is_ipv6 = FALSE;
2070 else if (strcmp (conn->addrtype, "IP6") == 0)
2071 stream->is_ipv6 = TRUE;
2076 g_free (stream->destination);
2077 stream->destination = g_strdup (conn->address);
2079 /* check for multicast */
2080 stream->is_multicast =
2081 gst_sdp_address_is_multicast (conn->nettype, conn->addrtype,
2083 stream->ttl = conn->ttl;
2086 /* Go over the connections for a stream.
2087 * - If we are dealing with IPV6, we will setup IPV6 sockets for sending and
2089 * - If we are dealing with a localhost address, we disable multicast
2092 gst_rtspsrc_collect_connections (GstRTSPSrc * src, const GstSDPMessage * sdp,
2093 const GstSDPMedia * media, GstRTSPStream * stream)
2095 const GstSDPConnection *conn;
2098 /* first look in the media specific section */
2099 len = gst_sdp_media_connections_len (media);
2100 for (i = 0; i < len; i++) {
2101 conn = gst_sdp_media_get_connection (media, i);
2103 gst_rtspsrc_do_stream_connection (src, stream, conn);
2105 /* then look in the message specific section */
2106 if ((conn = gst_sdp_message_get_connection (sdp))) {
2107 gst_rtspsrc_do_stream_connection (src, stream, conn);
2112 make_stream_id (GstRTSPStream * stream, const GstSDPMedia * media)
2115 g_strdup_printf ("%s:%d:%d:%s:%d", media->media, media->port,
2116 media->num_ports, media->proto, stream->default_pt);
2118 g_strcanon (stream_id, G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS, ':');
2123 /* m=<media> <UDP port> RTP/AVP <payload>
2126 gst_rtspsrc_collect_payloads (GstRTSPSrc * src, const GstSDPMessage * sdp,
2127 const GstSDPMedia * media, GstRTSPStream * stream)
2131 GstCaps *global_caps;
2134 proto = gst_sdp_media_get_proto (media);
2138 if (g_str_equal (proto, "RTP/AVP"))
2139 stream->profile = GST_RTSP_PROFILE_AVP;
2140 else if (g_str_equal (proto, "RTP/SAVP"))
2141 stream->profile = GST_RTSP_PROFILE_SAVP;
2142 else if (g_str_equal (proto, "RTP/AVPF"))
2143 stream->profile = GST_RTSP_PROFILE_AVPF;
2144 else if (g_str_equal (proto, "RTP/SAVPF"))
2145 stream->profile = GST_RTSP_PROFILE_SAVPF;
2149 if (gst_sdp_media_get_attribute_val (media, "sendonly") != NULL &&
2150 /* We want to setup caps for streams configured as backchannel */
2151 !stream->is_backchannel && src->backchannel != BACKCHANNEL_NONE)
2152 goto sendonly_media;
2154 /* Parse global SDP attributes once */
2155 global_caps = gst_caps_new_empty_simple ("application/x-unknown");
2156 GST_DEBUG ("mapping sdp session level attributes to caps");
2157 gst_sdp_message_attributes_to_caps (sdp, global_caps);
2158 GST_DEBUG ("mapping sdp media level attributes to caps");
2159 gst_sdp_media_attributes_to_caps (media, global_caps);
2161 /* Keep a copy of the SDP key management */
2162 gst_sdp_media_parse_keymgmt (media, &stream->mikey);
2163 if (stream->mikey == NULL)
2164 gst_sdp_message_parse_keymgmt (sdp, &stream->mikey);
2166 len = gst_sdp_media_formats_len (media);
2167 for (i = 0; i < len; i++) {
2169 GstCaps *caps, *outcaps;
2173 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
2174 const gchar *encoder, *mediatype;
2176 pt = atoi (gst_sdp_media_get_format (media, i));
2178 GST_DEBUG_OBJECT (src, " looking at %d pt: %d", i, pt);
2181 caps = gst_sdp_media_get_caps_from_media (media, pt);
2183 GST_WARNING_OBJECT (src, " skipping pt %d without caps", pt);
2187 /* do some tweaks */
2188 s = gst_caps_get_structure (caps, 0);
2189 if ((enc = gst_structure_get_string (s, "encoding-name"))) {
2190 stream->is_real = (strstr (enc, "-REAL") != NULL);
2191 if (strcmp (enc, "X-ASF-PF") == 0)
2192 stream->container = TRUE;
2194 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
2195 if ((mediatype = gst_structure_get_string (s, "media"))) {
2196 GST_DEBUG_OBJECT (src, " mediatype : %s", mediatype);
2197 if (!strcmp (mediatype, "video")) {
2198 if ((encoder = gst_structure_get_string (s, "encoding-name"))) {
2199 GST_DEBUG_OBJECT (src, " encoder : %s", encoder);
2200 if ((!strcmp (encoder, "H261")) ||
2201 (!strcmp (encoder, "H263")) ||
2202 (!strcmp (encoder, "H263-1998"))
2203 || (!strcmp (encoder, "H263-2000")) || (!strcmp (encoder, "H264"))
2204 || (!strcmp (encoder, "MP4V-ES"))) {
2205 src->is_video_codec_supported = TRUE;
2206 GST_DEBUG_OBJECT (src, "Supported Video Codec %s", encoder);
2208 GST_DEBUG_OBJECT (src, "Unsupported Video Codec %s", encoder);
2212 src->video_codec = g_strdup (encoder);
2213 src->video_frame_size =
2214 g_strdup (gst_structure_get_string (s, "a-framesize"));
2215 GST_DEBUG_OBJECT (src, "video_codec %s , video_frame_size %s ",
2216 src->video_codec, src->video_frame_size);
2217 } else if (!strcmp (mediatype, "audio")) {
2218 if ((encoder = gst_structure_get_string (s, "encoding-name"))) {
2219 GST_DEBUG_OBJECT (src, " encoder : %s", encoder);
2220 if ((!strcmp (encoder, "MP4A-LATM")) ||
2221 (!strcmp (encoder, "AMR")) || (!strcmp (encoder, "AMR-WB"))
2222 || (!strcmp (encoder, "AMR-NB"))
2223 || (!strcmp (encoder, "mpeg4-generic"))
2224 || (!strcmp (encoder, "MPEG4-GENERIC"))
2225 || (!strcmp (encoder, "QCELP")) || ((strstr (encoder, "G726"))
2226 || (strstr (encoder, "PCMU")))) {
2227 src->is_audio_codec_supported = TRUE;
2228 GST_DEBUG_OBJECT (src, "Supported Audio Codec %s", encoder);
2230 GST_DEBUG_OBJECT (src, "Unsupported Audio Codec %s", encoder);
2234 src->audio_codec = g_strdup (encoder);
2235 GST_DEBUG_OBJECT (src, "audio_codec %s ", src->audio_codec);
2240 /* Merge in global caps */
2241 /* Intersect will merge in missing fields to the current caps */
2242 outcaps = gst_caps_intersect (caps, global_caps);
2243 gst_caps_unref (caps);
2245 /* the first pt will be the default */
2246 if (stream->ptmap->len == 0)
2247 stream->default_pt = pt;
2250 item.caps = outcaps;
2252 g_array_append_val (stream->ptmap, item);
2255 stream->stream_id = make_stream_id (stream, media);
2257 gst_caps_unref (global_caps);
2262 GST_ERROR_OBJECT (src, "can't find proto in media");
2267 GST_ERROR_OBJECT (src, "unknown proto in media: '%s'", proto);
2272 GST_DEBUG_OBJECT (src, "sendonly media ignored, no backchannel");
2277 static const gchar *
2278 get_aggregate_control (GstRTSPSrc * src)
2283 base = src->control;
2284 else if (src->content_base)
2285 base = src->content_base;
2286 else if (src->conninfo.url_str)
2287 base = src->conninfo.url_str;
2295 clear_ptmap_item (PtMapItem * item)
2298 gst_caps_unref (item->caps);
2301 static GstRTSPStream *
2302 gst_rtspsrc_create_stream (GstRTSPSrc * src, GstSDPMessage * sdp, gint idx,
2305 GstRTSPStream *stream;
2306 const gchar *control_url;
2307 const GstSDPMedia *media;
2309 /* get media, should not return NULL */
2310 media = gst_sdp_message_get_media (sdp, idx);
2314 stream = g_new0 (GstRTSPStream, 1);
2315 stream->parent = src;
2316 /* we mark the pad as not linked, we will mark it as OK when we add the pad to
2318 stream->last_ret = GST_FLOW_NOT_LINKED;
2319 stream->added = FALSE;
2320 stream->setup = FALSE;
2321 stream->skipped = FALSE;
2323 stream->eos = FALSE;
2324 stream->discont = TRUE;
2325 stream->seqbase = -1;
2326 stream->timebase = -1;
2327 stream->send_ssrc = g_random_int ();
2328 stream->profile = GST_RTSP_PROFILE_AVP;
2329 stream->ptmap = g_array_new (FALSE, FALSE, sizeof (PtMapItem));
2330 stream->mikey = NULL;
2331 stream->stream_id = NULL;
2332 stream->is_backchannel = FALSE;
2333 g_mutex_init (&stream->conninfo.send_lock);
2334 g_mutex_init (&stream->conninfo.recv_lock);
2335 g_array_set_clear_func (stream->ptmap, (GDestroyNotify) clear_ptmap_item);
2337 /* stream is sendonly and onvif backchannel is requested */
2338 if (gst_sdp_media_get_attribute_val (media, "sendonly") != NULL &&
2339 src->backchannel != BACKCHANNEL_NONE)
2340 stream->is_backchannel = TRUE;
2342 /* collect bandwidth information for this steam. FIXME, configure in the RTP
2343 * session manager to scale RTCP. */
2344 gst_rtspsrc_collect_bandwidth (src, sdp, media, stream);
2346 /* collect connection info */
2347 gst_rtspsrc_collect_connections (src, sdp, media, stream);
2349 /* make the payload type map */
2350 gst_rtspsrc_collect_payloads (src, sdp, media, stream);
2352 /* collect port number */
2353 stream->port = gst_sdp_media_get_port (media);
2355 /* get control url to construct the setup url. The setup url is used to
2356 * configure the transport of the stream and is used to identity the stream in
2357 * the RTP-Info header field returned from PLAY. */
2358 control_url = gst_sdp_media_get_attribute_val (media, "control");
2359 if (control_url == NULL)
2360 control_url = gst_sdp_message_get_attribute_val_n (sdp, "control", 0);
2362 GST_DEBUG_OBJECT (src, "stream %d, (%p)", stream->id, stream);
2363 GST_DEBUG_OBJECT (src, " port: %d", stream->port);
2364 GST_DEBUG_OBJECT (src, " container: %d", stream->container);
2365 GST_DEBUG_OBJECT (src, " control: %s", GST_STR_NULL (control_url));
2367 /* RFC 2326, C.3: missing control_url permitted in case of a single stream */
2368 if (control_url == NULL && n_streams == 1) {
2372 if (control_url != NULL) {
2373 stream->control_url = g_strdup (control_url);
2374 /* Build a fully qualified url using the content_base if any or by prefixing
2375 * the original request.
2376 * If the control_url starts with a '/' or a non rtsp: protocol we will most
2377 * likely build a URL that the server will fail to understand, this is ok,
2378 * we will fail then. */
2379 if (g_str_has_prefix (control_url, "rtsp://"))
2380 stream->conninfo.location = g_strdup (control_url);
2385 if (g_strcmp0 (control_url, "*") == 0)
2388 base = get_aggregate_control (src);
2390 /* check if the base ends or control starts with / */
2391 has_slash = g_str_has_prefix (control_url, "/");
2392 has_slash = has_slash || g_str_has_suffix (base, "/");
2394 /* concatenate the two strings, insert / when not present */
2395 stream->conninfo.location =
2396 g_strdup_printf ("%s%s%s", base, has_slash ? "" : "/", control_url);
2399 GST_DEBUG_OBJECT (src, " setup: %s",
2400 GST_STR_NULL (stream->conninfo.location));
2402 /* we keep track of all streams */
2403 src->streams = g_list_append (src->streams, stream);
2411 gst_rtspsrc_stream_free (GstRTSPSrc * src, GstRTSPStream * stream)
2415 GST_DEBUG_OBJECT (src, "free stream %p", stream);
2417 g_array_free (stream->ptmap, TRUE);
2419 g_free (stream->destination);
2420 g_free (stream->control_url);
2421 g_free (stream->conninfo.location);
2422 g_free (stream->stream_id);
2424 for (i = 0; i < 2; i++) {
2425 if (stream->udpsrc[i]) {
2426 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
2427 if (gst_object_has_as_parent (GST_OBJECT (stream->udpsrc[i]),
2429 gst_bin_remove (GST_BIN_CAST (src), stream->udpsrc[i]);
2430 gst_object_unref (stream->udpsrc[i]);
2432 if (stream->channelpad[i])
2433 gst_object_unref (stream->channelpad[i]);
2435 if (stream->udpsink[i]) {
2436 gst_element_set_state (stream->udpsink[i], GST_STATE_NULL);
2437 if (gst_object_has_as_parent (GST_OBJECT (stream->udpsink[i]),
2439 gst_bin_remove (GST_BIN_CAST (src), stream->udpsink[i]);
2440 gst_object_unref (stream->udpsink[i]);
2443 if (stream->rtpsrc) {
2444 gst_element_set_state (stream->rtpsrc, GST_STATE_NULL);
2445 gst_bin_remove (GST_BIN_CAST (src), stream->rtpsrc);
2446 gst_object_unref (stream->rtpsrc);
2448 if (stream->srcpad) {
2449 gst_pad_set_active (stream->srcpad, FALSE);
2451 gst_element_remove_pad (GST_ELEMENT_CAST (src), stream->srcpad);
2453 if (stream->srtpenc)
2454 gst_object_unref (stream->srtpenc);
2455 if (stream->srtpdec)
2456 gst_object_unref (stream->srtpdec);
2457 if (stream->srtcpparams)
2458 gst_caps_unref (stream->srtcpparams);
2460 gst_mikey_message_unref (stream->mikey);
2461 if (stream->rtcppad)
2462 gst_object_unref (stream->rtcppad);
2463 if (stream->session)
2464 g_object_unref (stream->session);
2465 if (stream->rtx_pt_map)
2466 gst_structure_free (stream->rtx_pt_map);
2468 g_mutex_clear (&stream->conninfo.send_lock);
2469 g_mutex_clear (&stream->conninfo.recv_lock);
2475 gst_rtspsrc_cleanup (GstRTSPSrc * src)
2479 GST_DEBUG_OBJECT (src, "cleanup");
2481 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2482 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2484 gst_rtspsrc_stream_free (src, stream);
2486 g_list_free (src->streams);
2487 src->streams = NULL;
2489 if (src->manager_sig_id) {
2490 g_signal_handler_disconnect (src->manager, src->manager_sig_id);
2491 src->manager_sig_id = 0;
2493 gst_element_set_state (src->manager, GST_STATE_NULL);
2494 gst_bin_remove (GST_BIN_CAST (src), src->manager);
2495 src->manager = NULL;
2498 gst_structure_free (src->props);
2501 g_free (src->content_base);
2502 src->content_base = NULL;
2504 g_free (src->control);
2505 src->control = NULL;
2508 gst_rtsp_range_free (src->range);
2511 /* don't clear the SDP when it was used in the url */
2512 if (src->sdp && !src->from_sdp) {
2513 gst_sdp_message_free (src->sdp);
2517 src->need_segment = FALSE;
2519 if (src->provided_clock) {
2520 gst_object_unref (src->provided_clock);
2521 src->provided_clock = NULL;
2524 /* free parameter requests queue */
2525 if (!g_queue_is_empty (&src->set_get_param_q))
2526 g_queue_free_full (&src->set_get_param_q, free_param_queue);
2531 gst_rtspsrc_alloc_udp_ports (GstRTSPStream * stream,
2532 gint * rtpport, gint * rtcpport)
2535 GstStateChangeReturn ret;
2536 GstElement *udpsrc0, *udpsrc1;
2537 gint tmp_rtp, tmp_rtcp;
2541 src = stream->parent;
2547 /* Start at next port */
2548 tmp_rtp = src->next_port_num;
2550 if (stream->is_ipv6)
2551 host = "udp://[::0]";
2553 host = "udp://0.0.0.0";
2555 /* try to allocate 2 UDP ports, the RTP port should be an even
2556 * number and the RTCP port should be the next (uneven) port */
2559 if (tmp_rtp != 0 && src->client_port_range.max > 0 &&
2560 tmp_rtp >= src->client_port_range.max)
2563 udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
2564 if (udpsrc0 == NULL)
2565 goto no_udp_protocol;
2566 g_object_set (G_OBJECT (udpsrc0), "port", tmp_rtp, "reuse", FALSE, NULL);
2568 if (src->udp_buffer_size != 0)
2569 g_object_set (G_OBJECT (udpsrc0), "buffer-size", src->udp_buffer_size,
2572 ret = gst_element_set_state (udpsrc0, GST_STATE_READY);
2573 if (ret == GST_STATE_CHANGE_FAILURE) {
2575 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTP port %d", tmp_rtp);
2578 if (++count > src->retry)
2581 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
2582 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2583 gst_object_unref (udpsrc0);
2586 GST_DEBUG_OBJECT (src, "retry %d", count);
2589 goto no_udp_protocol;
2592 g_object_get (G_OBJECT (udpsrc0), "port", &tmp_rtp, NULL);
2593 GST_DEBUG_OBJECT (src, "got RTP port %d", tmp_rtp);
2595 /* check if port is even */
2596 if ((tmp_rtp & 0x01) != 0) {
2597 /* port not even, close and allocate another */
2598 if (++count > src->retry)
2601 GST_DEBUG_OBJECT (src, "RTP port not even");
2603 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
2604 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2605 gst_object_unref (udpsrc0);
2608 GST_DEBUG_OBJECT (src, "retry %d", count);
2613 /* allocate port+1 for RTCP now */
2614 udpsrc1 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
2615 if (udpsrc1 == NULL)
2616 goto no_udp_rtcp_protocol;
2619 tmp_rtcp = tmp_rtp + 1;
2620 if (src->client_port_range.max > 0 && tmp_rtcp > src->client_port_range.max)
2623 g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, "reuse", FALSE, NULL);
2625 GST_DEBUG_OBJECT (src, "starting RTCP on port %d", tmp_rtcp);
2626 ret = gst_element_set_state (udpsrc1, GST_STATE_READY);
2627 /* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
2628 if (ret == GST_STATE_CHANGE_FAILURE) {
2629 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTCP port %d", tmp_rtcp);
2631 if (++count > src->retry)
2634 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
2635 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2636 gst_object_unref (udpsrc0);
2639 GST_DEBUG_OBJECT (src, "free RTCP udpsrc");
2640 gst_element_set_state (udpsrc1, GST_STATE_NULL);
2641 gst_object_unref (udpsrc1);
2645 GST_DEBUG_OBJECT (src, "retry %d", count);
2649 /* all fine, do port check */
2650 g_object_get (G_OBJECT (udpsrc0), "port", rtpport, NULL);
2651 g_object_get (G_OBJECT (udpsrc1), "port", rtcpport, NULL);
2653 /* this should not happen... */
2654 if (*rtpport != tmp_rtp || *rtcpport != tmp_rtcp)
2657 /* we keep these elements, we configure all in configure_transport when the
2658 * server told us to really use the UDP ports. */
2659 stream->udpsrc[0] = gst_object_ref_sink (udpsrc0);
2660 stream->udpsrc[1] = gst_object_ref_sink (udpsrc1);
2661 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
2662 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
2664 /* keep track of next available port number when we have a range
2666 if (src->next_port_num != 0)
2667 src->next_port_num = tmp_rtcp + 1;
2674 GST_DEBUG_OBJECT (src, "could not get UDP source");
2679 GST_DEBUG_OBJECT (src, "could not allocate UDP port pair after %d retries",
2683 no_udp_rtcp_protocol:
2685 GST_DEBUG_OBJECT (src, "could not get UDP source for RTCP");
2690 GST_DEBUG_OBJECT (src, "ports don't match rtp: %d<->%d, rtcp: %d<->%d",
2691 tmp_rtp, *rtpport, tmp_rtcp, *rtcpport);
2697 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2698 gst_object_unref (udpsrc0);
2701 gst_element_set_state (udpsrc1, GST_STATE_NULL);
2702 gst_object_unref (udpsrc1);
2709 gst_rtspsrc_set_state (GstRTSPSrc * src, GstState state)
2713 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
2714 GST_WARNING_OBJECT (src, "Setting [%s] element state to: %s \n",
2715 GST_ELEMENT_NAME (GST_ELEMENT_CAST (src)),
2716 gst_element_state_get_name (state));
2719 gst_element_set_state (GST_ELEMENT_CAST (src->manager), state);
2721 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2722 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2725 for (i = 0; i < 2; i++) {
2726 if (stream->udpsrc[i])
2727 gst_element_set_state (stream->udpsrc[i], state);
2733 gst_rtspsrc_flush (GstRTSPSrc * src, gboolean flush, gboolean playing,
2741 event = gst_event_new_flush_start ();
2742 gst_event_set_seqnum (event, seqnum);
2743 GST_DEBUG_OBJECT (src, "start flush");
2745 state = GST_STATE_PAUSED;
2747 event = gst_event_new_flush_stop (FALSE);
2748 gst_event_set_seqnum (event, seqnum);
2749 GST_DEBUG_OBJECT (src, "stop flush; playing %d", playing);
2752 state = GST_STATE_PLAYING;
2754 state = GST_STATE_PAUSED;
2756 gst_rtspsrc_push_event (src, event);
2757 gst_rtspsrc_loop_send_cmd (src, cmd, CMD_LOOP);
2758 gst_rtspsrc_set_state (src, state);
2761 static GstRTSPResult
2762 gst_rtspsrc_connection_send (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
2763 GstRTSPMessage * message, GTimeVal * timeout)
2767 if (conninfo->connection) {
2768 g_mutex_lock (&conninfo->send_lock);
2769 ret = gst_rtsp_connection_send (conninfo->connection, message, timeout);
2770 g_mutex_unlock (&conninfo->send_lock);
2772 ret = GST_RTSP_ERROR;
2778 static GstRTSPResult
2779 gst_rtspsrc_connection_receive (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
2780 GstRTSPMessage * message, GTimeVal * timeout)
2784 if (conninfo->connection) {
2785 g_mutex_lock (&conninfo->recv_lock);
2786 ret = gst_rtsp_connection_receive (conninfo->connection, message, timeout);
2787 g_mutex_unlock (&conninfo->recv_lock);
2789 ret = GST_RTSP_ERROR;
2796 gst_rtspsrc_get_position (GstRTSPSrc * src)
2801 query = gst_query_new_position (GST_FORMAT_TIME);
2802 /* should be known somewhere down the stream (e.g. jitterbuffer) */
2803 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2804 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2808 if (stream->srcpad) {
2809 if (gst_pad_query (stream->srcpad, query)) {
2810 gst_query_parse_position (query, &fmt, &pos);
2811 GST_DEBUG_OBJECT (src, "retaining position %" GST_TIME_FORMAT,
2812 GST_TIME_ARGS (pos));
2813 src->last_pos = pos;
2823 gst_query_unref (query);
2827 gst_rtspsrc_perform_seek (GstRTSPSrc * src, GstEvent * event)
2832 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type;
2834 gboolean flush, skip;
2837 GstSegment seeksegment = { 0, };
2839 const gchar *seek_style = NULL;
2841 GST_DEBUG_OBJECT (src, "doing seek with event %" GST_PTR_FORMAT, event);
2843 gst_event_parse_seek (event, &rate, &format, &flags,
2844 &cur_type, &cur, &stop_type, &stop);
2846 /* no negative rates yet */
2850 /* we need TIME format */
2851 if (format != src->segment.format)
2854 /* Check if we are not at all seekable */
2855 if (src->seekable == -1.0)
2858 /* Additional seeking-to-beginning-only check */
2859 if (src->seekable == 0.0 && cur != 0)
2862 if (flags & GST_SEEK_FLAG_SEGMENT)
2863 goto invalid_segment_flag;
2865 /* get flush flag */
2866 flush = flags & GST_SEEK_FLAG_FLUSH;
2867 skip = flags & GST_SEEK_FLAG_SKIP;
2869 /* now we need to make sure the streaming thread is stopped. We do this by
2870 * either sending a FLUSH_START event downstream which will cause the
2871 * streaming thread to stop with a WRONG_STATE.
2872 * For a non-flushing seek we simply pause the task, which will happen as soon
2873 * as it completes one iteration (and thus might block when the sink is
2874 * blocking in preroll). */
2876 GST_DEBUG_OBJECT (src, "starting flush");
2877 gst_rtspsrc_flush (src, TRUE, FALSE, gst_event_get_seqnum (event));
2880 gst_task_pause (src->task);
2884 /* we should now be able to grab the streaming thread because we stopped it
2885 * with the above flush/pause code */
2886 GST_RTSP_STREAM_LOCK (src);
2888 GST_DEBUG_OBJECT (src, "stopped streaming");
2890 /* stop flushing the rtsp connection so we can send PAUSE/PLAY below */
2891 gst_rtspsrc_connection_flush (src, FALSE);
2893 /* copy segment, we need this because we still need the old
2894 * segment when we close the current segment. */
2895 memcpy (&seeksegment, &src->segment, sizeof (GstSegment));
2897 /* configure the seek parameters in the seeksegment. We will then have the
2898 * right values in the segment to perform the seek */
2899 GST_DEBUG_OBJECT (src, "configuring seek");
2900 gst_segment_do_seek (&seeksegment, rate, format, flags,
2901 cur_type, cur, stop_type, stop, &update);
2903 /* figure out the last position we need to play. If it's configured (stop !=
2904 * -1), use that, else we play until the total duration of the file */
2905 if ((stop = seeksegment.stop) == -1)
2906 stop = seeksegment.duration;
2908 /* if we were playing, pause first */
2909 playing = (src->state == GST_RTSP_STATE_PLAYING);
2911 /* obtain current position in case seek fails */
2912 gst_rtspsrc_get_position (src);
2913 gst_rtspsrc_pause (src, FALSE);
2917 src->state = GST_RTSP_STATE_SEEKING;
2919 /* PLAY will add the range header now. */
2920 src->need_range = TRUE;
2922 /* prepare for streaming again */
2924 /* if we started flush, we stop now */
2925 GST_DEBUG_OBJECT (src, "stopping flush");
2926 gst_rtspsrc_flush (src, FALSE, playing, gst_event_get_seqnum (event));
2929 /* now we did the seek and can activate the new segment values */
2930 memcpy (&src->segment, &seeksegment, sizeof (GstSegment));
2932 /* if we're doing a segment seek, post a SEGMENT_START message */
2933 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
2934 gst_element_post_message (GST_ELEMENT_CAST (src),
2935 gst_message_new_segment_start (GST_OBJECT_CAST (src),
2936 src->segment.format, src->segment.position));
2939 /* now create the newsegment */
2940 GST_DEBUG_OBJECT (src, "Creating newsegment from %" G_GINT64_FORMAT
2941 " to %" G_GINT64_FORMAT, src->segment.position, stop);
2944 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
2945 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2946 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2947 stream->discont = TRUE;
2950 /* and continue playing if needed */
2951 GST_OBJECT_LOCK (src);
2952 playing = (GST_STATE_PENDING (src) == GST_STATE_VOID_PENDING
2953 && GST_STATE (src) == GST_STATE_PLAYING)
2954 || (GST_STATE_PENDING (src) == GST_STATE_PLAYING);
2955 GST_OBJECT_UNLOCK (src);
2957 if (src->version >= GST_RTSP_VERSION_2_0) {
2958 if (flags & GST_SEEK_FLAG_ACCURATE)
2960 else if (flags & GST_SEEK_FLAG_KEY_UNIT)
2961 seek_style = "CoRAP";
2962 else if (flags & GST_SEEK_FLAG_KEY_UNIT
2963 && flags & GST_SEEK_FLAG_SNAP_BEFORE)
2964 seek_style = "First-Prior";
2965 else if (flags & GST_SEEK_FLAG_KEY_UNIT && flags & GST_SEEK_FLAG_SNAP_AFTER)
2966 seek_style = "Next";
2970 gst_rtspsrc_play (src, &seeksegment, FALSE, seek_style);
2972 GST_RTSP_STREAM_UNLOCK (src);
2979 GST_DEBUG_OBJECT (src, "negative playback rates are not supported yet.");
2984 GST_DEBUG_OBJECT (src, "unsupported format given, seek aborted.");
2989 GST_DEBUG_OBJECT (src, "stream is not seekable");
2992 invalid_segment_flag:
2994 GST_WARNING_OBJECT (src, "Segment seeks not supported");
3000 gst_rtspsrc_handle_src_event (GstPad * pad, GstObject * parent,
3004 gboolean res = TRUE;
3007 src = GST_RTSPSRC_CAST (parent);
3009 GST_DEBUG_OBJECT (src, "pad %s:%s received event %s",
3010 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
3012 switch (GST_EVENT_TYPE (event)) {
3013 case GST_EVENT_SEEK:
3014 res = gst_rtspsrc_perform_seek (src, event);
3018 case GST_EVENT_NAVIGATION:
3019 case GST_EVENT_LATENCY:
3027 if ((target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad)))) {
3028 res = gst_pad_send_event (target, event);
3029 gst_object_unref (target);
3031 gst_event_unref (event);
3034 gst_event_unref (event);
3041 gst_rtspsrc_handle_src_sink_event (GstPad * pad, GstObject * parent,
3044 GstRTSPStream *stream;
3046 stream = gst_pad_get_element_private (pad);
3048 switch (GST_EVENT_TYPE (event)) {
3049 case GST_EVENT_STREAM_START:{
3050 const gchar *upstream_id;
3053 gst_event_parse_stream_start (event, &upstream_id);
3054 stream_id = g_strdup_printf ("%s/%s", upstream_id, stream->stream_id);
3056 gst_event_unref (event);
3057 event = gst_event_new_stream_start (stream_id);
3065 return gst_pad_push_event (stream->srcpad, event);
3068 /* this is the final event function we receive on the internal source pad when
3069 * we deal with TCP connections */
3071 gst_rtspsrc_handle_internal_src_event (GstPad * pad, GstObject * parent,
3076 GST_DEBUG_OBJECT (pad, "received event %s", GST_EVENT_TYPE_NAME (event));
3078 switch (GST_EVENT_TYPE (event)) {
3079 case GST_EVENT_SEEK:
3081 case GST_EVENT_NAVIGATION:
3082 case GST_EVENT_LATENCY:
3084 gst_event_unref (event);
3091 /* this is the final query function we receive on the internal source pad when
3092 * we deal with TCP connections */
3094 gst_rtspsrc_handle_internal_src_query (GstPad * pad, GstObject * parent,
3098 gboolean res = TRUE;
3100 src = GST_RTSPSRC_CAST (gst_pad_get_element_private (pad));
3102 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
3103 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3105 switch (GST_QUERY_TYPE (query)) {
3106 case GST_QUERY_POSITION:
3111 case GST_QUERY_DURATION:
3115 gst_query_parse_duration (query, &format, NULL);
3118 case GST_FORMAT_TIME:
3119 gst_query_set_duration (query, format, src->segment.duration);
3127 case GST_QUERY_LATENCY:
3129 /* we are live with a min latency of 0 and unlimited max latency, this
3130 * result will be updated by the session manager if there is any. */
3131 gst_query_set_latency (query, TRUE, 0, -1);
3141 /* this query is executed on the ghost source pad exposed on rtspsrc. */
3143 gst_rtspsrc_handle_src_query (GstPad * pad, GstObject * parent,
3147 gboolean res = FALSE;
3149 src = GST_RTSPSRC_CAST (parent);
3151 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
3152 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3154 switch (GST_QUERY_TYPE (query)) {
3155 case GST_QUERY_DURATION:
3159 gst_query_parse_duration (query, &format, NULL);
3162 case GST_FORMAT_TIME:
3163 gst_query_set_duration (query, format, src->segment.duration);
3171 case GST_QUERY_SEEKING:
3175 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
3176 if (format == GST_FORMAT_TIME) {
3178 src->cur_protocols != GST_RTSP_LOWER_TRANS_UDP_MCAST;
3179 GstClockTime start = 0, duration = src->segment.duration;
3181 /* seeking without duration is unlikely */
3182 seekable = seekable && src->seekable >= 0.0 && src->segment.duration &&
3183 GST_CLOCK_TIME_IS_VALID (src->segment.duration);
3186 if (src->seekable > 0.0) {
3187 start = src->last_pos - src->seekable * GST_SECOND;
3189 /* src->seekable == 0 means that we can only seek to 0 */
3195 GST_LOG_OBJECT (src, "seekable : %d", seekable);
3197 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, start,
3207 uri = gst_rtspsrc_uri_get_uri (GST_URI_HANDLER (src));
3209 gst_query_set_uri (query, uri);
3217 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad));
3219 /* forward the query to the proxy target pad */
3221 res = gst_pad_query (target, query);
3222 gst_object_unref (target);
3231 /* callback for RTCP messages to be sent to the server when operating in TCP
3233 static GstFlowReturn
3234 gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
3237 GstRTSPStream *stream;
3238 GstFlowReturn res = GST_FLOW_OK;
3243 GstRTSPMessage message = { 0 };
3244 GstRTSPConnInfo *conninfo;
3246 stream = (GstRTSPStream *) gst_pad_get_element_private (pad);
3247 src = stream->parent;
3249 gst_buffer_map (buffer, &map, GST_MAP_READ);
3253 gst_rtsp_message_init_data (&message, stream->channel[1]);
3255 /* lend the body data to the message */
3256 gst_rtsp_message_take_body (&message, data, size);
3258 if (stream->conninfo.connection)
3259 conninfo = &stream->conninfo;
3261 conninfo = &src->conninfo;
3263 GST_DEBUG_OBJECT (src, "sending %u bytes RTCP", size);
3264 ret = gst_rtspsrc_connection_send (src, conninfo, &message, NULL);
3265 GST_DEBUG_OBJECT (src, "sent RTCP, %d", ret);
3267 /* and steal it away again because we will free it when unreffing the
3269 gst_rtsp_message_steal_body (&message, &data, &size);
3270 gst_rtsp_message_unset (&message);
3272 gst_buffer_unmap (buffer, &map);
3273 gst_buffer_unref (buffer);
3278 static GstFlowReturn
3279 gst_rtspsrc_push_backchannel_buffer (GstRTSPSrc * src, guint id,
3282 GstFlowReturn res = GST_FLOW_OK;
3283 GstRTSPStream *stream;
3285 if (!src->conninfo.connected || src->state != GST_RTSP_STATE_PLAYING)
3288 stream = find_stream (src, &id, (gpointer) find_stream_by_id);
3289 if (stream == NULL) {
3290 GST_ERROR_OBJECT (src, "no stream with id %u", id);
3294 if (src->interleaved) {
3300 GstRTSPMessage message = { 0 };
3301 GstRTSPConnInfo *conninfo;
3303 buffer = gst_sample_get_buffer (sample);
3305 gst_buffer_map (buffer, &map, GST_MAP_READ);
3309 gst_rtsp_message_init_data (&message, stream->channel[0]);
3311 /* lend the body data to the message */
3312 gst_rtsp_message_take_body (&message, data, size);
3314 if (stream->conninfo.connection)
3315 conninfo = &stream->conninfo;
3317 conninfo = &src->conninfo;
3319 GST_DEBUG_OBJECT (src, "sending %u bytes backchannel RTP", size);
3320 ret = gst_rtspsrc_connection_send (src, conninfo, &message, NULL);
3321 GST_DEBUG_OBJECT (src, "sent backchannel RTP, %d", ret);
3323 /* and steal it away again because we will free it when unreffing the
3325 gst_rtsp_message_steal_body (&message, &data, &size);
3326 gst_rtsp_message_unset (&message);
3328 gst_buffer_unmap (buffer, &map);
3332 g_signal_emit_by_name (stream->rtpsrc, "push-sample", sample, &res);
3333 GST_DEBUG_OBJECT (src, "sent backchannel RTP sample %p: %s", sample,
3334 gst_flow_get_name (res));
3338 gst_sample_unref (sample);
3343 static GstPadProbeReturn
3344 pad_blocked (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
3346 GstRTSPSrc *src = user_data;
3348 GST_DEBUG_OBJECT (src, "pad %s:%s blocked, activating streams",
3349 GST_DEBUG_PAD_NAME (pad));
3351 /* activate the streams */
3352 GST_OBJECT_LOCK (src);
3353 if (!src->need_activate)
3356 src->need_activate = FALSE;
3357 GST_OBJECT_UNLOCK (src);
3359 gst_rtspsrc_activate_streams (src);
3361 return GST_PAD_PROBE_OK;
3365 GST_OBJECT_UNLOCK (src);
3366 return GST_PAD_PROBE_OK;
3370 static GstPadProbeReturn
3371 udpsrc_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
3373 guint32 *segment_seqnum = user_data;
3375 switch (GST_EVENT_TYPE (info->data)) {
3376 case GST_EVENT_SEGMENT:
3377 if (!gst_event_is_writable (info->data))
3378 info->data = gst_event_make_writable (info->data);
3380 *segment_seqnum = gst_event_get_seqnum (info->data);
3385 return GST_PAD_PROBE_OK;
3389 copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
3391 GstPad *gpad = GST_PAD_CAST (user_data);
3393 GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
3394 gst_pad_store_sticky_event (gpad, *event);
3400 add_backchannel_fakesink (GstRTSPSrc * src, GstRTSPStream * stream,
3404 GstElement *fakesink;
3406 fakesink = gst_element_factory_make ("fakesink", NULL);
3407 if (fakesink == NULL) {
3408 GST_ERROR_OBJECT (src, "no fakesink");
3412 sinkpad = gst_element_get_static_pad (fakesink, "sink");
3414 GST_DEBUG_OBJECT (src, "backchannel stream %p, hooking fakesink", stream);
3416 gst_bin_add (GST_BIN_CAST (src), fakesink);
3417 if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) {
3418 GST_WARNING_OBJECT (src, "could not link to fakesink");
3422 gst_object_unref (sinkpad);
3424 gst_element_sync_state_with_parent (fakesink);
3428 /* this callback is called when the session manager generated a new src pad with
3429 * payloaded RTP packets. We simply ghost the pad here. */
3431 new_manager_pad (GstElement * manager, GstPad * pad, GstRTSPSrc * src)
3434 GstPadTemplate *template;
3437 GstRTSPStream *stream;
3439 GstPad *internal_src;
3441 GST_DEBUG_OBJECT (src, "got new manager pad %" GST_PTR_FORMAT, pad);
3443 GST_RTSP_STATE_LOCK (src);
3445 name = gst_object_get_name (GST_OBJECT_CAST (pad));
3446 if (sscanf (name, "recv_rtp_src_%u_%u_%u", &id, &ssrc, &pt) != 3)
3447 goto unknown_stream;
3449 GST_DEBUG_OBJECT (src, "stream: %u, SSRC %08x, PT %d", id, ssrc, pt);
3451 stream = find_stream (src, &id, (gpointer) find_stream_by_id);
3453 goto unknown_stream;
3456 stream->ssrc = ssrc;
3458 /* we'll add it later see below */
3459 stream->added = TRUE;
3461 /* check if we added all streams */
3463 for (ostreams = src->streams; ostreams; ostreams = g_list_next (ostreams)) {
3464 GstRTSPStream *ostream = (GstRTSPStream *) ostreams->data;
3466 GST_DEBUG_OBJECT (src, "stream %p, container %d, added %d, setup %d",
3467 ostream, ostream->container, ostream->added, ostream->setup);
3469 /* if we find a stream for which we did a setup that is not added, we
3470 * need to wait some more */
3471 if (ostream->setup && !ostream->added) {
3476 GST_RTSP_STATE_UNLOCK (src);
3478 /* create a new pad we will use to stream to */
3479 template = gst_static_pad_template_get (&rtptemplate);
3480 stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
3481 gst_object_unref (template);
3484 /* We intercept and modify the stream start event */
3486 GST_PAD (gst_proxy_pad_get_internal (GST_PROXY_PAD (stream->srcpad)));
3487 gst_pad_set_element_private (internal_src, stream);
3488 gst_pad_set_event_function (internal_src, gst_rtspsrc_handle_src_sink_event);
3489 gst_object_unref (internal_src);
3491 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
3492 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
3493 gst_pad_set_active (stream->srcpad, TRUE);
3494 gst_pad_sticky_events_foreach (pad, copy_sticky_events, stream->srcpad);
3496 /* don't add the srcpad if this is a sendonly stream */
3497 if (stream->is_backchannel)
3498 add_backchannel_fakesink (src, stream, stream->srcpad);
3500 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
3503 GST_DEBUG_OBJECT (src, "We added all streams");
3504 /* when we get here, all stream are added and we can fire the no-more-pads
3506 gst_element_no_more_pads (GST_ELEMENT_CAST (src));
3514 GST_DEBUG_OBJECT (src, "ignoring unknown stream");
3515 GST_RTSP_STATE_UNLOCK (src);
3522 stream_get_caps_for_pt (GstRTSPStream * stream, guint pt)
3526 len = stream->ptmap->len;
3527 for (i = 0; i < len; i++) {
3528 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
3536 request_pt_map (GstElement * manager, guint session, guint pt, GstRTSPSrc * src)
3538 GstRTSPStream *stream;
3541 GST_DEBUG_OBJECT (src, "getting pt map for pt %d in session %d", pt, session);
3543 GST_RTSP_STATE_LOCK (src);
3544 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
3546 goto unknown_stream;
3548 if ((caps = stream_get_caps_for_pt (stream, pt)))
3549 gst_caps_ref (caps);
3550 GST_RTSP_STATE_UNLOCK (src);
3556 GST_DEBUG_OBJECT (src, "unknown stream %d", session);
3557 GST_RTSP_STATE_UNLOCK (src);
3563 gst_rtspsrc_do_stream_eos (GstRTSPSrc * src, GstRTSPStream * stream)
3565 GST_DEBUG_OBJECT (src, "setting stream for session %u to EOS", stream->id);
3571 gst_rtspsrc_stream_push_event (src, stream, gst_event_new_eos ());
3577 GST_DEBUG_OBJECT (src, "stream for session %u was already EOS", stream->id);
3583 on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
3585 GstRTSPSrc *src = stream->parent;
3588 g_object_get (source, "ssrc", &ssrc, NULL);
3590 GST_DEBUG_OBJECT (src, "source %08x, stream %08x, session %u received BYE",
3591 ssrc, stream->ssrc, stream->id);
3593 if (ssrc == stream->ssrc)
3594 gst_rtspsrc_do_stream_eos (src, stream);
3598 on_timeout_common (GObject * session, GObject * source, GstRTSPStream * stream)
3600 GstRTSPSrc *src = stream->parent;
3603 g_object_get (source, "ssrc", &ssrc, NULL);
3605 GST_WARNING_OBJECT (src, "source %08x, stream %08x in session %u timed out",
3606 ssrc, stream->ssrc, stream->id);
3608 if (ssrc == stream->ssrc)
3609 gst_rtspsrc_do_stream_eos (src, stream);
3613 on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
3615 GstRTSPSrc *src = stream->parent;
3617 /* timeout, post element message */
3618 gst_element_post_message (GST_ELEMENT_CAST (src),
3619 gst_message_new_element (GST_OBJECT_CAST (src),
3620 gst_structure_new ("GstRTSPSrcTimeout",
3621 "cause", G_TYPE_ENUM, GST_RTSP_SRC_TIMEOUT_CAUSE_RTCP,
3622 "stream-number", G_TYPE_INT, stream->id, "ssrc", G_TYPE_UINT,
3623 stream->ssrc, NULL)));
3625 on_timeout_common (session, source, stream);
3629 on_npt_stop (GstElement * rtpbin, guint session, guint ssrc, GstRTSPSrc * src)
3631 GstRTSPStream *stream;
3633 GST_DEBUG_OBJECT (src, "source in session %u reached NPT stop", session);
3635 /* get stream for session */
3636 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
3638 gst_rtspsrc_do_stream_eos (src, stream);
3643 on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
3645 GST_DEBUG_OBJECT (stream->parent, "source in session %u is active",
3650 set_manager_buffer_mode (GstRTSPSrc * src)
3652 GObjectClass *klass;
3654 if (src->manager == NULL)
3657 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
3659 if (!g_object_class_find_property (klass, "buffer-mode"))
3662 if (src->buffer_mode != BUFFER_MODE_AUTO) {
3663 g_object_set (src->manager, "buffer-mode", src->buffer_mode, NULL);
3668 GST_DEBUG_OBJECT (src,
3669 "auto buffering mode, have clock %" GST_PTR_FORMAT, src->provided_clock);
3671 if (src->provided_clock) {
3672 GstClock *clock = gst_element_get_clock (GST_ELEMENT_CAST (src));
3674 if (clock == src->provided_clock) {
3675 GST_DEBUG_OBJECT (src, "selected synced");
3676 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SYNCED, NULL);
3679 gst_object_unref (clock);
3684 /* Otherwise fall-through and use another buffer mode */
3686 gst_object_unref (clock);
3689 GST_DEBUG_OBJECT (src, "auto buffering mode");
3690 if (src->use_buffering) {
3691 GST_DEBUG_OBJECT (src, "selected buffer");
3692 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_BUFFER, NULL);
3694 GST_DEBUG_OBJECT (src, "selected slave");
3695 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SLAVE, NULL);
3700 request_key (GstElement * srtpdec, guint ssrc, GstRTSPStream * stream)
3704 GstMIKEYMessage *msg = stream->mikey;
3706 GST_DEBUG ("request key SSRC %u", ssrc);
3708 caps = gst_caps_ref (stream_get_caps_for_pt (stream, stream->default_pt));
3709 caps = gst_caps_make_writable (caps);
3711 /* parse crypto sessions and look for the SSRC rollover counter */
3712 msg = stream->mikey;
3713 for (i = 0; msg && i < gst_mikey_message_get_n_cs (msg); i++) {
3714 const GstMIKEYMapSRTP *map = gst_mikey_message_get_cs_srtp (msg, i);
3716 if (ssrc == map->ssrc) {
3717 gst_caps_set_simple (caps, "roc", G_TYPE_UINT, map->roc, NULL);
3726 request_rtp_decoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
3728 GST_DEBUG ("decoder session %u, stream %p, %d", session, stream, stream->id);
3729 if (stream->id != session)
3732 if (stream->profile != GST_RTSP_PROFILE_SAVP &&
3733 stream->profile != GST_RTSP_PROFILE_SAVPF)
3736 if (stream->srtpdec == NULL) {
3739 name = g_strdup_printf ("srtpdec_%u", session);
3740 stream->srtpdec = gst_element_factory_make ("srtpdec", name);
3743 if (stream->srtpdec == NULL) {
3744 GST_ELEMENT_ERROR (stream->parent, CORE, MISSING_PLUGIN, (NULL),
3745 ("no srtpdec element present!"));
3748 g_signal_connect (stream->srtpdec, "request-key",
3749 (GCallback) request_key, stream);
3751 return gst_object_ref (stream->srtpdec);
3755 request_rtcp_encoder (GstElement * rtpbin, guint session,
3756 GstRTSPStream * stream)
3761 GST_DEBUG ("decoder session %u, stream %p, %d", session, stream, stream->id);
3762 if (stream->id != session)
3765 if (stream->profile != GST_RTSP_PROFILE_SAVP &&
3766 stream->profile != GST_RTSP_PROFILE_SAVPF)
3769 if (stream->srtpenc == NULL) {
3772 name = g_strdup_printf ("srtpenc_%u", session);
3773 stream->srtpenc = gst_element_factory_make ("srtpenc", name);
3776 if (stream->srtpenc == NULL) {
3777 GST_ELEMENT_ERROR (stream->parent, CORE, MISSING_PLUGIN, (NULL),
3778 ("no srtpenc element present!"));
3782 /* get RTCP crypto parameters from caps */
3783 s = gst_caps_get_structure (stream->srtcpparams, 0);
3787 GType ciphertype, authtype;
3788 GValue rtcp_cipher = G_VALUE_INIT, rtcp_auth = G_VALUE_INIT;
3790 ciphertype = g_type_from_name ("GstSrtpCipherType");
3791 authtype = g_type_from_name ("GstSrtpAuthType");
3792 g_value_init (&rtcp_cipher, ciphertype);
3793 g_value_init (&rtcp_auth, authtype);
3795 str = gst_structure_get_string (s, "srtcp-cipher");
3796 gst_value_deserialize (&rtcp_cipher, str);
3797 str = gst_structure_get_string (s, "srtcp-auth");
3798 gst_value_deserialize (&rtcp_auth, str);
3799 gst_structure_get (s, "srtp-key", GST_TYPE_BUFFER, &buf, NULL);
3801 g_object_set_property (G_OBJECT (stream->srtpenc), "rtp-cipher",
3803 g_object_set_property (G_OBJECT (stream->srtpenc), "rtp-auth",
3805 g_object_set_property (G_OBJECT (stream->srtpenc), "rtcp-cipher",
3807 g_object_set_property (G_OBJECT (stream->srtpenc), "rtcp-auth",
3809 g_object_set (stream->srtpenc, "key", buf, NULL);
3811 g_value_unset (&rtcp_cipher);
3812 g_value_unset (&rtcp_auth);
3813 gst_buffer_unref (buf);
3816 name = g_strdup_printf ("rtcp_sink_%d", session);
3817 pad = gst_element_get_request_pad (stream->srtpenc, name);
3819 gst_object_unref (pad);
3821 return gst_object_ref (stream->srtpenc);
3825 request_aux_receiver (GstElement * rtpbin, guint sessid, GstRTSPSrc * src)
3827 GstElement *rtx, *bin;
3830 GstRTSPStream *stream;
3832 stream = find_stream (src, &sessid, (gpointer) find_stream_by_id);
3834 GST_WARNING_OBJECT (src, "Stream %u not found", sessid);
3838 GST_INFO_OBJECT (src, "creating retransmision receiver for session %u "
3839 "with map %" GST_PTR_FORMAT, sessid, stream->rtx_pt_map);
3840 bin = gst_bin_new (NULL);
3841 rtx = gst_element_factory_make ("rtprtxreceive", NULL);
3842 g_object_set (rtx, "payload-type-map", stream->rtx_pt_map, NULL);
3843 gst_bin_add (GST_BIN (bin), rtx);
3845 pad = gst_element_get_static_pad (rtx, "src");
3846 name = g_strdup_printf ("src_%u", sessid);
3847 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
3849 gst_object_unref (pad);
3851 pad = gst_element_get_static_pad (rtx, "sink");
3852 name = g_strdup_printf ("sink_%u", sessid);
3853 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
3855 gst_object_unref (pad);
3861 add_retransmission (GstRTSPSrc * src, GstRTSPTransport * transport)
3865 gboolean do_retransmission = FALSE;
3867 if (transport->trans != GST_RTSP_TRANS_RTP)
3869 if (transport->profile != GST_RTSP_PROFILE_AVPF &&
3870 transport->profile != GST_RTSP_PROFILE_SAVPF)
3873 signal_id = g_signal_lookup ("request-aux-receiver",
3874 G_OBJECT_TYPE (src->manager));
3875 /* there's already something connected */
3876 if (g_signal_handler_find (src->manager, G_SIGNAL_MATCH_ID, signal_id, 0,
3877 NULL, NULL, NULL) != 0) {
3878 GST_DEBUG_OBJECT (src, "Not adding RTX AUX element as "
3879 "\"request-aux-receiver\" signal is "
3880 "already used by the application");
3884 /* build the retransmission payload type map */
3885 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3886 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3887 gboolean do_retransmission_stream = FALSE;
3890 if (stream->rtx_pt_map)
3891 gst_structure_free (stream->rtx_pt_map);
3892 stream->rtx_pt_map = gst_structure_new_empty ("application/x-rtp-pt-map");
3894 for (i = 0; i < stream->ptmap->len; i++) {
3895 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
3896 GstStructure *s = gst_caps_get_structure (item->caps, 0);
3897 const gchar *encoding;
3899 /* we only care about RTX streams */
3900 if ((encoding = gst_structure_get_string (s, "encoding-name"))
3901 && g_strcmp0 (encoding, "RTX") == 0) {
3902 const gchar *stream_pt_s;
3905 if (gst_structure_get_int (s, "payload", &rtx_pt)
3906 && (stream_pt_s = gst_structure_get_string (s, "apt"))) {
3909 gst_structure_set (stream->rtx_pt_map, stream_pt_s, G_TYPE_UINT,
3911 do_retransmission_stream = TRUE;
3917 if (do_retransmission_stream) {
3918 GST_DEBUG_OBJECT (src, "built retransmission payload map for stream "
3919 "id %i: %" GST_PTR_FORMAT, stream->id, stream->rtx_pt_map);
3920 do_retransmission = TRUE;
3922 GST_DEBUG_OBJECT (src, "no retransmission payload map for stream "
3923 "id %i", stream->id);
3924 gst_structure_free (stream->rtx_pt_map);
3925 stream->rtx_pt_map = NULL;
3929 if (do_retransmission) {
3930 GST_DEBUG_OBJECT (src, "Enabling retransmissions");
3932 g_object_set (src->manager, "do-retransmission", TRUE, NULL);
3934 /* enable RFC4588 retransmission handling by setting rtprtxreceive
3935 * as the "aux" element of rtpbin */
3936 g_signal_connect (src->manager, "request-aux-receiver",
3937 (GCallback) request_aux_receiver, src);
3939 GST_DEBUG_OBJECT (src,
3940 "Not enabling retransmissions as no stream had a retransmission payload map");
3944 /* try to get and configure a manager */
3946 gst_rtspsrc_stream_configure_manager (GstRTSPSrc * src, GstRTSPStream * stream,
3947 GstRTSPTransport * transport)
3949 const gchar *manager;
3951 GstStateChangeReturn ret;
3953 /* find a manager */
3954 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 0) < 0)
3958 GST_DEBUG_OBJECT (src, "using manager %s", manager);
3960 /* configure the manager */
3961 if (src->manager == NULL) {
3962 GObjectClass *klass;
3964 if (!(src->manager = gst_element_factory_make (manager, "manager"))) {
3966 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 1) < 0)
3970 goto use_no_manager;
3972 if (!(src->manager = gst_element_factory_make (manager, "manager")))
3973 goto manager_failed;
3975 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
3976 if (g_strcmp0 (manager, "rtpbin") == 0) {
3977 /* set for player rtsp buffering */
3978 g_object_set (src->manager, "use-rtsp-buffering", TRUE, NULL);
3982 /* we manage this element */
3983 gst_element_set_locked_state (src->manager, TRUE);
3984 gst_bin_add (GST_BIN_CAST (src), src->manager);
3986 ret = gst_element_set_state (src->manager, GST_STATE_PAUSED);
3987 if (ret == GST_STATE_CHANGE_FAILURE)
3988 goto start_manager_failure;
3990 g_object_set (src->manager, "latency", src->latency, NULL);
3992 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
3994 if (g_object_class_find_property (klass, "ntp-sync")) {
3995 g_object_set (src->manager, "ntp-sync", src->ntp_sync, NULL);
3998 if (g_object_class_find_property (klass, "rfc7273-sync")) {
3999 g_object_set (src->manager, "rfc7273-sync", src->rfc7273_sync, NULL);
4002 if (src->use_pipeline_clock) {
4003 if (g_object_class_find_property (klass, "use-pipeline-clock")) {
4004 g_object_set (src->manager, "use-pipeline-clock", TRUE, NULL);
4007 if (g_object_class_find_property (klass, "ntp-time-source")) {
4008 g_object_set (src->manager, "ntp-time-source", src->ntp_time_source,
4013 if (src->sdes && g_object_class_find_property (klass, "sdes")) {
4014 g_object_set (src->manager, "sdes", src->sdes, NULL);
4017 if (g_object_class_find_property (klass, "drop-on-latency")) {
4018 g_object_set (src->manager, "drop-on-latency", src->drop_on_latency,
4022 if (g_object_class_find_property (klass, "max-rtcp-rtp-time-diff")) {
4023 g_object_set (src->manager, "max-rtcp-rtp-time-diff",
4024 src->max_rtcp_rtp_time_diff, NULL);
4027 if (g_object_class_find_property (klass, "max-ts-offset-adjustment")) {
4028 g_object_set (src->manager, "max-ts-offset-adjustment",
4029 src->max_ts_offset_adjustment, NULL);
4032 if (g_object_class_find_property (klass, "max-ts-offset")) {
4033 gint64 max_ts_offset;
4035 /* setting max-ts-offset in the manager has side effects so only do it
4036 * if the value differs */
4037 g_object_get (src->manager, "max-ts-offset", &max_ts_offset, NULL);
4038 if (max_ts_offset != src->max_ts_offset) {
4039 g_object_set (src->manager, "max-ts-offset", src->max_ts_offset,
4044 /* buffer mode pauses are handled by adding offsets to buffer times,
4045 * but some depayloaders may have a hard time syncing output times
4046 * with such input times, e.g. container ones, most notably ASF */
4047 /* TODO alternatives are having an event that indicates these shifts,
4048 * or having rtsp extensions provide suggestion on buffer mode */
4049 /* valid duration implies not likely live pipeline,
4050 * so slaving in jitterbuffer does not make much sense
4051 * (and might mess things up due to bursts) */
4052 if (GST_CLOCK_TIME_IS_VALID (src->segment.duration) &&
4053 src->segment.duration && stream->container) {
4054 src->use_buffering = TRUE;
4056 src->use_buffering = FALSE;
4059 set_manager_buffer_mode (src);
4061 /* connect to signals */
4062 GST_DEBUG_OBJECT (src, "connect to signals on session manager, stream %p",
4064 src->manager_sig_id =
4065 g_signal_connect (src->manager, "pad-added",
4066 (GCallback) new_manager_pad, src);
4067 src->manager_ptmap_id =
4068 g_signal_connect (src->manager, "request-pt-map",
4069 (GCallback) request_pt_map, src);
4071 g_signal_connect (src->manager, "on-npt-stop", (GCallback) on_npt_stop,
4074 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_NEW_MANAGER], 0,
4077 if (src->do_retransmission)
4078 add_retransmission (src, transport);
4080 g_signal_connect (src->manager, "request-rtp-decoder",
4081 (GCallback) request_rtp_decoder, stream);
4082 g_signal_connect (src->manager, "request-rtcp-decoder",
4083 (GCallback) request_rtp_decoder, stream);
4084 g_signal_connect (src->manager, "request-rtcp-encoder",
4085 (GCallback) request_rtcp_encoder, stream);
4087 /* we stream directly to the manager, get some pads. Each RTSP stream goes
4088 * into a separate RTP session. */
4089 name = g_strdup_printf ("recv_rtp_sink_%u", stream->id);
4090 stream->channelpad[0] = gst_element_get_request_pad (src->manager, name);
4092 name = g_strdup_printf ("recv_rtcp_sink_%u", stream->id);
4093 stream->channelpad[1] = gst_element_get_request_pad (src->manager, name);
4096 /* now configure the bandwidth in the manager */
4097 if (g_signal_lookup ("get-internal-session",
4098 G_OBJECT_TYPE (src->manager)) != 0) {
4099 GObject *rtpsession;
4101 g_signal_emit_by_name (src->manager, "get-internal-session", stream->id,
4104 GstRTPProfile rtp_profile;
4106 GST_INFO_OBJECT (src, "configure bandwidth in session %p", rtpsession);
4108 stream->session = rtpsession;
4110 if (stream->as_bandwidth != -1) {
4111 GST_INFO_OBJECT (src, "setting AS: %f",
4112 (gdouble) (stream->as_bandwidth * 1000));
4113 g_object_set (rtpsession, "bandwidth",
4114 (gdouble) (stream->as_bandwidth * 1000), NULL);
4116 if (stream->rr_bandwidth != -1) {
4117 GST_INFO_OBJECT (src, "setting RR: %u", stream->rr_bandwidth);
4118 g_object_set (rtpsession, "rtcp-rr-bandwidth", stream->rr_bandwidth,
4121 if (stream->rs_bandwidth != -1) {
4122 GST_INFO_OBJECT (src, "setting RS: %u", stream->rs_bandwidth);
4123 g_object_set (rtpsession, "rtcp-rs-bandwidth", stream->rs_bandwidth,
4127 switch (stream->profile) {
4128 case GST_RTSP_PROFILE_AVPF:
4129 rtp_profile = GST_RTP_PROFILE_AVPF;
4131 case GST_RTSP_PROFILE_SAVP:
4132 rtp_profile = GST_RTP_PROFILE_SAVP;
4134 case GST_RTSP_PROFILE_SAVPF:
4135 rtp_profile = GST_RTP_PROFILE_SAVPF;
4137 case GST_RTSP_PROFILE_AVP:
4139 rtp_profile = GST_RTP_PROFILE_AVP;
4143 g_object_set (rtpsession, "rtp-profile", rtp_profile, NULL);
4145 g_object_set (rtpsession, "probation", src->probation, NULL);
4147 g_object_set (rtpsession, "internal-ssrc", stream->send_ssrc, NULL);
4149 g_signal_connect (rtpsession, "on-bye-ssrc", (GCallback) on_bye_ssrc,
4151 g_signal_connect (rtpsession, "on-bye-timeout",
4152 (GCallback) on_timeout_common, stream);
4153 g_signal_connect (rtpsession, "on-timeout", (GCallback) on_timeout,
4155 g_signal_connect (rtpsession, "on-ssrc-active",
4156 (GCallback) on_ssrc_active, stream);
4167 GST_DEBUG_OBJECT (src, "cannot get a session manager");
4172 GST_DEBUG_OBJECT (src, "no session manager element %s found", manager);
4175 start_manager_failure:
4177 GST_DEBUG_OBJECT (src, "could not start session manager");
4182 /* free the UDP sources allocated when negotiating a transport.
4183 * This function is called when the server negotiated to a transport where the
4184 * UDP sources are not needed anymore, such as TCP or multicast. */
4186 gst_rtspsrc_stream_free_udp (GstRTSPStream * stream)
4190 for (i = 0; i < 2; i++) {
4191 if (stream->udpsrc[i]) {
4192 GST_DEBUG ("free UDP source %d for stream %p", i, stream);
4193 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
4194 gst_object_unref (stream->udpsrc[i]);
4195 stream->udpsrc[i] = NULL;
4200 /* for TCP, create pads to send and receive data to and from the manager and to
4201 * intercept various events and queries
4204 gst_rtspsrc_stream_configure_tcp (GstRTSPSrc * src, GstRTSPStream * stream,
4205 GstRTSPTransport * transport, GstPad ** outpad)
4208 GstPadTemplate *template;
4209 GstPad *pad0, *pad1;
4211 /* configure for interleaved delivery, nothing needs to be done
4212 * here, the loop function will call the chain functions of the
4213 * session manager. */
4214 stream->channel[0] = transport->interleaved.min;
4215 stream->channel[1] = transport->interleaved.max;
4216 GST_DEBUG_OBJECT (src, "stream %p on channels %d-%d", stream,
4217 stream->channel[0], stream->channel[1]);
4219 /* we can remove the allocated UDP ports now */
4220 gst_rtspsrc_stream_free_udp (stream);
4222 /* no session manager, send data to srcpad directly */
4223 if (!stream->channelpad[0]) {
4224 GST_DEBUG_OBJECT (src, "no manager, creating pad");
4226 /* create a new pad we will use to stream to */
4227 name = g_strdup_printf ("stream_%u", stream->id);
4228 template = gst_static_pad_template_get (&rtptemplate);
4229 stream->channelpad[0] = gst_pad_new_from_template (template, name);
4230 gst_object_unref (template);
4233 /* set caps and activate */
4234 gst_pad_use_fixed_caps (stream->channelpad[0]);
4235 gst_pad_set_active (stream->channelpad[0], TRUE);
4237 *outpad = gst_object_ref (stream->channelpad[0]);
4239 GST_DEBUG_OBJECT (src, "using manager source pad");
4241 template = gst_static_pad_template_get (&anysrctemplate);
4243 /* allocate pads for sending the channel data into the manager */
4244 pad0 = gst_pad_new_from_template (template, "internalsrc_0");
4245 gst_pad_link_full (pad0, stream->channelpad[0], GST_PAD_LINK_CHECK_NOTHING);
4246 gst_object_unref (stream->channelpad[0]);
4247 stream->channelpad[0] = pad0;
4248 gst_pad_set_event_function (pad0, gst_rtspsrc_handle_internal_src_event);
4249 gst_pad_set_query_function (pad0, gst_rtspsrc_handle_internal_src_query);
4250 gst_pad_set_element_private (pad0, src);
4251 gst_pad_set_active (pad0, TRUE);
4253 if (stream->channelpad[1]) {
4254 /* if we have a sinkpad for the other channel, create a pad and link to the
4256 pad1 = gst_pad_new_from_template (template, "internalsrc_1");
4257 gst_pad_set_event_function (pad1, gst_rtspsrc_handle_internal_src_event);
4258 gst_pad_link_full (pad1, stream->channelpad[1],
4259 GST_PAD_LINK_CHECK_NOTHING);
4260 gst_object_unref (stream->channelpad[1]);
4261 stream->channelpad[1] = pad1;
4262 gst_pad_set_active (pad1, TRUE);
4264 gst_object_unref (template);
4266 /* setup RTCP transport back to the server if we have to. */
4267 if (src->manager && src->do_rtcp) {
4270 template = gst_static_pad_template_get (&anysinktemplate);
4272 stream->rtcppad = gst_pad_new_from_template (template, "internalsink_0");
4273 gst_pad_set_chain_function (stream->rtcppad, gst_rtspsrc_sink_chain);
4274 gst_pad_set_element_private (stream->rtcppad, stream);
4275 gst_pad_set_active (stream->rtcppad, TRUE);
4277 /* get session RTCP pad */
4278 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
4279 pad = gst_element_get_request_pad (src->manager, name);
4284 gst_pad_link_full (pad, stream->rtcppad, GST_PAD_LINK_CHECK_NOTHING);
4285 gst_object_unref (pad);
4288 gst_object_unref (template);
4294 gst_rtspsrc_get_transport_info (GstRTSPSrc * src, GstRTSPStream * stream,
4295 GstRTSPTransport * transport, const gchar ** destination, gint * min,
4296 gint * max, guint * ttl)
4298 if (transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
4300 if (!(*destination = transport->destination))
4301 *destination = stream->destination;
4304 /* transport first */
4305 *min = transport->port.min;
4306 *max = transport->port.max;
4307 if (*min == -1 && *max == -1) {
4308 /* then try from SDP */
4309 if (stream->port != 0) {
4310 *min = stream->port;
4311 *max = stream->port + 1;
4317 if (!(*ttl = transport->ttl))
4322 /* first take the source, then the endpoint to figure out where to send
4324 if (!(*destination = transport->source)) {
4325 if (src->conninfo.connection)
4326 *destination = gst_rtsp_connection_get_ip (src->conninfo.connection);
4327 else if (stream->conninfo.connection)
4329 gst_rtsp_connection_get_ip (stream->conninfo.connection);
4333 /* for unicast we only expect the ports here */
4334 *min = transport->server_port.min;
4335 *max = transport->server_port.max;
4340 /* For multicast create UDP sources and join the multicast group. */
4342 gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
4343 GstRTSPTransport * transport, GstPad ** outpad)
4346 const gchar *destination;
4349 GST_DEBUG_OBJECT (src, "creating UDP sources for multicast");
4351 /* we can remove the allocated UDP ports now */
4352 gst_rtspsrc_stream_free_udp (stream);
4354 gst_rtspsrc_get_transport_info (src, stream, transport, &destination, &min,
4357 /* we need a destination now */
4358 if (destination == NULL)
4359 goto no_destination;
4361 /* we really need ports now or we won't be able to receive anything at all */
4362 if (min == -1 && max == -1)
4365 GST_DEBUG_OBJECT (src, "have destination '%s' and ports (%d)-(%d)",
4366 destination, min, max);
4368 /* creating UDP source for RTP */
4370 uri = g_strdup_printf ("udp://%s:%d", destination, min);
4372 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
4374 if (stream->udpsrc[0] == NULL)
4377 /* take ownership */
4378 gst_object_ref_sink (stream->udpsrc[0]);
4380 if (src->udp_buffer_size != 0)
4381 g_object_set (G_OBJECT (stream->udpsrc[0]), "buffer-size",
4382 src->udp_buffer_size, NULL);
4384 if (src->multi_iface != NULL)
4385 g_object_set (G_OBJECT (stream->udpsrc[0]), "multicast-iface",
4386 src->multi_iface, NULL);
4389 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
4390 gst_element_set_state (stream->udpsrc[0], GST_STATE_READY);
4393 /* creating another UDP source for RTCP */
4397 uri = g_strdup_printf ("udp://%s:%d", destination, max);
4399 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
4401 if (stream->udpsrc[1] == NULL)
4404 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
4405 stream->profile == GST_RTSP_PROFILE_SAVPF)
4406 caps = gst_caps_new_empty_simple ("application/x-srtcp");
4408 caps = gst_caps_new_empty_simple ("application/x-rtcp");
4409 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
4410 gst_caps_unref (caps);
4412 /* take ownership */
4413 gst_object_ref_sink (stream->udpsrc[1]);
4415 if (src->multi_iface != NULL)
4416 g_object_set (G_OBJECT (stream->udpsrc[1]), "multicast-iface",
4417 src->multi_iface, NULL);
4419 gst_element_set_state (stream->udpsrc[1], GST_STATE_READY);
4426 GST_DEBUG_OBJECT (src, "no UDP source element found");
4431 GST_DEBUG_OBJECT (src, "no destination found");
4436 GST_DEBUG_OBJECT (src, "no ports found");
4441 /* configure the remainder of the UDP ports */
4443 gst_rtspsrc_stream_configure_udp (GstRTSPSrc * src, GstRTSPStream * stream,
4444 GstRTSPTransport * transport, GstPad ** outpad)
4446 /* we manage the UDP elements now. For unicast, the UDP sources where
4447 * allocated in the stream when we suggested a transport. */
4448 if (stream->udpsrc[0]) {
4451 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
4452 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[0]);
4454 GST_DEBUG_OBJECT (src, "setting up UDP source");
4456 /* configure a timeout on the UDP port. When the timeout message is
4457 * posted, we assume UDP transport is not possible. We reconnect using TCP
4459 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout",
4460 src->udp_timeout * 1000, NULL);
4462 if ((caps = stream_get_caps_for_pt (stream, stream->default_pt)))
4463 g_object_set (stream->udpsrc[0], "caps", caps, NULL);
4465 /* get output pad of the UDP source. */
4466 *outpad = gst_element_get_static_pad (stream->udpsrc[0], "src");
4468 /* save it so we can unblock */
4469 stream->blockedpad = *outpad;
4471 /* configure pad block on the pad. As soon as there is dataflow on the
4472 * UDP source, we know that UDP is not blocked by a firewall and we can
4473 * configure all the streams to let the application autoplug decoders. */
4475 gst_pad_add_probe (stream->blockedpad,
4476 GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
4477 GST_PAD_PROBE_TYPE_BUFFER_LIST, pad_blocked, src, NULL);
4479 gst_pad_add_probe (stream->blockedpad,
4480 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, udpsrc_probe_cb,
4481 &(stream->segment_seqnum[0]), NULL);
4483 if (stream->channelpad[0]) {
4484 GST_DEBUG_OBJECT (src, "connecting UDP source 0 to manager");
4485 /* configure for UDP delivery, we need to connect the UDP pads to
4486 * the session plugin. */
4487 gst_pad_link_full (*outpad, stream->channelpad[0],
4488 GST_PAD_LINK_CHECK_NOTHING);
4489 gst_object_unref (*outpad);
4491 /* we connected to pad-added signal to get pads from the manager */
4493 GST_DEBUG_OBJECT (src, "using UDP src pad as output");
4498 if (stream->udpsrc[1]) {
4501 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
4502 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[1]);
4504 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
4505 stream->profile == GST_RTSP_PROFILE_SAVPF)
4506 caps = gst_caps_new_empty_simple ("application/x-srtcp");
4508 caps = gst_caps_new_empty_simple ("application/x-rtcp");
4509 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
4510 gst_caps_unref (caps);
4512 if (stream->channelpad[1]) {
4515 GST_DEBUG_OBJECT (src, "connecting UDP source 1 to manager");
4517 pad = gst_element_get_static_pad (stream->udpsrc[1], "src");
4518 gst_pad_add_probe (pad,
4519 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, udpsrc_probe_cb,
4520 &(stream->segment_seqnum[1]), NULL);
4521 gst_pad_link_full (pad, stream->channelpad[1],
4522 GST_PAD_LINK_CHECK_NOTHING);
4523 gst_object_unref (pad);
4525 /* leave unlinked */
4531 /* configure the UDP sink back to the server for status reports */
4533 gst_rtspsrc_stream_configure_udp_sinks (GstRTSPSrc * src,
4534 GstRTSPStream * stream, GstRTSPTransport * transport)
4537 gint rtp_port, rtcp_port;
4538 gboolean do_rtp, do_rtcp;
4539 const gchar *destination;
4544 /* get transport info */
4545 gst_rtspsrc_get_transport_info (src, stream, transport, &destination,
4546 &rtp_port, &rtcp_port, &ttl);
4548 /* see what we need to do */
4549 do_rtp = (rtp_port != -1);
4550 /* it's possible that the server does not want us to send RTCP in which case
4552 do_rtcp = (rtcp_port != -1 && src->manager != NULL && src->do_rtcp);
4554 /* we need a destination when we have RTP or RTCP ports */
4555 if (destination == NULL && (do_rtp || do_rtcp))
4556 goto no_destination;
4558 /* try to construct the fakesrc to the RTP port of the server to open up any
4559 * NAT firewalls or, if backchannel, construct an appsrc */
4561 GST_DEBUG_OBJECT (src, "configure RTP UDP sink for %s:%d", destination,
4564 uri = g_strdup_printf ("udp://%s:%d", destination, rtp_port);
4565 stream->udpsink[0] =
4566 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
4568 if (stream->udpsink[0] == NULL)
4569 goto no_sink_element;
4571 /* don't join multicast group, we will have the source socket do that */
4572 /* no sync or async state changes needed */
4573 g_object_set (G_OBJECT (stream->udpsink[0]), "auto-multicast", FALSE,
4574 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
4576 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
4578 if (stream->udpsrc[0]) {
4579 /* configure socket, we give it the same UDP socket as the udpsrc for RTP
4580 * so that NAT firewalls will open a hole for us */
4581 g_object_get (G_OBJECT (stream->udpsrc[0]), "used-socket", &socket, NULL);
4585 GST_DEBUG_OBJECT (src, "RTP UDP src has sock %p", socket);
4586 /* configure socket and make sure udpsink does not close it when shutting
4587 * down, it belongs to udpsrc after all. */
4588 g_object_set (G_OBJECT (stream->udpsink[0]), "socket", socket,
4589 "close-socket", FALSE, NULL);
4590 g_object_unref (socket);
4593 if (stream->is_backchannel) {
4594 /* appsrc is for the app to shovel data using push-backchannel-buffer */
4595 stream->rtpsrc = gst_element_factory_make ("appsrc", NULL);
4596 if (stream->rtpsrc == NULL)
4597 goto no_appsrc_element;
4599 /* interal use only, don't emit signals */
4600 g_object_set (G_OBJECT (stream->rtpsrc), "emit-signals", TRUE,
4601 "is-live", TRUE, NULL);
4603 /* the source for the dummy packets to open up NAT */
4604 stream->rtpsrc = gst_element_factory_make ("fakesrc", NULL);
4605 if (stream->rtpsrc == NULL)
4606 goto no_fakesrc_element;
4608 /* random data in 5 buffers, a size of 200 bytes should be fine */
4609 g_object_set (G_OBJECT (stream->rtpsrc), "filltype", 3, "num-buffers", 5,
4610 "sizetype", 2, "sizemax", 200, "silent", TRUE, NULL);
4613 /* keep everything locked */
4614 gst_element_set_locked_state (stream->udpsink[0], TRUE);
4615 gst_element_set_locked_state (stream->rtpsrc, TRUE);
4617 gst_object_ref (stream->udpsink[0]);
4618 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[0]);
4619 gst_object_ref (stream->rtpsrc);
4620 gst_bin_add (GST_BIN_CAST (src), stream->rtpsrc);
4622 gst_element_link_pads_full (stream->rtpsrc, "src", stream->udpsink[0],
4623 "sink", GST_PAD_LINK_CHECK_NOTHING);
4626 GST_DEBUG_OBJECT (src, "configure RTCP UDP sink for %s:%d", destination,
4629 uri = g_strdup_printf ("udp://%s:%d", destination, rtcp_port);
4630 stream->udpsink[1] =
4631 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
4633 if (stream->udpsink[1] == NULL)
4634 goto no_sink_element;
4636 /* don't join multicast group, we will have the source socket do that */
4637 /* no sync or async state changes needed */
4638 g_object_set (G_OBJECT (stream->udpsink[1]), "auto-multicast", FALSE,
4639 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
4641 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
4643 if (stream->udpsrc[1]) {
4644 /* configure socket, we give it the same UDP socket as the udpsrc for RTCP
4645 * because some servers check the port number of where it sends RTCP to identify
4646 * the RTCP packets it receives */
4647 g_object_get (G_OBJECT (stream->udpsrc[1]), "used-socket", &socket, NULL);
4651 GST_DEBUG_OBJECT (src, "RTCP UDP src has sock %p", socket);
4652 /* configure socket and make sure udpsink does not close it when shutting
4653 * down, it belongs to udpsrc after all. */
4654 g_object_set (G_OBJECT (stream->udpsink[1]), "socket", socket,
4655 "close-socket", FALSE, NULL);
4656 g_object_unref (socket);
4659 /* we keep this playing always */
4660 gst_element_set_locked_state (stream->udpsink[1], TRUE);
4661 gst_element_set_state (stream->udpsink[1], GST_STATE_PLAYING);
4663 gst_object_ref (stream->udpsink[1]);
4664 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[1]);
4666 stream->rtcppad = gst_element_get_static_pad (stream->udpsink[1], "sink");
4668 /* get session RTCP pad */
4669 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
4670 pad = gst_element_get_request_pad (src->manager, name);
4675 gst_pad_link_full (pad, stream->rtcppad, GST_PAD_LINK_CHECK_NOTHING);
4676 gst_object_unref (pad);
4685 GST_ERROR_OBJECT (src, "no destination address specified");
4690 GST_ERROR_OBJECT (src, "no UDP sink element found");
4695 GST_ERROR_OBJECT (src, "no appsrc element found");
4700 GST_ERROR_OBJECT (src, "no fakesrc element found");
4705 GST_ERROR_OBJECT (src, "failed to create socket");
4710 /* sets up all elements needed for streaming over the specified transport.
4711 * Does not yet expose the element pads, this will be done when there is actuall
4712 * dataflow detected, which might never happen when UDP is blocked in a
4713 * firewall, for example.
4716 gst_rtspsrc_stream_configure_transport (GstRTSPStream * stream,
4717 GstRTSPTransport * transport)
4720 GstPad *outpad = NULL;
4721 GstPadTemplate *template;
4723 const gchar *media_type;
4726 src = stream->parent;
4728 GST_DEBUG_OBJECT (src, "configuring transport for stream %p", stream);
4730 /* get the proper media type for this stream now */
4731 if (gst_rtsp_transport_get_media_type (transport, &media_type) < 0)
4732 goto unknown_transport;
4734 goto unknown_transport;
4736 /* configure the final media type */
4737 GST_DEBUG_OBJECT (src, "setting media type to %s", media_type);
4739 len = stream->ptmap->len;
4740 for (i = 0; i < len; i++) {
4742 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
4744 if (item->caps == NULL)
4747 s = gst_caps_get_structure (item->caps, 0);
4748 gst_structure_set_name (s, media_type);
4749 /* set ssrc if known */
4750 if (transport->ssrc)
4751 gst_structure_set (s, "ssrc", G_TYPE_UINT, transport->ssrc, NULL);
4754 /* try to get and configure a manager, channelpad[0-1] will be configured with
4755 * the pads for the manager, or NULL when no manager is needed. */
4756 if (!gst_rtspsrc_stream_configure_manager (src, stream, transport))
4759 switch (transport->lower_transport) {
4760 case GST_RTSP_LOWER_TRANS_TCP:
4761 if (!gst_rtspsrc_stream_configure_tcp (src, stream, transport, &outpad))
4762 goto transport_failed;
4764 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
4765 if (!gst_rtspsrc_stream_configure_mcast (src, stream, transport, &outpad))
4766 goto transport_failed;
4767 /* fallthrough, the rest is the same for UDP and MCAST */
4768 case GST_RTSP_LOWER_TRANS_UDP:
4769 if (!gst_rtspsrc_stream_configure_udp (src, stream, transport, &outpad))
4770 goto transport_failed;
4771 /* configure udpsinks back to the server for RTCP messages, for the
4772 * dummy RTP messages to open NAT, and for the backchannel */
4773 if (!gst_rtspsrc_stream_configure_udp_sinks (src, stream, transport))
4774 goto transport_failed;
4777 goto unknown_transport;
4780 /* using backchannel and no manager, hence no srcpad for this stream */
4781 if (outpad && stream->is_backchannel) {
4782 add_backchannel_fakesink (src, stream, outpad);
4783 gst_object_unref (outpad);
4784 } else if (outpad) {
4785 GST_DEBUG_OBJECT (src, "creating ghostpad for stream %p", stream);
4787 gst_pad_use_fixed_caps (outpad);
4789 /* create ghostpad, don't add just yet, this will be done when we activate
4791 name = g_strdup_printf ("stream_%u", stream->id);
4792 template = gst_static_pad_template_get (&rtptemplate);
4793 stream->srcpad = gst_ghost_pad_new_from_template (name, outpad, template);
4794 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
4795 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
4796 gst_object_unref (template);
4799 gst_object_unref (outpad);
4801 /* mark pad as ok */
4802 stream->last_ret = GST_FLOW_OK;
4809 GST_WARNING_OBJECT (src, "failed to configure transport");
4814 GST_WARNING_OBJECT (src, "unknown transport");
4819 GST_WARNING_OBJECT (src, "cannot get a session manager");
4824 /* send a couple of dummy random packets on the receiver RTP port to the server,
4825 * this should make a firewall think we initiated the data transfer and
4826 * hopefully allow packets to go from the sender port to our RTP receiver port */
4828 gst_rtspsrc_send_dummy_packets (GstRTSPSrc * src)
4832 if (src->nat_method != GST_RTSP_NAT_DUMMY)
4835 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4836 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4838 if (!stream->rtpsrc || !stream->udpsink[0])
4841 if (stream->is_backchannel)
4842 GST_DEBUG_OBJECT (src, "starting backchannel stream %p", stream);
4844 GST_DEBUG_OBJECT (src, "sending dummy packet to stream %p", stream);
4846 gst_element_set_state (stream->udpsink[0], GST_STATE_NULL);
4847 gst_element_set_state (stream->rtpsrc, GST_STATE_NULL);
4848 gst_element_set_state (stream->udpsink[0], GST_STATE_PLAYING);
4849 gst_element_set_state (stream->rtpsrc, GST_STATE_PLAYING);
4854 /* Adds the source pads of all configured streams to the element.
4855 * This code is performed when we detected dataflow.
4857 * We detect dataflow from either the _loop function or with pad probes on the
4861 gst_rtspsrc_activate_streams (GstRTSPSrc * src)
4865 GST_DEBUG_OBJECT (src, "activating streams");
4867 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4868 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4870 if (stream->udpsrc[0]) {
4871 /* remove timeout, we are streaming now and timeouts will be handled by
4872 * the session manager and jitter buffer */
4873 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout", (guint64) 0, NULL);
4875 if (stream->srcpad) {
4876 GST_DEBUG_OBJECT (src, "activating stream pad %p", stream);
4877 gst_pad_set_active (stream->srcpad, TRUE);
4879 /* if we don't have a session manager, set the caps now. If we have a
4880 * session, we will get a notification of the pad and the caps. */
4881 if (!src->manager) {
4884 caps = stream_get_caps_for_pt (stream, stream->default_pt);
4885 GST_DEBUG_OBJECT (src, "setting pad caps for stream %p", stream);
4886 gst_pad_set_caps (stream->srcpad, caps);
4889 if (!stream->added) {
4890 GST_DEBUG_OBJECT (src, "adding stream pad %p", stream);
4891 if (stream->is_backchannel)
4892 add_backchannel_fakesink (src, stream, stream->srcpad);
4894 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
4895 stream->added = TRUE;
4900 /* unblock all pads */
4901 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4902 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4904 if (stream->blockid) {
4905 GST_DEBUG_OBJECT (src, "unblocking stream pad %p", stream);
4906 gst_pad_remove_probe (stream->blockedpad, stream->blockid);
4907 stream->blockid = 0;
4915 gst_rtspsrc_configure_caps (GstRTSPSrc * src, GstSegment * segment,
4916 gboolean reset_manager)
4919 guint64 start, stop;
4920 gdouble play_speed, play_scale;
4922 GST_DEBUG_OBJECT (src, "configuring stream caps");
4924 start = segment->position;
4925 stop = segment->duration;
4926 play_speed = segment->rate;
4927 play_scale = segment->applied_rate;
4929 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4930 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4936 len = stream->ptmap->len;
4937 for (j = 0; j < len; j++) {
4939 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, j);
4941 if (item->caps == NULL)
4944 caps = gst_caps_make_writable (item->caps);
4946 if (stream->timebase != -1)
4947 gst_caps_set_simple (caps, "clock-base", G_TYPE_UINT,
4948 (guint) stream->timebase, NULL);
4949 if (stream->seqbase != -1)
4950 gst_caps_set_simple (caps, "seqnum-base", G_TYPE_UINT,
4951 (guint) stream->seqbase, NULL);
4952 gst_caps_set_simple (caps, "npt-start", G_TYPE_UINT64, start, NULL);
4954 gst_caps_set_simple (caps, "npt-stop", G_TYPE_UINT64, stop, NULL);
4955 gst_caps_set_simple (caps, "play-speed", G_TYPE_DOUBLE, play_speed, NULL);
4956 gst_caps_set_simple (caps, "play-scale", G_TYPE_DOUBLE, play_scale, NULL);
4959 GST_DEBUG_OBJECT (src, "stream %p, pt %d, caps %" GST_PTR_FORMAT, stream,
4962 if (item->pt == stream->default_pt) {
4963 if (stream->udpsrc[0])
4964 g_object_set (stream->udpsrc[0], "caps", caps, NULL);
4965 stream->need_caps = TRUE;
4969 if (reset_manager && src->manager) {
4970 GST_DEBUG_OBJECT (src, "clear session");
4971 g_signal_emit_by_name (src->manager, "clear-pt-map", NULL);
4975 static GstFlowReturn
4976 gst_rtspsrc_combine_flows (GstRTSPSrc * src, GstRTSPStream * stream,
4981 /* store the value */
4982 stream->last_ret = ret;
4984 /* if it's success we can return the value right away */
4985 if (ret == GST_FLOW_OK)
4988 /* any other error that is not-linked can be returned right
4990 if (ret != GST_FLOW_NOT_LINKED)
4993 /* only return NOT_LINKED if all other pads returned NOT_LINKED */
4994 for (streams = src->streams; streams; streams = g_list_next (streams)) {
4995 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
4997 ret = ostream->last_ret;
4998 /* some other return value (must be SUCCESS but we can return
4999 * other values as well) */
5000 if (ret != GST_FLOW_NOT_LINKED)
5003 /* if we get here, all other pads were unlinked and we return
5004 * NOT_LINKED then */
5010 gst_rtspsrc_stream_push_event (GstRTSPSrc * src, GstRTSPStream * stream,
5013 gboolean res = TRUE;
5015 /* only streams that have a connection to the outside world */
5019 if (stream->udpsrc[0]) {
5020 GstEvent *sent_event;
5022 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
5023 sent_event = gst_event_new_eos ();
5024 gst_event_set_seqnum (sent_event, stream->segment_seqnum[0]);
5026 sent_event = gst_event_ref (event);
5029 res = gst_element_send_event (stream->udpsrc[0], sent_event);
5030 } else if (stream->channelpad[0]) {
5031 gst_event_ref (event);
5032 if (GST_PAD_IS_SRC (stream->channelpad[0]))
5033 res = gst_pad_push_event (stream->channelpad[0], event);
5035 res = gst_pad_send_event (stream->channelpad[0], event);
5038 if (stream->udpsrc[1]) {
5039 GstEvent *sent_event;
5041 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
5042 sent_event = gst_event_new_eos ();
5043 if (stream->segment_seqnum[1] != GST_SEQNUM_INVALID) {
5044 gst_event_set_seqnum (sent_event, stream->segment_seqnum[1]);
5047 sent_event = gst_event_ref (event);
5050 res &= gst_element_send_event (stream->udpsrc[1], sent_event);
5051 } else if (stream->channelpad[1]) {
5052 gst_event_ref (event);
5053 if (GST_PAD_IS_SRC (stream->channelpad[1]))
5054 res &= gst_pad_push_event (stream->channelpad[1], event);
5056 res &= gst_pad_send_event (stream->channelpad[1], event);
5060 gst_event_unref (event);
5066 gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event)
5069 gboolean res = TRUE;
5071 for (streams = src->streams; streams; streams = g_list_next (streams)) {
5072 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
5074 gst_event_ref (event);
5075 res &= gst_rtspsrc_stream_push_event (src, ostream, event);
5077 gst_event_unref (event);
5083 accept_certificate_cb (GTlsConnection * conn, GTlsCertificate * peer_cert,
5084 GTlsCertificateFlags errors, gpointer user_data)
5086 GstRTSPSrc *src = user_data;
5087 gboolean accept = FALSE;
5089 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_ACCEPT_CERTIFICATE], 0, conn,
5090 peer_cert, errors, &accept);
5095 static GstRTSPResult
5096 gst_rtsp_conninfo_connect (GstRTSPSrc * src, GstRTSPConnInfo * info,
5100 GstRTSPMessage response;
5101 gboolean retry = FALSE;
5102 memset (&response, 0, sizeof (response));
5103 gst_rtsp_message_init (&response);
5105 if (info->connection == NULL) {
5106 if (info->url == NULL) {
5107 GST_DEBUG_OBJECT (src, "parsing uri (%s)...", info->location);
5108 if ((res = gst_rtsp_url_parse (info->location, &info->url)) < 0)
5111 /* create connection */
5112 GST_DEBUG_OBJECT (src, "creating connection (%s)...", info->location);
5113 if ((res = gst_rtsp_connection_create (info->url, &info->connection)) < 0)
5114 goto could_not_create;
5117 gst_rtspsrc_setup_auth (src, &response);
5120 g_free (info->url_str);
5121 info->url_str = gst_rtsp_url_get_request_uri (info->url);
5123 GST_DEBUG_OBJECT (src, "sanitized uri %s", info->url_str);
5125 if (info->url->transports & GST_RTSP_LOWER_TRANS_TLS) {
5126 if (!gst_rtsp_connection_set_tls_validation_flags (info->connection,
5127 src->tls_validation_flags))
5128 GST_WARNING_OBJECT (src, "Unable to set TLS validation flags");
5130 if (src->tls_database)
5131 gst_rtsp_connection_set_tls_database (info->connection,
5134 if (src->tls_interaction)
5135 gst_rtsp_connection_set_tls_interaction (info->connection,
5136 src->tls_interaction);
5137 gst_rtsp_connection_set_accept_certificate_func (info->connection,
5138 accept_certificate_cb, src, NULL);
5141 if (info->url->transports & GST_RTSP_LOWER_TRANS_HTTP)
5142 gst_rtsp_connection_set_tunneled (info->connection, TRUE);
5144 if (src->proxy_host) {
5145 GST_DEBUG_OBJECT (src, "setting proxy %s:%d", src->proxy_host,
5147 gst_rtsp_connection_set_proxy (info->connection, src->proxy_host,
5152 if (!info->connected) {
5155 GST_ELEMENT_PROGRESS (src, CONTINUE, "connect",
5156 ("Connecting to %s", info->location));
5157 GST_DEBUG_OBJECT (src, "connecting (%s)...", info->location);
5158 res = gst_rtsp_connection_connect_with_response (info->connection,
5159 src->ptcp_timeout, &response);
5161 if (response.type == GST_RTSP_MESSAGE_HTTP_RESPONSE &&
5162 response.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
5163 gst_rtsp_conninfo_close (src, info, TRUE);
5167 retry = FALSE; // we should not retry more than once
5172 if (res == GST_RTSP_OK)
5173 info->connected = TRUE;
5175 goto could_not_connect;
5177 } while (!info->connected && retry);
5179 gst_rtsp_message_unset (&response);
5185 GST_ERROR_OBJECT (src, "No valid RTSP URL was provided");
5186 gst_rtsp_message_unset (&response);
5191 gchar *str = gst_rtsp_strresult (res);
5192 GST_ERROR_OBJECT (src, "Could not create connection. (%s)", str);
5194 gst_rtsp_message_unset (&response);
5199 gchar *str = gst_rtsp_strresult (res);
5200 GST_ERROR_OBJECT (src, "Could not connect to server. (%s)", str);
5202 gst_rtsp_message_unset (&response);
5207 static GstRTSPResult
5208 gst_rtsp_conninfo_close (GstRTSPSrc * src, GstRTSPConnInfo * info,
5211 GST_RTSP_STATE_LOCK (src);
5212 if (info->connected) {
5213 GST_DEBUG_OBJECT (src, "closing connection...");
5214 gst_rtsp_connection_close (info->connection);
5215 info->connected = FALSE;
5217 if (free && info->connection) {
5218 /* free connection */
5219 GST_DEBUG_OBJECT (src, "freeing connection...");
5220 gst_rtsp_connection_free (info->connection);
5221 info->connection = NULL;
5222 info->flushing = FALSE;
5224 GST_RTSP_STATE_UNLOCK (src);
5228 static GstRTSPResult
5229 gst_rtsp_conninfo_reconnect (GstRTSPSrc * src, GstRTSPConnInfo * info,
5234 GST_DEBUG_OBJECT (src, "reconnecting connection...");
5235 gst_rtsp_conninfo_close (src, info, FALSE);
5236 res = gst_rtsp_conninfo_connect (src, info, async);
5242 gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush)
5246 GST_DEBUG_OBJECT (src, "set flushing %d", flush);
5247 GST_RTSP_STATE_LOCK (src);
5248 if (src->conninfo.connection && src->conninfo.flushing != flush) {
5249 GST_DEBUG_OBJECT (src, "connection flush");
5250 gst_rtsp_connection_flush (src->conninfo.connection, flush);
5251 src->conninfo.flushing = flush;
5253 for (walk = src->streams; walk; walk = g_list_next (walk)) {
5254 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
5255 if (stream->conninfo.connection && stream->conninfo.flushing != flush) {
5256 GST_DEBUG_OBJECT (src, "stream %p flush", stream);
5257 gst_rtsp_connection_flush (stream->conninfo.connection, flush);
5258 stream->conninfo.flushing = flush;
5261 GST_RTSP_STATE_UNLOCK (src);
5264 static GstRTSPResult
5265 gst_rtspsrc_init_request (GstRTSPSrc * src, GstRTSPMessage * msg,
5266 GstRTSPMethod method, const gchar * uri)
5270 res = gst_rtsp_message_init_request (msg, method, uri);
5274 /* set user-agent */
5275 if (src->user_agent)
5276 gst_rtsp_message_add_header (msg, GST_RTSP_HDR_USER_AGENT, src->user_agent);
5281 /* FIXME, handle server request, reply with OK, for now */
5282 static GstRTSPResult
5283 gst_rtspsrc_handle_request (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
5284 GstRTSPMessage * request)
5286 GstRTSPMessage response = { 0 };
5289 GST_DEBUG_OBJECT (src, "got server request message");
5291 DEBUG_RTSP (src, request);
5293 res = gst_rtsp_ext_list_receive_request (src->extensions, request);
5295 if (res == GST_RTSP_ENOTIMPL) {
5296 /* default implementation, send OK */
5297 GST_DEBUG_OBJECT (src, "prepare OK reply");
5299 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, "OK",
5304 /* let app parse and reply */
5305 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST],
5306 0, request, &response);
5308 DEBUG_RTSP (src, &response);
5310 res = gst_rtspsrc_connection_send (src, conninfo, &response, NULL);
5314 gst_rtsp_message_unset (&response);
5315 } else if (res == GST_RTSP_EEOF)
5323 gst_rtsp_message_unset (&response);
5328 /* send server keep-alive */
5329 static GstRTSPResult
5330 gst_rtspsrc_send_keep_alive (GstRTSPSrc * src)
5332 GstRTSPMessage request = { 0 };
5334 GstRTSPMethod method;
5335 const gchar *control;
5337 if (src->do_rtsp_keep_alive == FALSE) {
5338 GST_DEBUG_OBJECT (src, "do-rtsp-keep-alive is FALSE, not sending.");
5339 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
5343 GST_DEBUG_OBJECT (src, "creating server keep-alive");
5345 /* find a method to use for keep-alive */
5346 if (src->methods & GST_RTSP_GET_PARAMETER)
5347 method = GST_RTSP_GET_PARAMETER;
5349 method = GST_RTSP_OPTIONS;
5351 control = get_aggregate_control (src);
5352 if (control == NULL)
5355 res = gst_rtspsrc_init_request (src, &request, method, control);
5359 request.type_data.request.version = src->version;
5361 res = gst_rtspsrc_connection_send (src, &src->conninfo, &request, NULL);
5365 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
5366 gst_rtsp_message_unset (&request);
5373 GST_WARNING_OBJECT (src, "no control url to send keepalive");
5378 gchar *str = gst_rtsp_strresult (res);
5380 gst_rtsp_message_unset (&request);
5381 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
5382 ("Could not send keep-alive. (%s)", str));
5388 static GstFlowReturn
5389 gst_rtspsrc_handle_data (GstRTSPSrc * src, GstRTSPMessage * message)
5391 GstFlowReturn ret = GST_FLOW_OK;
5393 GstRTSPStream *stream;
5394 GstPad *outpad = NULL;
5400 channel = message->type_data.data.channel;
5402 stream = find_stream (src, &channel, (gpointer) find_stream_by_channel);
5404 goto unknown_stream;
5406 if (channel == stream->channel[0]) {
5407 outpad = stream->channelpad[0];
5409 } else if (channel == stream->channel[1]) {
5410 outpad = stream->channelpad[1];
5416 /* take a look at the body to figure out what we have */
5417 gst_rtsp_message_get_body (message, &data, &size);
5419 goto invalid_length;
5421 /* channels are not correct on some servers, do extra check */
5422 if (data[1] >= 200 && data[1] <= 204) {
5423 /* hmm RTCP message switch to the RTCP pad of the same stream. */
5424 outpad = stream->channelpad[1];
5428 /* we have no clue what this is, just ignore then. */
5430 goto unknown_stream;
5432 /* take the message body for further processing */
5433 gst_rtsp_message_steal_body (message, &data, &size);
5435 /* strip the trailing \0 */
5438 buf = gst_buffer_new ();
5439 gst_buffer_append_memory (buf,
5440 gst_memory_new_wrapped (0, data, size, 0, size, data, g_free));
5442 /* don't need message anymore */
5443 gst_rtsp_message_unset (message);
5445 GST_DEBUG_OBJECT (src, "pushing data of size %d on channel %d", size,
5448 if (src->need_activate) {
5454 guint group_id = gst_util_group_id_next ();
5456 /* generate an SHA256 sum of the URI */
5457 cs = g_checksum_new (G_CHECKSUM_SHA256);
5458 uri = src->conninfo.location;
5459 g_checksum_update (cs, (const guchar *) uri, strlen (uri));
5461 for (streams = src->streams; streams; streams = g_list_next (streams)) {
5462 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
5466 g_strdup_printf ("%s/%d", g_checksum_get_string (cs), ostream->id);
5467 event = gst_event_new_stream_start (stream_id);
5468 gst_event_set_group_id (event, group_id);
5471 gst_rtspsrc_stream_push_event (src, ostream, event);
5473 if ((caps = stream_get_caps_for_pt (ostream, ostream->default_pt))) {
5474 /* only streams that have a connection to the outside world */
5475 if (ostream->setup) {
5476 if (ostream->udpsrc[0]) {
5477 gst_element_send_event (ostream->udpsrc[0],
5478 gst_event_new_caps (caps));
5479 } else if (ostream->channelpad[0]) {
5480 if (GST_PAD_IS_SRC (ostream->channelpad[0]))
5481 gst_pad_push_event (ostream->channelpad[0],
5482 gst_event_new_caps (caps));
5484 gst_pad_send_event (ostream->channelpad[0],
5485 gst_event_new_caps (caps));
5487 ostream->need_caps = FALSE;
5489 if (ostream->profile == GST_RTSP_PROFILE_SAVP ||
5490 ostream->profile == GST_RTSP_PROFILE_SAVPF)
5491 caps = gst_caps_new_empty_simple ("application/x-srtcp");
5493 caps = gst_caps_new_empty_simple ("application/x-rtcp");
5495 if (ostream->udpsrc[1]) {
5496 gst_element_send_event (ostream->udpsrc[1],
5497 gst_event_new_caps (caps));
5498 } else if (ostream->channelpad[1]) {
5499 if (GST_PAD_IS_SRC (ostream->channelpad[1]))
5500 gst_pad_push_event (ostream->channelpad[1],
5501 gst_event_new_caps (caps));
5503 gst_pad_send_event (ostream->channelpad[1],
5504 gst_event_new_caps (caps));
5507 gst_caps_unref (caps);
5511 g_checksum_free (cs);
5513 gst_rtspsrc_activate_streams (src);
5514 src->need_activate = FALSE;
5515 src->need_segment = TRUE;
5518 if (src->base_time == -1) {
5519 /* Take current running_time. This timestamp will be put on
5520 * the first buffer of each stream because we are a live source and so we
5521 * timestamp with the running_time. When we are dealing with TCP, we also
5522 * only timestamp the first buffer (using the DISCONT flag) because a server
5523 * typically bursts data, for which we don't want to compensate by speeding
5524 * up the media. The other timestamps will be interpollated from this one
5525 * using the RTP timestamps. */
5526 GST_OBJECT_LOCK (src);
5527 if (GST_ELEMENT_CLOCK (src)) {
5529 GstClockTime base_time;
5531 now = gst_clock_get_time (GST_ELEMENT_CLOCK (src));
5532 base_time = GST_ELEMENT_CAST (src)->base_time;
5534 src->base_time = now - base_time;
5536 GST_DEBUG_OBJECT (src, "first buffer at time %" GST_TIME_FORMAT ", base %"
5537 GST_TIME_FORMAT, GST_TIME_ARGS (now), GST_TIME_ARGS (base_time));
5539 GST_OBJECT_UNLOCK (src);
5542 /* If needed send a new segment, don't forget we are live and buffer are
5543 * timestamped with running time */
5544 if (src->need_segment) {
5546 src->need_segment = FALSE;
5547 gst_segment_init (&segment, GST_FORMAT_TIME);
5548 gst_rtspsrc_push_event (src, gst_event_new_segment (&segment));
5551 if (stream->need_caps) {
5554 if ((caps = stream_get_caps_for_pt (stream, stream->default_pt))) {
5555 /* only streams that have a connection to the outside world */
5556 if (stream->setup) {
5557 /* Only need to update the TCP caps here, UDP is already handled */
5558 if (stream->channelpad[0]) {
5559 if (GST_PAD_IS_SRC (stream->channelpad[0]))
5560 gst_pad_push_event (stream->channelpad[0],
5561 gst_event_new_caps (caps));
5563 gst_pad_send_event (stream->channelpad[0],
5564 gst_event_new_caps (caps));
5566 stream->need_caps = FALSE;
5570 stream->need_caps = FALSE;
5573 if (stream->discont && !is_rtcp) {
5574 /* mark first RTP buffer as discont */
5575 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
5576 stream->discont = FALSE;
5577 /* first buffer gets the timestamp, other buffers are not timestamped and
5578 * their presentation time will be interpollated from the rtp timestamps. */
5579 GST_DEBUG_OBJECT (src, "setting timestamp %" GST_TIME_FORMAT,
5580 GST_TIME_ARGS (src->base_time));
5582 GST_BUFFER_TIMESTAMP (buf) = src->base_time;
5585 /* chain to the peer pad */
5586 if (GST_PAD_IS_SINK (outpad))
5587 ret = gst_pad_chain (outpad, buf);
5589 ret = gst_pad_push (outpad, buf);
5592 /* combine all stream flows for the data transport */
5593 ret = gst_rtspsrc_combine_flows (src, stream, ret);
5600 GST_DEBUG_OBJECT (src, "unknown stream on channel %d, ignored", channel);
5601 gst_rtsp_message_unset (message);
5606 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5607 ("Short message received, ignoring."));
5608 gst_rtsp_message_unset (message);
5613 static GstFlowReturn
5614 gst_rtspsrc_loop_interleaved (GstRTSPSrc * src)
5616 GstRTSPMessage message = { 0 };
5618 GstFlowReturn ret = GST_FLOW_OK;
5619 GTimeVal tv_timeout;
5622 /* get the next timeout interval */
5623 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
5625 /* see if the timeout period expired */
5626 if ((tv_timeout.tv_sec | tv_timeout.tv_usec) == 0) {
5627 GST_DEBUG_OBJECT (src, "timout, sending keep-alive");
5628 /* send keep-alive, only act on interrupt, a warning will be posted for
5630 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5632 /* get new timeout */
5633 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
5636 GST_DEBUG_OBJECT (src, "doing receive with timeout %ld seconds, %ld usec",
5637 tv_timeout.tv_sec, tv_timeout.tv_usec);
5639 /* protect the connection with the connection lock so that we can see when
5640 * we are finished doing server communication */
5642 gst_rtspsrc_connection_receive (src, &src->conninfo,
5643 &message, src->ptcp_timeout);
5647 GST_DEBUG_OBJECT (src, "we received a server message");
5649 case GST_RTSP_EINTR:
5650 /* we got interrupted this means we need to stop */
5652 case GST_RTSP_ETIMEOUT:
5653 /* no reply, send keep alive */
5654 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
5655 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5659 /* go EOS when the server closed the connection */
5665 switch (message.type) {
5666 case GST_RTSP_MESSAGE_REQUEST:
5667 /* server sends us a request message, handle it */
5668 res = gst_rtspsrc_handle_request (src, &src->conninfo, &message);
5669 if (res == GST_RTSP_EEOF)
5672 goto handle_request_failed;
5674 case GST_RTSP_MESSAGE_RESPONSE:
5675 /* we ignore response messages */
5676 GST_DEBUG_OBJECT (src, "ignoring response message");
5677 DEBUG_RTSP (src, &message);
5679 case GST_RTSP_MESSAGE_DATA:
5680 GST_DEBUG_OBJECT (src, "got data message");
5681 ret = gst_rtspsrc_handle_data (src, &message);
5682 if (ret != GST_FLOW_OK)
5683 goto handle_data_failed;
5686 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
5691 g_assert_not_reached ();
5696 GST_DEBUG_OBJECT (src, "we got an eof from the server");
5697 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5698 ("The server closed the connection."));
5699 src->conninfo.connected = FALSE;
5700 gst_rtsp_message_unset (&message);
5701 return GST_FLOW_EOS;
5705 gst_rtsp_message_unset (&message);
5706 GST_DEBUG_OBJECT (src, "got interrupted");
5707 return GST_FLOW_FLUSHING;
5711 gchar *str = gst_rtsp_strresult (res);
5713 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
5714 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_SERVER,
5715 "Could not receive message.");
5717 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5718 ("Could not receive message. (%s)", str));
5722 gst_rtsp_message_unset (&message);
5723 return GST_FLOW_ERROR;
5725 handle_request_failed:
5727 gchar *str = gst_rtsp_strresult (res);
5729 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
5730 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_SERVICE_UNAVAILABLE,
5731 "Could not handle server message.");
5733 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5734 ("Could not handle server message. (%s)", str));
5737 gst_rtsp_message_unset (&message);
5738 return GST_FLOW_ERROR;
5742 GST_DEBUG_OBJECT (src, "could no handle data message");
5747 static GstFlowReturn
5748 gst_rtspsrc_loop_udp (GstRTSPSrc * src)
5751 GstRTSPMessage message = { 0 };
5755 GTimeVal tv_timeout;
5757 /* get the next timeout interval */
5758 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
5760 GST_DEBUG_OBJECT (src, "doing receive with timeout %d seconds",
5761 (gint) tv_timeout.tv_sec);
5763 gst_rtsp_message_unset (&message);
5765 /* we should continue reading the TCP socket because the server might
5766 * send us requests. When the session timeout expires, we need to send a
5767 * keep-alive request to keep the session open. */
5768 res = gst_rtspsrc_connection_receive (src, &src->conninfo,
5769 &message, &tv_timeout);
5773 GST_DEBUG_OBJECT (src, "we received a server message");
5775 case GST_RTSP_EINTR:
5776 /* we got interrupted, see what we have to do */
5778 case GST_RTSP_ETIMEOUT:
5779 /* send keep-alive, ignore the result, a warning will be posted. */
5780 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
5781 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5785 /* server closed the connection. not very fatal for UDP, reconnect and
5786 * see what happens. */
5787 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5788 ("The server closed the connection."));
5789 if (src->udp_reconnect) {
5791 gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) < 0)
5798 GST_DEBUG_OBJECT (src, "An ethernet problem occured.");
5800 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5801 ("Unhandled return value %d.", res));
5805 switch (message.type) {
5806 case GST_RTSP_MESSAGE_REQUEST:
5807 /* server sends us a request message, handle it */
5808 res = gst_rtspsrc_handle_request (src, &src->conninfo, &message);
5809 if (res == GST_RTSP_EEOF)
5812 goto handle_request_failed;
5814 case GST_RTSP_MESSAGE_RESPONSE:
5815 /* we ignore response and data messages */
5816 GST_DEBUG_OBJECT (src, "ignoring response message");
5817 DEBUG_RTSP (src, &message);
5818 if (message.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
5819 GST_DEBUG_OBJECT (src, "but is Unauthorized response ...");
5820 if (gst_rtspsrc_setup_auth (src, &message) && !(retry++)) {
5821 GST_DEBUG_OBJECT (src, "so retrying keep-alive");
5822 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5829 case GST_RTSP_MESSAGE_DATA:
5830 /* we ignore response and data messages */
5831 GST_DEBUG_OBJECT (src, "ignoring data message");
5834 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
5839 g_assert_not_reached ();
5841 /* we get here when the connection got interrupted */
5844 gst_rtsp_message_unset (&message);
5845 GST_DEBUG_OBJECT (src, "got interrupted");
5846 return GST_FLOW_FLUSHING;
5850 gchar *str = gst_rtsp_strresult (res);
5853 src->conninfo.connected = FALSE;
5854 if (res != GST_RTSP_EINTR) {
5855 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
5856 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
5857 "Could not connect to server.");
5859 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
5860 ("Could not connect to server. (%s)", str));
5863 ret = GST_FLOW_ERROR;
5865 ret = GST_FLOW_FLUSHING;
5871 gchar *str = gst_rtsp_strresult (res);
5873 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
5874 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_SERVER_DISCONNECTED,
5875 "Could not receive message.");
5877 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5878 ("Could not receive message. (%s)", str));
5881 return GST_FLOW_ERROR;
5883 handle_request_failed:
5885 gchar *str = gst_rtsp_strresult (res);
5888 gst_rtsp_message_unset (&message);
5889 if (res != GST_RTSP_EINTR) {
5890 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
5891 gst_rtspsrc_post_error_message (src,
5892 GST_RTSPSRC_ERROR_SERVICE_UNAVAILABLE,
5893 "Could not handle server message.");
5895 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5896 ("Could not handle server message. (%s)", str));
5899 ret = GST_FLOW_ERROR;
5901 ret = GST_FLOW_FLUSHING;
5907 GST_DEBUG_OBJECT (src, "we got an eof from the server");
5908 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5909 ("The server closed the connection."));
5910 src->conninfo.connected = FALSE;
5911 gst_rtsp_message_unset (&message);
5912 return GST_FLOW_EOS;
5916 static GstRTSPResult
5917 gst_rtspsrc_reconnect (GstRTSPSrc * src, gboolean async)
5919 GstRTSPResult res = GST_RTSP_OK;
5922 GST_DEBUG_OBJECT (src, "doing reconnect");
5924 GST_OBJECT_LOCK (src);
5925 /* only restart when the pads were not yet activated, else we were
5926 * streaming over UDP */
5927 restart = src->need_activate;
5928 GST_OBJECT_UNLOCK (src);
5930 /* no need to restart, we're done */
5934 /* we can try only TCP now */
5935 src->cur_protocols = GST_RTSP_LOWER_TRANS_TCP;
5937 /* close and cleanup our state */
5938 if ((res = gst_rtspsrc_close (src, async, FALSE)) < 0)
5941 /* see if we have TCP left to try. Also don't try TCP when we were configured
5943 if (!(src->protocols & GST_RTSP_LOWER_TRANS_TCP) || src->from_sdp)
5946 /* We post a warning message now to inform the user
5947 * that nothing happened. It's most likely a firewall thing. */
5948 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5949 ("Could not receive any UDP packets for %.4f seconds, maybe your "
5950 "firewall is blocking it. Retrying using a tcp connection.",
5951 gst_guint64_to_gdouble (src->udp_timeout) / 1000000.0));
5953 /* open new connection using tcp */
5954 if (gst_rtspsrc_open (src, async) < 0)
5957 /* start playback */
5958 if (gst_rtspsrc_play (src, &src->segment, async, NULL) < 0)
5967 src->cur_protocols = 0;
5968 /* no transport possible, post an error and stop */
5969 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
5970 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_TRANSPORT,
5971 "Could not receive any UDP packets for seconds, maybe your firewall is blocking it. No other protocols to try.");
5973 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5974 ("Could not receive any UDP packets for %.4f seconds, maybe your "
5975 "firewall is blocking it. No other protocols to try.",
5976 gst_guint64_to_gdouble (src->udp_timeout) / 1000000.0));
5978 return GST_RTSP_ERROR;
5982 GST_DEBUG_OBJECT (src, "open failed");
5987 GST_DEBUG_OBJECT (src, "play failed");
5993 gst_rtspsrc_loop_start_cmd (GstRTSPSrc * src, gint cmd)
5997 GST_ELEMENT_PROGRESS (src, START, "open", ("Opening Stream"));
6000 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PLAY request"));
6003 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PAUSE request"));
6005 case CMD_GET_PARAMETER:
6006 GST_ELEMENT_PROGRESS (src, START, "request",
6007 ("Sending GET_PARAMETER request"));
6009 case CMD_SET_PARAMETER:
6010 GST_ELEMENT_PROGRESS (src, START, "request",
6011 ("Sending SET_PARAMETER request"));
6014 GST_ELEMENT_PROGRESS (src, START, "close", ("Closing Stream"));
6022 gst_rtspsrc_loop_complete_cmd (GstRTSPSrc * src, gint cmd)
6024 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6026 GST_WARNING_OBJECT (src, "Got cmd %s", cmd_to_string (cmd));
6031 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6032 GST_DEBUG_OBJECT (src,
6033 "rtsp_duration %" GST_TIME_FORMAT
6034 ", rtsp_audio_codec %s , rtsp_video_codec %s , rtsp_video_frame_size %s",
6035 GST_TIME_ARGS (src->segment.duration), src->audio_codec,
6036 src->video_codec, src->video_frame_size);
6039 s = gst_message_new_element (GST_OBJECT_CAST (src),
6040 gst_structure_new ("rtspsrc_properties",
6041 "rtsp_duration", G_TYPE_UINT64, src->segment.duration,
6042 "rtsp_audio_codec", G_TYPE_STRING, src->audio_codec,
6043 "rtsp_video_codec", G_TYPE_STRING, src->video_codec,
6044 "rtsp_video_frame_size", G_TYPE_STRING, src->video_frame_size,
6047 gst_element_post_message (GST_ELEMENT_CAST (src), s);
6049 GST_ELEMENT_PROGRESS (src, COMPLETE, "open", ("Opened Stream"));
6050 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6051 /* rtspsrc PAUSE state should be here for parsing sdp before PAUSE state changed. */
6052 g_mutex_lock (&(src)->pause_lock);
6053 g_cond_signal (&(src)->open_end);
6054 g_mutex_unlock (&(src)->pause_lock);
6058 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PLAY request"));
6061 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PAUSE request"));
6063 case CMD_GET_PARAMETER:
6064 GST_ELEMENT_PROGRESS (src, COMPLETE, "request",
6065 ("Sent GET_PARAMETER request"));
6067 case CMD_SET_PARAMETER:
6068 GST_ELEMENT_PROGRESS (src, COMPLETE, "request",
6069 ("Sent SET_PARAMETER request"));
6072 GST_ELEMENT_PROGRESS (src, COMPLETE, "close", ("Closed Stream"));
6080 gst_rtspsrc_loop_cancel_cmd (GstRTSPSrc * src, gint cmd)
6084 GST_ELEMENT_PROGRESS (src, CANCELED, "open", ("Open canceled"));
6087 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PLAY canceled"));
6090 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PAUSE canceled"));
6092 case CMD_GET_PARAMETER:
6093 GST_ELEMENT_PROGRESS (src, CANCELED, "request",
6094 ("GET_PARAMETER canceled"));
6096 case CMD_SET_PARAMETER:
6097 GST_ELEMENT_PROGRESS (src, CANCELED, "request",
6098 ("SET_PARAMETER canceled"));
6101 GST_ELEMENT_PROGRESS (src, CANCELED, "close", ("Close canceled"));
6109 gst_rtspsrc_loop_error_cmd (GstRTSPSrc * src, gint cmd)
6113 GST_ELEMENT_PROGRESS (src, ERROR, "open", ("Open failed"));
6114 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6115 /* Ending conditional wait for pause when open fails.*/
6116 g_mutex_lock (&(src)->pause_lock);
6117 g_cond_signal (&(src)->open_end);
6118 g_mutex_unlock (&(src)->pause_lock);
6119 GST_WARNING_OBJECT (src,
6120 "ending conditional wait for pause as open is failed.");
6124 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PLAY failed"));
6127 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PAUSE failed"));
6129 case CMD_GET_PARAMETER:
6130 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("GET_PARAMETER failed"));
6132 case CMD_SET_PARAMETER:
6133 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("SET_PARAMETER failed"));
6136 GST_ELEMENT_PROGRESS (src, ERROR, "close", ("Close failed"));
6144 gst_rtspsrc_loop_end_cmd (GstRTSPSrc * src, gint cmd, GstRTSPResult ret)
6146 if (ret == GST_RTSP_OK)
6147 gst_rtspsrc_loop_complete_cmd (src, cmd);
6148 else if (ret == GST_RTSP_EINTR)
6149 gst_rtspsrc_loop_cancel_cmd (src, cmd);
6151 gst_rtspsrc_loop_error_cmd (src, cmd);
6155 gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd, gint mask)
6158 gboolean flushed = FALSE;
6160 /* start new request */
6161 gst_rtspsrc_loop_start_cmd (src, cmd);
6163 GST_DEBUG_OBJECT (src, "sending cmd %s", cmd_to_string (cmd));
6165 GST_OBJECT_LOCK (src);
6166 old = src->pending_cmd;
6168 if (old == CMD_RECONNECT) {
6169 GST_DEBUG_OBJECT (src, "ignore, we were reconnecting");
6170 cmd = CMD_RECONNECT;
6171 } else if (old == CMD_CLOSE) {
6172 /* our CMD_CLOSE might have interrutped CMD_LOOP. gst_rtspsrc_loop
6173 * will send a CMD_WAIT which would cancel our pending CMD_CLOSE (if
6174 * still pending). We just avoid it here by making sure CMD_CLOSE is
6175 * still the pending command. */
6176 GST_DEBUG_OBJECT (src, "ignore, we were closing");
6178 } else if (old == CMD_SET_PARAMETER) {
6179 GST_DEBUG_OBJECT (src, "ignore, we have a pending %s", cmd_to_string (old));
6180 cmd = CMD_SET_PARAMETER;
6181 } else if (old == CMD_GET_PARAMETER) {
6182 GST_DEBUG_OBJECT (src, "ignore, we have a pending %s", cmd_to_string (old));
6183 cmd = CMD_GET_PARAMETER;
6184 } else if (old != CMD_WAIT) {
6185 src->pending_cmd = CMD_WAIT;
6186 GST_OBJECT_UNLOCK (src);
6187 /* cancel previous request */
6188 GST_DEBUG_OBJECT (src, "cancel previous request %s", cmd_to_string (old));
6189 gst_rtspsrc_loop_cancel_cmd (src, old);
6190 GST_OBJECT_LOCK (src);
6192 src->pending_cmd = cmd;
6193 /* interrupt if allowed */
6194 if (src->busy_cmd & mask) {
6195 GST_DEBUG_OBJECT (src, "connection flush busy %s",
6196 cmd_to_string (src->busy_cmd));
6197 gst_rtspsrc_connection_flush (src, TRUE);
6200 GST_DEBUG_OBJECT (src, "not interrupting busy cmd %s",
6201 cmd_to_string (src->busy_cmd));
6204 gst_task_start (src->task);
6205 GST_OBJECT_UNLOCK (src);
6211 gst_rtspsrc_loop_send_cmd_and_wait (GstRTSPSrc * src, gint cmd, gint mask,
6212 GstClockTime timeout)
6214 gboolean flushed = gst_rtspsrc_loop_send_cmd (src, cmd, mask);
6217 gint64 end_time = g_get_monotonic_time () + (timeout / 1000);
6218 GST_OBJECT_LOCK (src);
6219 while (src->pending_cmd == cmd || src->busy_cmd == cmd) {
6220 if (!g_cond_wait_until (&src->cmd_cond, GST_OBJECT_GET_LOCK (src),
6222 GST_WARNING_OBJECT (src,
6223 "Timed out waiting for TEARDOWN to be processed.");
6224 break; /* timeout passed */
6227 GST_OBJECT_UNLOCK (src);
6233 gst_rtspsrc_loop (GstRTSPSrc * src)
6237 if (!src->conninfo.connection || !src->conninfo.connected)
6240 if (src->interleaved)
6241 ret = gst_rtspsrc_loop_interleaved (src);
6243 ret = gst_rtspsrc_loop_udp (src);
6245 if (ret != GST_FLOW_OK)
6253 GST_WARNING_OBJECT (src, "we are not connected");
6254 ret = GST_FLOW_FLUSHING;
6259 const gchar *reason = gst_flow_get_name (ret);
6261 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
6262 src->running = FALSE;
6263 if (ret == GST_FLOW_EOS) {
6264 /* perform EOS logic */
6265 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
6266 gst_element_post_message (GST_ELEMENT_CAST (src),
6267 gst_message_new_segment_done (GST_OBJECT_CAST (src),
6268 src->segment.format, src->segment.position));
6269 gst_rtspsrc_push_event (src,
6270 gst_event_new_segment_done (src->segment.format,
6271 src->segment.position));
6273 gst_rtspsrc_push_event (src, gst_event_new_eos ());
6275 } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
6276 /* for fatal errors we post an error message, post the error before the
6277 * EOS so the app knows about the error first. */
6278 GST_ELEMENT_FLOW_ERROR (src, ret);
6279 gst_rtspsrc_push_event (src, gst_event_new_eos ());
6281 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_LOOP);
6286 #ifndef GST_DISABLE_GST_DEBUG
6287 static const gchar *
6288 gst_rtsp_auth_method_to_string (GstRTSPAuthMethod method)
6292 while (method != 0) {
6309 /* Parse a WWW-Authenticate Response header and determine the
6310 * available authentication methods
6312 * This code should also cope with the fact that each WWW-Authenticate
6313 * header can contain multiple challenge methods + tokens
6315 * At the moment, for Basic auth, we just do a minimal check and don't
6316 * even parse out the realm */
6318 gst_rtspsrc_parse_auth_hdr (GstRTSPMessage * response,
6319 GstRTSPAuthMethod * methods, GstRTSPConnection * conn, gboolean * stale)
6321 GstRTSPAuthCredential **credentials, **credential;
6323 g_return_if_fail (response != NULL);
6324 g_return_if_fail (methods != NULL);
6325 g_return_if_fail (stale != NULL);
6328 gst_rtsp_message_parse_auth_credentials (response,
6329 GST_RTSP_HDR_WWW_AUTHENTICATE);
6333 credential = credentials;
6334 while (*credential) {
6335 if ((*credential)->scheme == GST_RTSP_AUTH_BASIC) {
6336 *methods |= GST_RTSP_AUTH_BASIC;
6337 } else if ((*credential)->scheme == GST_RTSP_AUTH_DIGEST) {
6338 GstRTSPAuthParam **param = (*credential)->params;
6340 *methods |= GST_RTSP_AUTH_DIGEST;
6342 gst_rtsp_connection_clear_auth_params (conn);
6346 if (strcmp ((*param)->name, "stale") == 0
6347 && g_ascii_strcasecmp ((*param)->value, "TRUE") == 0)
6349 gst_rtsp_connection_set_auth_param (conn, (*param)->name,
6358 gst_rtsp_auth_credentials_free (credentials);
6362 * gst_rtspsrc_setup_auth:
6363 * @src: the rtsp source
6365 * Configure a username and password and auth method on the
6366 * connection object based on a response we received from the
6369 * Currently, this requires that a username and password were supplied
6370 * in the uri. In the future, they may be requested on demand by sending
6371 * a message up the bus.
6373 * Returns: TRUE if authentication information could be set up correctly.
6376 gst_rtspsrc_setup_auth (GstRTSPSrc * src, GstRTSPMessage * response)
6380 GstRTSPAuthMethod avail_methods = GST_RTSP_AUTH_NONE;
6381 GstRTSPAuthMethod method;
6382 GstRTSPResult auth_result;
6384 GstRTSPConnection *conn;
6385 gboolean stale = FALSE;
6387 conn = src->conninfo.connection;
6389 /* Identify the available auth methods and see if any are supported */
6390 gst_rtspsrc_parse_auth_hdr (response, &avail_methods, conn, &stale);
6392 if (avail_methods == GST_RTSP_AUTH_NONE)
6393 goto no_auth_available;
6395 /* For digest auth, if the response indicates that the session
6396 * data are stale, we just update them in the connection object and
6397 * return TRUE to retry the request */
6399 src->tried_url_auth = FALSE;
6401 url = gst_rtsp_connection_get_url (conn);
6403 /* Do we have username and password available? */
6404 if (url != NULL && !src->tried_url_auth && url->user != NULL
6405 && url->passwd != NULL) {
6408 src->tried_url_auth = TRUE;
6409 GST_DEBUG_OBJECT (src,
6410 "Attempting authentication using credentials from the URL");
6412 user = src->user_id;
6413 pass = src->user_pw;
6414 GST_DEBUG_OBJECT (src,
6415 "Attempting authentication using credentials from the properties");
6418 /* FIXME: If the url didn't contain username and password or we tried them
6419 * already, request a username and passwd from the application via some kind
6420 * of credentials request message */
6422 /* If we don't have a username and passwd at this point, bail out. */
6423 if (user == NULL || pass == NULL)
6426 /* Try to configure for each available authentication method, strongest to
6428 for (method = GST_RTSP_AUTH_MAX; method != GST_RTSP_AUTH_NONE; method >>= 1) {
6429 /* Check if this method is available on the server */
6430 if ((method & avail_methods) == 0)
6433 /* Pass the credentials to the connection to try on the next request */
6434 auth_result = gst_rtsp_connection_set_auth (conn, method, user, pass);
6435 /* INVAL indicates an invalid username/passwd were supplied, so we'll just
6436 * ignore it and end up retrying later */
6437 if (auth_result == GST_RTSP_OK || auth_result == GST_RTSP_EINVAL) {
6438 GST_DEBUG_OBJECT (src, "Attempting %s authentication",
6439 gst_rtsp_auth_method_to_string (method));
6444 if (method == GST_RTSP_AUTH_NONE)
6445 goto no_auth_available;
6451 /* Output an error indicating that we couldn't connect because there were
6452 * no supported authentication protocols */
6453 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6454 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_NOT_AUTHORIZED,
6455 "No supported authentication protocol was found");
6457 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
6458 ("No supported authentication protocol was found"));
6464 /* We don't fire an error message, we just return FALSE and let the
6465 * normal NOT_AUTHORIZED error be propagated */
6470 static GstRTSPResult
6471 gst_rtsp_src_receive_response (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
6472 GstRTSPMessage * response, GstRTSPStatusCode * code)
6474 GstRTSPStatusCode thecode;
6475 gchar *content_base = NULL;
6476 GstRTSPResult res = gst_rtspsrc_connection_receive (src, conninfo,
6477 response, src->ptcp_timeout);
6482 DEBUG_RTSP (src, response);
6484 switch (response->type) {
6485 case GST_RTSP_MESSAGE_REQUEST:
6486 res = gst_rtspsrc_handle_request (src, conninfo, response);
6487 if (res == GST_RTSP_EEOF)
6490 goto handle_request_failed;
6492 /* Not a response, receive next message */
6493 return gst_rtsp_src_receive_response (src, conninfo, response, code);
6494 case GST_RTSP_MESSAGE_RESPONSE:
6495 /* ok, a response is good */
6496 GST_DEBUG_OBJECT (src, "received response message");
6498 case GST_RTSP_MESSAGE_DATA:
6499 /* get next response */
6500 GST_DEBUG_OBJECT (src, "handle data response message");
6501 gst_rtspsrc_handle_data (src, response);
6503 /* Not a response, receive next message */
6504 return gst_rtsp_src_receive_response (src, conninfo, response, code);
6506 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
6509 /* Not a response, receive next message */
6510 return gst_rtsp_src_receive_response (src, conninfo, response, code);
6513 thecode = response->type_data.response.code;
6515 GST_DEBUG_OBJECT (src, "got response message %d", thecode);
6517 /* if the caller wanted the result code, we store it. */
6521 /* If the request didn't succeed, bail out before doing any more */
6522 if (thecode != GST_RTSP_STS_OK)
6525 /* store new content base if any */
6526 gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_BASE,
6529 g_free (src->content_base);
6530 src->content_base = g_strdup (content_base);
6540 return GST_RTSP_EEOF;
6543 gchar *str = gst_rtsp_strresult (res);
6545 if (res != GST_RTSP_EINTR) {
6546 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6547 gst_rtspsrc_post_error_message (src,
6548 GST_RTSPSRC_ERROR_SERVER_DISCONNECTED,
6549 "Could not receive message.");
6551 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
6552 ("Could not receive message. (%s)", str));
6555 GST_WARNING_OBJECT (src, "receive interrupted");
6563 handle_request_failed:
6565 /* ERROR was posted */
6566 gst_rtsp_message_unset (response);
6571 GST_DEBUG_OBJECT (src, "we got an eof from the server");
6572 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
6573 ("The server closed the connection."));
6574 gst_rtsp_message_unset (response);
6580 static GstRTSPResult
6581 gst_rtspsrc_try_send (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
6582 GstRTSPMessage * request, GstRTSPMessage * response,
6583 GstRTSPStatusCode * code)
6587 gboolean allow_send = TRUE;
6590 if (!src->short_header)
6591 gst_rtsp_ext_list_before_send (src->extensions, request);
6593 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_BEFORE_SEND], 0,
6594 request, &allow_send);
6596 GST_DEBUG_OBJECT (src, "skipping message, disabled by signal");
6600 GST_DEBUG_OBJECT (src, "sending message");
6602 DEBUG_RTSP (src, request);
6604 res = gst_rtspsrc_connection_send (src, conninfo, request, src->ptcp_timeout);
6608 gst_rtsp_connection_reset_timeout (conninfo->connection);
6612 res = gst_rtsp_src_receive_response (src, conninfo, response, code);
6613 if (res == GST_RTSP_EEOF) {
6614 GST_WARNING_OBJECT (src, "server closed connection");
6615 /* only try once after reconnect, then fallthrough and error out */
6616 if ((try == 0) && !src->interleaved && src->udp_reconnect) {
6618 /* if reconnect succeeds, try again */
6619 if ((res = gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) == 0)
6623 gst_rtsp_ext_list_after_send (src->extensions, request, response);
6629 gchar *str = gst_rtsp_strresult (res);
6631 if (res != GST_RTSP_EINTR) {
6632 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6633 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
6634 "Could not send message.");
6636 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6637 ("Could not send message. (%s)", str));
6640 GST_WARNING_OBJECT (src, "send interrupted");
6649 * @src: the rtsp source
6650 * @conninfo: the connection information to send on
6651 * @request: must point to a valid request
6652 * @response: must point to an empty #GstRTSPMessage
6653 * @code: an optional code result
6654 * @versions: List of versions to try, setting it back onto the @request message
6655 * if not set, `src->version` will be used as RTSP version.
6657 * send @request and retrieve the response in @response. optionally @code can be
6658 * non-NULL in which case it will contain the status code of the response.
6660 * If This function returns #GST_RTSP_OK, @response will contain a valid response
6661 * message that should be cleaned with gst_rtsp_message_unset() after usage.
6663 * If @code is NULL, this function will return #GST_RTSP_ERROR (with an invalid
6664 * @response message) if the response code was not 200 (OK).
6666 * If the attempt results in an authentication failure, then this will attempt
6667 * to retrieve authentication credentials via gst_rtspsrc_setup_auth and retry
6670 * Returns: #GST_RTSP_OK if the processing was successful.
6672 static GstRTSPResult
6673 gst_rtspsrc_send (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
6674 GstRTSPMessage * request, GstRTSPMessage * response,
6675 GstRTSPStatusCode * code, GstRTSPVersion * versions)
6677 GstRTSPStatusCode int_code = GST_RTSP_STS_OK;
6678 GstRTSPResult res = GST_RTSP_ERROR;
6681 GstRTSPMethod method = GST_RTSP_INVALID;
6682 gint version_retry = 0;
6688 /* make sure we don't loop forever */
6692 /* save method so we can disable it when the server complains */
6693 method = request->type_data.request.method;
6696 request->type_data.request.version = src->version;
6699 gst_rtspsrc_try_send (src, conninfo, request, response,
6704 case GST_RTSP_STS_UNAUTHORIZED:
6705 case GST_RTSP_STS_NOT_FOUND:
6706 if (gst_rtspsrc_setup_auth (src, response)) {
6707 /* Try the request/response again after configuring the auth info
6712 case GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED:
6713 GST_INFO_OBJECT (src, "Version %s not supported by the server",
6714 versions ? gst_rtsp_version_as_text (versions[version_retry]) :
6716 if (versions && versions[version_retry] != GST_RTSP_VERSION_INVALID) {
6717 GST_INFO_OBJECT (src, "Unsupported version %s => trying %s",
6718 gst_rtsp_version_as_text (request->type_data.request.version),
6719 gst_rtsp_version_as_text (versions[version_retry]));
6720 request->type_data.request.version = versions[version_retry];
6729 } while (retry == TRUE);
6731 /* If the user requested the code, let them handle errors, otherwise
6732 * post an error below */
6735 else if (int_code != GST_RTSP_STS_OK)
6736 goto error_response;
6743 GST_DEBUG_OBJECT (src, "got error %d", res);
6748 res = GST_RTSP_ERROR;
6750 switch (response->type_data.response.code) {
6751 case GST_RTSP_STS_NOT_FOUND:
6752 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6753 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
6756 RTSP_SRC_RESPONSE_ERROR (src, response, RESOURCE, NOT_FOUND,
6760 case GST_RTSP_STS_UNAUTHORIZED:
6761 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6762 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_NOT_AUTHORIZED,
6763 "STS NOT AUTHORIZED");
6765 RTSP_SRC_RESPONSE_ERROR (src, response, RESOURCE, NOT_AUTHORIZED,
6769 case GST_RTSP_STS_MOVED_PERMANENTLY:
6770 case GST_RTSP_STS_MOVE_TEMPORARILY:
6772 gchar *new_location;
6773 GstRTSPLowerTrans transports;
6775 GST_DEBUG_OBJECT (src, "got redirection");
6776 /* if we don't have a Location Header, we must error */
6777 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_LOCATION,
6778 &new_location, 0) < 0)
6781 /* When we receive a redirect result, we go back to the INIT state after
6782 * parsing the new URI. The caller should do the needed steps to issue
6783 * a new setup when it detects this state change. */
6784 GST_DEBUG_OBJECT (src, "redirection to %s", new_location);
6786 /* save current transports */
6787 if (src->conninfo.url)
6788 transports = src->conninfo.url->transports;
6790 transports = GST_RTSP_LOWER_TRANS_UNKNOWN;
6792 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (src), new_location, NULL);
6794 /* set old transports */
6795 if (src->conninfo.url && transports != GST_RTSP_LOWER_TRANS_UNKNOWN)
6796 src->conninfo.url->transports = transports;
6798 src->need_redirect = TRUE;
6802 case GST_RTSP_STS_NOT_ACCEPTABLE:
6803 case GST_RTSP_STS_NOT_IMPLEMENTED:
6804 case GST_RTSP_STS_METHOD_NOT_ALLOWED:
6805 GST_WARNING_OBJECT (src, "got NOT IMPLEMENTED, disable method %s",
6806 gst_rtsp_method_as_text (method));
6807 src->methods &= ~method;
6811 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6812 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_UNEXPECTED_MSG,
6813 "Got error response from Server");
6815 RTSP_SRC_RESPONSE_ERROR (src, response, RESOURCE, READ,
6820 /* if we return ERROR we should unset the response ourselves */
6821 if (res == GST_RTSP_ERROR)
6822 gst_rtsp_message_unset (response);
6828 static GstRTSPResult
6829 gst_rtspsrc_send_cb (GstRTSPExtension * ext, GstRTSPMessage * request,
6830 GstRTSPMessage * response, GstRTSPSrc * src)
6832 return gst_rtspsrc_send (src, &src->conninfo, request, response, NULL, NULL);
6836 /* parse the response and collect all the supported methods. We need this
6837 * information so that we don't try to send an unsupported request to the
6841 gst_rtspsrc_parse_methods (GstRTSPSrc * src, GstRTSPMessage * response)
6843 GstRTSPHeaderField field;
6847 /* reset supported methods */
6850 /* Try Allow Header first */
6851 field = GST_RTSP_HDR_ALLOW;
6854 gst_rtsp_message_get_header (response, field, &respoptions, indx);
6858 src->methods |= gst_rtsp_options_from_text (respoptions);
6864 field = GST_RTSP_HDR_PUBLIC;
6867 gst_rtsp_message_get_header (response, field, &respoptions, indx);
6871 src->methods |= gst_rtsp_options_from_text (respoptions);
6876 if (src->methods == 0) {
6877 /* neither Allow nor Public are required, assume the server supports
6878 * at least DESCRIBE, SETUP, we always assume it supports PLAY as
6880 GST_DEBUG_OBJECT (src, "could not get OPTIONS");
6881 src->methods = GST_RTSP_DESCRIBE | GST_RTSP_SETUP;
6883 /* always assume PLAY, FIXME, extensions should be able to override
6885 src->methods |= GST_RTSP_PLAY;
6886 /* also assume it will support Range */
6887 src->seekable = G_MAXFLOAT;
6889 /* we need describe and setup */
6890 if (!(src->methods & GST_RTSP_DESCRIBE))
6892 if (!(src->methods & GST_RTSP_SETUP))
6900 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6901 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_METHOD_NOT_ALLOWED,
6902 "Server does not support DESCRIBE.");
6904 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
6905 ("Server does not support DESCRIBE."));
6911 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
6912 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_METHOD_NOT_ALLOWED,
6913 "Server does not support SETUP.");
6915 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
6916 ("Server does not support SETUP."));
6922 /* masks to be kept in sync with the hardcoded protocol order of preference
6924 static const guint protocol_masks[] = {
6925 GST_RTSP_LOWER_TRANS_UDP,
6926 GST_RTSP_LOWER_TRANS_UDP_MCAST,
6927 GST_RTSP_LOWER_TRANS_TCP,
6931 static GstRTSPResult
6932 gst_rtspsrc_create_transports_string (GstRTSPSrc * src,
6933 GstRTSPLowerTrans protocols, GstRTSPProfile profile, gchar ** transports)
6937 gboolean add_udp_str;
6942 gst_rtsp_ext_list_get_transports (src->extensions, protocols, transports);
6947 GST_DEBUG_OBJECT (src, "got transports %s", GST_STR_NULL (*transports));
6949 /* extension listed transports, use those */
6950 if (*transports != NULL)
6953 /* it's the default */
6954 add_udp_str = FALSE;
6956 /* the default RTSP transports */
6957 result = g_string_new ("RTP");
6960 case GST_RTSP_PROFILE_AVP:
6961 g_string_append (result, "/AVP");
6963 case GST_RTSP_PROFILE_SAVP:
6964 g_string_append (result, "/SAVP");
6966 case GST_RTSP_PROFILE_AVPF:
6967 g_string_append (result, "/AVPF");
6969 case GST_RTSP_PROFILE_SAVPF:
6970 g_string_append (result, "/SAVPF");
6976 if (protocols & GST_RTSP_LOWER_TRANS_UDP) {
6977 GST_DEBUG_OBJECT (src, "adding UDP unicast");
6979 g_string_append (result, "/UDP");
6980 g_string_append (result, ";unicast;client_port=%%u1-%%u2");
6981 } else if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST) {
6982 GST_DEBUG_OBJECT (src, "adding UDP multicast");
6983 /* we don't have to allocate any UDP ports yet, if the selected transport
6984 * turns out to be multicast we can create them and join the multicast
6985 * group indicated in the transport reply */
6987 g_string_append (result, "/UDP");
6988 g_string_append (result, ";multicast");
6989 if (src->next_port_num != 0) {
6990 if (src->client_port_range.max > 0 &&
6991 src->next_port_num >= src->client_port_range.max)
6994 g_string_append_printf (result, ";client_port=%d-%d",
6995 src->next_port_num, src->next_port_num + 1);
6997 } else if (protocols & GST_RTSP_LOWER_TRANS_TCP) {
6998 GST_DEBUG_OBJECT (src, "adding TCP");
7000 g_string_append (result, "/TCP;unicast;interleaved=%%i1-%%i2");
7002 *transports = g_string_free (result, FALSE);
7004 GST_DEBUG_OBJECT (src, "prepared transports %s", GST_STR_NULL (*transports));
7011 GST_ERROR ("extension gave error %d", res);
7016 GST_ERROR ("no more ports available");
7017 return GST_RTSP_ERROR;
7021 static GstRTSPResult
7022 gst_rtspsrc_prepare_transports (GstRTSPStream * stream, gchar ** transports,
7023 gint orig_rtpport, gint orig_rtcpport)
7026 gint nr_udp, nr_int;
7028 gint rtpport = 0, rtcpport = 0;
7031 src = stream->parent;
7033 /* find number of placeholders first */
7034 if (strstr (*transports, "%%i2"))
7036 else if (strstr (*transports, "%%i1"))
7041 if (strstr (*transports, "%%u2"))
7043 else if (strstr (*transports, "%%u1"))
7048 if (nr_udp == 0 && nr_int == 0)
7052 if (!orig_rtpport || !orig_rtcpport) {
7053 if (!gst_rtspsrc_alloc_udp_ports (stream, &rtpport, &rtcpport))
7056 rtpport = orig_rtpport;
7057 rtcpport = orig_rtcpport;
7061 str = g_string_new ("");
7063 while ((next = strstr (p, "%%"))) {
7064 g_string_append_len (str, p, next - p);
7065 if (next[2] == 'u') {
7067 g_string_append_printf (str, "%d", rtpport);
7068 else if (next[3] == '2')
7069 g_string_append_printf (str, "%d", rtcpport);
7071 if (next[2] == 'i') {
7073 g_string_append_printf (str, "%d", src->free_channel);
7074 else if (next[3] == '2')
7075 g_string_append_printf (str, "%d", src->free_channel + 1);
7081 if (src->version >= GST_RTSP_VERSION_2_0)
7082 src->free_channel += 2;
7084 /* append final part */
7085 g_string_append (str, p);
7087 g_free (*transports);
7088 *transports = g_string_free (str, FALSE);
7096 GST_ERROR ("failed to allocate udp ports");
7097 return GST_RTSP_ERROR;
7102 signal_get_srtcp_params (GstRTSPSrc * src, GstRTSPStream * stream)
7104 GstCaps *caps = NULL;
7106 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_REQUEST_RTCP_KEY], 0,
7110 GST_DEBUG_OBJECT (src, "SRTP parameters received");
7116 default_srtcp_params (void)
7123 guint data_size = GST_ROUND_UP_4 (KEY_SIZE);
7125 /* create a random key */
7126 key_data = g_malloc (data_size);
7127 for (i = 0; i < data_size; i += 4)
7128 GST_WRITE_UINT32_BE (key_data + i, g_random_int ());
7130 buf = gst_buffer_new_wrapped (key_data, KEY_SIZE);
7132 caps = gst_caps_new_simple ("application/x-srtcp",
7133 "srtp-key", GST_TYPE_BUFFER, buf,
7134 "srtp-cipher", G_TYPE_STRING, "aes-128-icm",
7135 "srtp-auth", G_TYPE_STRING, "hmac-sha1-80",
7136 "srtcp-cipher", G_TYPE_STRING, "aes-128-icm",
7137 "srtcp-auth", G_TYPE_STRING, "hmac-sha1-80", NULL);
7139 gst_buffer_unref (buf);
7145 gst_rtspsrc_stream_make_keymgmt (GstRTSPSrc * src, GstRTSPStream * stream)
7147 gchar *base64, *result = NULL;
7148 GstMIKEYMessage *mikey_msg;
7150 stream->srtcpparams = signal_get_srtcp_params (src, stream);
7151 if (stream->srtcpparams == NULL)
7152 stream->srtcpparams = default_srtcp_params ();
7154 mikey_msg = gst_mikey_message_new_from_caps (stream->srtcpparams);
7156 /* add policy '0' for our SSRC */
7157 gst_mikey_message_add_cs_srtp (mikey_msg, 0, stream->send_ssrc, 0);
7159 base64 = gst_mikey_message_base64_encode (mikey_msg);
7160 gst_mikey_message_unref (mikey_msg);
7163 result = gst_sdp_make_keymgmt (stream->conninfo.location, base64);
7171 static GstRTSPResult
7172 gst_rtsp_src_setup_stream_from_response (GstRTSPSrc * src,
7173 GstRTSPStream * stream, GstRTSPMessage * response,
7174 GstRTSPLowerTrans * protocols, gint retry, gint * rtpport, gint * rtcpport)
7176 gchar *resptrans = NULL;
7177 GstRTSPTransport transport = { 0 };
7179 gst_rtsp_message_get_header (response, GST_RTSP_HDR_TRANSPORT, &resptrans, 0);
7181 gst_rtspsrc_stream_free_udp (stream);
7185 /* parse transport, go to next stream on parse error */
7186 if (gst_rtsp_transport_parse (resptrans, &transport) != GST_RTSP_OK) {
7187 GST_WARNING_OBJECT (src, "failed to parse transport %s", resptrans);
7188 return GST_RTSP_ELAST;
7191 /* update allowed transports for other streams. once the transport of
7192 * one stream has been determined, we make sure that all other streams
7193 * are configured in the same way */
7194 switch (transport.lower_transport) {
7195 case GST_RTSP_LOWER_TRANS_TCP:
7196 GST_DEBUG_OBJECT (src, "stream %p as TCP interleaved", stream);
7198 *protocols = GST_RTSP_LOWER_TRANS_TCP;
7199 src->interleaved = TRUE;
7200 if (src->version < GST_RTSP_VERSION_2_0) {
7201 /* update free channels */
7202 src->free_channel = MAX (transport.interleaved.min, src->free_channel);
7203 src->free_channel = MAX (transport.interleaved.max, src->free_channel);
7204 src->free_channel++;
7207 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
7208 /* only allow multicast for other streams */
7209 GST_DEBUG_OBJECT (src, "stream %p as UDP multicast", stream);
7211 *protocols = GST_RTSP_LOWER_TRANS_UDP_MCAST;
7212 /* if the server selected our ports, increment our counters so that
7213 * we select a new port later */
7214 if (src->next_port_num == transport.port.min &&
7215 src->next_port_num + 1 == transport.port.max) {
7216 src->next_port_num += 2;
7219 case GST_RTSP_LOWER_TRANS_UDP:
7220 /* only allow unicast for other streams */
7221 GST_DEBUG_OBJECT (src, "stream %p as UDP unicast", stream);
7223 *protocols = GST_RTSP_LOWER_TRANS_UDP;
7226 GST_DEBUG_OBJECT (src, "stream %p unknown transport %d", stream,
7227 transport.lower_transport);
7231 if (!src->interleaved || !retry) {
7232 /* now configure the stream with the selected transport */
7233 if (!gst_rtspsrc_stream_configure_transport (stream, &transport)) {
7234 GST_DEBUG_OBJECT (src,
7235 "could not configure stream %p transport, skipping stream", stream);
7237 } else if (stream->udpsrc[0] && stream->udpsrc[1] && rtpport && rtcpport) {
7238 /* retain the first allocated UDP port pair */
7239 g_object_get (G_OBJECT (stream->udpsrc[0]), "port", rtpport, NULL);
7240 g_object_get (G_OBJECT (stream->udpsrc[1]), "port", rtcpport, NULL);
7243 /* we need to activate at least one stream when we detect activity */
7244 src->need_activate = TRUE;
7246 /* stream is setup now */
7247 stream->setup = TRUE;
7248 stream->waiting_setup_response = FALSE;
7250 if (src->version >= GST_RTSP_VERSION_2_0) {
7251 gchar *prop, *media_properties;
7255 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_MEDIA_PROPERTIES,
7256 &media_properties, 0) != GST_RTSP_OK) {
7257 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7258 ("Error: No MEDIA_PROPERTY header in a SETUP request in RTSP 2.0"
7259 " - this header is mandatory."));
7261 gst_rtsp_message_unset (response);
7262 return GST_RTSP_ERROR;
7265 props = g_strsplit (media_properties, ",", -2);
7266 for (i = 0; props[i]; i++) {
7269 while (*prop == ' ')
7272 if (strstr (prop, "Random-Access")) {
7273 gchar **random_seekable_val = g_strsplit (prop, "=", 2);
7275 if (!random_seekable_val[1])
7276 src->seekable = G_MAXFLOAT;
7278 src->seekable = g_ascii_strtod (random_seekable_val[1], NULL);
7280 g_strfreev (random_seekable_val);
7281 } else if (!g_strcmp0 (prop, "No-Seeking")) {
7282 src->seekable = -1.0;
7283 } else if (!g_strcmp0 (prop, "Beginning-Only")) {
7284 src->seekable = 0.0;
7292 /* clean up our transport struct */
7293 gst_rtsp_transport_init (&transport);
7294 /* clean up used RTSP messages */
7295 gst_rtsp_message_unset (response);
7301 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
7302 ("Server did not select transport."));
7304 gst_rtsp_message_unset (response);
7305 return GST_RTSP_ERROR;
7309 static GstRTSPResult
7310 gst_rtspsrc_setup_streams_end (GstRTSPSrc * src, gboolean async)
7313 GstRTSPConnInfo *conninfo;
7315 g_assert (src->version >= GST_RTSP_VERSION_2_0);
7317 conninfo = &src->conninfo;
7318 for (tmp = src->streams; tmp; tmp = tmp->next) {
7319 GstRTSPStream *stream = (GstRTSPStream *) tmp->data;
7320 GstRTSPMessage response = { 0, };
7322 if (!stream->waiting_setup_response)
7325 if (!src->conninfo.connection)
7326 conninfo = &((GstRTSPStream *) tmp->data)->conninfo;
7328 gst_rtsp_src_receive_response (src, conninfo, &response, NULL);
7330 gst_rtsp_src_setup_stream_from_response (src, stream,
7331 &response, NULL, 0, NULL, NULL);
7337 /* Perform the SETUP request for all the streams.
7339 * We ask the server for a specific transport, which initially includes all the
7340 * ones we can support (UDP/TCP/MULTICAST). For the UDP transport we allocate
7341 * two local UDP ports that we send to the server.
7343 * Once the server replied with a transport, we configure the other streams
7344 * with the same transport.
7346 * In case setup request are not pipelined, this function will also configure the
7347 * stream for the selected transport, * which basically means creating the pipeline.
7348 * Otherwise, the first stream is setup right away from the reply and a
7349 * CMD_FINALIZE_SETUP command is set for the stream pipelines to happen on the
7350 * remaining streams from the RTSP thread.
7352 static GstRTSPResult
7353 gst_rtspsrc_setup_streams_start (GstRTSPSrc * src, gboolean async)
7356 GstRTSPResult res = GST_RTSP_ERROR;
7357 GstRTSPMessage request = { 0 };
7358 GstRTSPMessage response = { 0 };
7359 GstRTSPStream *stream = NULL;
7360 GstRTSPLowerTrans protocols;
7361 GstRTSPStatusCode code;
7362 gboolean unsupported_real = FALSE;
7363 gint rtpport, rtcpport;
7366 gchar *pipelined_request_id = NULL;
7368 if (src->conninfo.connection) {
7369 url = gst_rtsp_connection_get_url (src->conninfo.connection);
7370 /* we initially allow all configured lower transports. based on the URL
7371 * transports and the replies from the server we narrow them down. */
7372 protocols = url->transports & src->cur_protocols;
7375 protocols = src->cur_protocols;
7381 /* reset some state */
7382 src->free_channel = 0;
7383 src->interleaved = FALSE;
7384 src->need_activate = FALSE;
7385 /* keep track of next port number, 0 is random */
7386 src->next_port_num = src->client_port_range.min;
7387 rtpport = rtcpport = 0;
7389 if (G_UNLIKELY (src->streams == NULL))
7392 for (walk = src->streams; walk; walk = g_list_next (walk)) {
7393 GstRTSPConnInfo *conninfo;
7400 stream = (GstRTSPStream *) walk->data;
7402 caps = stream_get_caps_for_pt (stream, stream->default_pt);
7404 GST_WARNING_OBJECT (src, "skipping stream %p, no caps", stream);
7408 if (stream->skipped) {
7409 GST_DEBUG_OBJECT (src, "skipping stream %p", stream);
7413 /* see if we need to configure this stream */
7414 if (!gst_rtsp_ext_list_configure_stream (src->extensions, caps)) {
7415 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by extension",
7420 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_SELECT_STREAM], 0,
7421 stream->id, caps, &selected);
7423 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by signal", stream);
7427 /* merge/overwrite global caps */
7432 s = gst_caps_get_structure (caps, 0);
7434 num = gst_structure_n_fields (src->props);
7435 for (j = 0; j < num; j++) {
7439 name = gst_structure_nth_field_name (src->props, j);
7440 val = gst_structure_get_value (src->props, name);
7441 gst_structure_set_value (s, name, val);
7443 GST_DEBUG_OBJECT (src, "copied %s", name);
7447 /* skip setup if we have no URL for it */
7448 if (stream->conninfo.location == NULL) {
7449 GST_WARNING_OBJECT (src, "skipping stream %p, no setup", stream);
7453 if (src->conninfo.connection == NULL) {
7454 if (!gst_rtsp_conninfo_connect (src, &stream->conninfo, async)) {
7455 GST_WARNING_OBJECT (src, "skipping stream %p, failed to connect",
7459 conninfo = &stream->conninfo;
7461 conninfo = &src->conninfo;
7463 GST_DEBUG_OBJECT (src, "doing setup of stream %p with %s", stream,
7464 stream->conninfo.location);
7466 /* if we have a multicast connection, only suggest multicast from now on */
7467 if (stream->is_multicast)
7468 protocols &= GST_RTSP_LOWER_TRANS_UDP_MCAST;
7471 /* first selectable protocol */
7472 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
7474 if (!protocol_masks[mask])
7478 GST_DEBUG_OBJECT (src, "protocols = 0x%x, protocol mask = 0x%x", protocols,
7479 protocol_masks[mask]);
7480 /* create a string with first transport in line */
7482 res = gst_rtspsrc_create_transports_string (src,
7483 protocols & protocol_masks[mask], stream->profile, &transports);
7484 if (res < 0 || transports == NULL)
7485 goto setup_transport_failed;
7487 if (strlen (transports) == 0) {
7488 g_free (transports);
7489 GST_DEBUG_OBJECT (src, "no transports found");
7494 GST_DEBUG_OBJECT (src, "replace ports in %s", GST_STR_NULL (transports));
7496 /* replace placeholders with real values, this function will optionally
7497 * allocate UDP ports and other info needed to execute the setup request */
7498 res = gst_rtspsrc_prepare_transports (stream, &transports,
7499 retry > 0 ? rtpport : 0, retry > 0 ? rtcpport : 0);
7501 g_free (transports);
7502 goto setup_transport_failed;
7505 GST_DEBUG_OBJECT (src, "transport is now %s", GST_STR_NULL (transports));
7506 /* create SETUP request */
7508 gst_rtspsrc_init_request (src, &request, GST_RTSP_SETUP,
7509 stream->conninfo.location);
7511 g_free (transports);
7512 goto create_request_failed;
7515 if (src->version >= GST_RTSP_VERSION_2_0) {
7516 if (!pipelined_request_id)
7517 pipelined_request_id = g_strdup_printf ("%d",
7518 g_random_int_range (0, G_MAXINT32));
7520 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_PIPELINED_REQUESTS,
7521 pipelined_request_id);
7522 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_ACCEPT_RANGES,
7523 "npt, clock, smpte, clock");
7526 /* select transport */
7527 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_TRANSPORT, transports);
7529 if (stream->is_backchannel && src->backchannel == BACKCHANNEL_ONVIF)
7530 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
7531 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
7534 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
7535 stream->profile == GST_RTSP_PROFILE_SAVPF) {
7536 hval = gst_rtspsrc_stream_make_keymgmt (src, stream);
7537 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_KEYMGMT, hval);
7540 /* if the user wants a non default RTP packet size we add the blocksize
7542 if (src->rtp_blocksize > 0) {
7543 hval = g_strdup_printf ("%d", src->rtp_blocksize);
7544 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_BLOCKSIZE, hval);
7548 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("SETUP stream %d",
7551 /* handle the code ourselves */
7553 gst_rtspsrc_send (src, conninfo, &request,
7554 pipelined_request_id ? NULL : &response, &code, NULL);
7559 case GST_RTSP_STS_OK:
7561 case GST_RTSP_STS_UNSUPPORTED_TRANSPORT:
7562 gst_rtsp_message_unset (&request);
7563 gst_rtsp_message_unset (&response);
7564 /* cleanup of leftover transport */
7565 gst_rtspsrc_stream_free_udp (stream);
7566 /* MS WMServer RTSP MUST use same UDP pair in all SETUP requests;
7567 * we might be in this case */
7568 if (stream->container && rtpport && rtcpport && !retry) {
7569 GST_DEBUG_OBJECT (src, "retrying with original port pair %u-%u",
7574 /* this transport did not go down well, but we may have others to try
7575 * that we did not send yet, try those and only give up then
7576 * but not without checking for lost cause/extension so we can
7577 * post a nicer/more useful error message later */
7578 if (!unsupported_real)
7579 unsupported_real = stream->is_real;
7580 /* select next available protocol, give up on this stream if none */
7582 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
7584 if (!protocol_masks[mask] || unsupported_real)
7589 /* cleanup of leftover transport and move to the next stream */
7590 gst_rtspsrc_stream_free_udp (stream);
7591 goto response_error;
7595 if (!pipelined_request_id) {
7596 /* parse response transport */
7597 res = gst_rtsp_src_setup_stream_from_response (src, stream,
7598 &response, &protocols, retry, &rtpport, &rtcpport);
7600 case GST_RTSP_ERROR:
7602 case GST_RTSP_ELAST:
7608 stream->waiting_setup_response = TRUE;
7609 /* we need to activate at least one stream when we detect activity */
7610 src->need_activate = TRUE;
7617 GstRTSPStream *sskip;
7619 skip = g_list_next (skip);
7623 sskip = (GstRTSPStream *) skip->data;
7625 /* skip all streams with the same control url */
7626 if (g_str_equal (stream->conninfo.location, sskip->conninfo.location)) {
7627 GST_DEBUG_OBJECT (src, "found stream %p with same control %s",
7628 sskip, sskip->conninfo.location);
7629 sskip->skipped = TRUE;
7633 gst_rtsp_message_unset (&request);
7636 if (pipelined_request_id) {
7637 gst_rtspsrc_setup_streams_end (src, TRUE);
7640 /* store the transport protocol that was configured */
7641 src->cur_protocols = protocols;
7643 gst_rtsp_ext_list_stream_select (src->extensions, url);
7645 if (pipelined_request_id)
7646 g_free (pipelined_request_id);
7648 /* if there is nothing to activate, error out */
7649 if (!src->need_activate)
7650 goto nothing_to_activate;
7657 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7658 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_INVALID_PROTOCOL,
7659 "Could not connect to server, no protocols left");
7661 /* no transport possible, post an error and stop */
7662 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
7663 ("Could not connect to server, no protocols left"));
7665 return GST_RTSP_ERROR;
7669 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7670 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONTENT_NOT_FOUND,
7671 "SDP contains no streams");
7673 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
7674 ("SDP contains no streams"));
7676 return GST_RTSP_ERROR;
7678 create_request_failed:
7680 gchar *str = gst_rtsp_strresult (res);
7682 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7683 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
7684 "Could not create request.");
7686 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
7687 ("Could not create request. (%s)", str));
7692 setup_transport_failed:
7694 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7695 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
7696 "Could not setup transport.");
7698 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
7699 ("Could not setup transport."));
7701 res = GST_RTSP_ERROR;
7706 #ifndef TIZEN_FEATURE_RTSP_MODIFICATION
7707 const gchar *str = gst_rtsp_status_as_text (code);
7710 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7711 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_UNEXPECTED_MSG,
7712 "Error from Server .");
7714 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7715 ("Error (%d): %s", code, GST_STR_NULL (str)));
7717 res = GST_RTSP_ERROR;
7722 gchar *str = gst_rtsp_strresult (res);
7724 if (res != GST_RTSP_EINTR) {
7725 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7726 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
7727 "Could not send message.");
7729 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7730 ("Could not send message. (%s)", str));
7733 GST_WARNING_OBJECT (src, "send interrupted");
7738 nothing_to_activate:
7740 /* none of the available error codes is really right .. */
7741 if (unsupported_real) {
7742 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7743 gst_rtspsrc_post_error_message (src,
7744 GST_RTSPSRC_ERROR_UNSUPPORTED_MEDIA_TYPE,
7745 "No supported stream was found. You might need to install a GStreamer RTSP extension plugin for Real media streams.");
7747 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
7748 (_("No supported stream was found. You might need to install a "
7749 "GStreamer RTSP extension plugin for Real media streams.")),
7753 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7754 gst_rtspsrc_post_error_message (src,
7755 GST_RTSPSRC_ERROR_UNSUPPORTED_MEDIA_TYPE,
7756 "No supported stream was found. You might need to allow more transport protocols or may otherwise be missing the right GStreamer RTSP extension plugin.");
7758 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
7759 (_("No supported stream was found. You might need to allow "
7760 "more transport protocols or may otherwise be missing "
7761 "the right GStreamer RTSP extension plugin.")), (NULL));
7764 return GST_RTSP_ERROR;
7768 if (pipelined_request_id)
7769 g_free (pipelined_request_id);
7770 gst_rtsp_message_unset (&request);
7771 gst_rtsp_message_unset (&response);
7777 gst_rtspsrc_parse_range (GstRTSPSrc * src, const gchar * range,
7778 GstSegment * segment)
7781 GstRTSPTimeRange *therange;
7784 gst_rtsp_range_free (src->range);
7786 if (gst_rtsp_range_parse (range, &therange) == GST_RTSP_OK) {
7787 GST_DEBUG_OBJECT (src, "parsed range %s", range);
7788 src->range = therange;
7790 GST_DEBUG_OBJECT (src, "failed to parse range %s", range);
7792 gst_segment_init (segment, GST_FORMAT_TIME);
7796 GST_DEBUG_OBJECT (src, "range: type %d, min %f - type %d, max %f ",
7797 therange->min.type, therange->min.seconds, therange->max.type,
7798 therange->max.seconds);
7800 if (therange->min.type == GST_RTSP_TIME_NOW)
7802 else if (therange->min.type == GST_RTSP_TIME_END)
7805 seconds = therange->min.seconds * GST_SECOND;
7807 GST_DEBUG_OBJECT (src, "range: min %" GST_TIME_FORMAT,
7808 GST_TIME_ARGS (seconds));
7810 /* we need to start playback without clipping from the position reported by
7812 segment->start = seconds;
7813 #ifndef TIZEN_FEATURE_RTSP_MODIFICATION
7815 The range-min points to the start of the segment , not the current position.
7816 After getting the current position from MSL during normal pause/resume or during seek , we should not
7817 update the segment->position again with the rtp header npt timestamp.
7819 segment->position = seconds;
7822 if (therange->max.type == GST_RTSP_TIME_NOW)
7823 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
7828 else if (therange->max.type == GST_RTSP_TIME_END)
7831 seconds = therange->max.seconds * GST_SECOND;
7833 GST_DEBUG_OBJECT (src, "range: max %" GST_TIME_FORMAT,
7834 GST_TIME_ARGS (seconds));
7836 /* live (WMS) server might send overflowed large max as its idea of infinity,
7837 * compensate to prevent problems later on */
7838 if (seconds != -1 && seconds < 0) {
7840 GST_DEBUG_OBJECT (src, "insane range, set to NONE");
7843 /* live (WMS) might send min == max, which is not worth recording */
7844 if (segment->duration == -1 && seconds == segment->start)
7847 /* don't change duration with unknown value, we might have a valid value
7848 * there that we want to keep. */
7850 segment->duration = seconds;
7855 /* Parse clock profived by the server with following syntax:
7857 * "GstNetTimeProvider <wrapped-clock> <server-IP:port> <clock-time>"
7860 gst_rtspsrc_parse_gst_clock (GstRTSPSrc * src, const gchar * gstclock)
7862 gboolean res = FALSE;
7864 if (g_str_has_prefix (gstclock, "GstNetTimeProvider ")) {
7865 gchar **fields = NULL, **parts = NULL;
7866 gchar *remote_ip, *str;
7868 GstClockTime base_time;
7871 fields = g_strsplit (gstclock, " ", 0);
7873 /* wrapped clock, not very interesting for now */
7874 if (fields[1] == NULL)
7877 /* remote IP address and port */
7878 if ((str = fields[2]) == NULL)
7881 parts = g_strsplit (str, ":", 0);
7883 if ((remote_ip = parts[0]) == NULL)
7886 if ((str = parts[1]) == NULL)
7894 if ((str = fields[3]) == NULL)
7897 base_time = g_ascii_strtoull (str, NULL, 10);
7900 gst_net_client_clock_new ((gchar *) "GstRTSPClock", remote_ip, port,
7903 if (src->provided_clock)
7904 gst_object_unref (src->provided_clock);
7905 src->provided_clock = netclock;
7907 gst_element_post_message (GST_ELEMENT_CAST (src),
7908 gst_message_new_clock_provide (GST_OBJECT_CAST (src),
7909 src->provided_clock, TRUE));
7913 g_strfreev (fields);
7919 /* must be called with the RTSP state lock */
7920 static GstRTSPResult
7921 gst_rtspsrc_open_from_sdp (GstRTSPSrc * src, GstSDPMessage * sdp,
7927 /* prepare global stream caps properties */
7929 gst_structure_remove_all_fields (src->props);
7931 src->props = gst_structure_new_empty ("RTSPProperties");
7933 DEBUG_SDP (src, sdp);
7935 gst_rtsp_ext_list_parse_sdp (src->extensions, sdp, src->props);
7937 /* let the app inspect and change the SDP */
7938 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_ON_SDP], 0, sdp);
7940 gst_segment_init (&src->segment, GST_FORMAT_TIME);
7942 /* parse range for duration reporting. */
7947 range = gst_sdp_message_get_attribute_val_n (sdp, "range", i);
7951 /* keep track of the range and configure it in the segment */
7952 if (gst_rtspsrc_parse_range (src, range, &src->segment))
7956 /* parse clock information. This is GStreamer specific, a server can tell the
7957 * client what clock it is using and wrap that in a network clock. The
7958 * advantage of that is that we can slave to it. */
7960 const gchar *gstclock;
7963 gstclock = gst_sdp_message_get_attribute_val_n (sdp, "x-gst-clock", i);
7964 if (gstclock == NULL)
7967 /* parse the clock and expose it in the provide_clock method */
7968 if (gst_rtspsrc_parse_gst_clock (src, gstclock))
7972 /* try to find a global control attribute. Note that a '*' means that we should
7973 * do aggregate control with the current url (so we don't do anything and
7974 * leave the current connection as is) */
7976 const gchar *control;
7979 control = gst_sdp_message_get_attribute_val_n (sdp, "control", i);
7980 if (control == NULL)
7983 /* only take fully qualified urls */
7984 if (g_str_has_prefix (control, "rtsp://"))
7988 g_free (src->conninfo.location);
7989 src->conninfo.location = g_strdup (control);
7990 /* make a connection for this, if there was a connection already, nothing
7992 if (gst_rtsp_conninfo_connect (src, &src->conninfo, async) < 0) {
7993 GST_ERROR_OBJECT (src, "could not connect");
7996 /* we need to keep the control url separate from the connection url because
7997 * the rules for constructing the media control url need it */
7998 g_free (src->control);
7999 src->control = g_strdup (control);
8002 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8003 src->is_audio_codec_supported = FALSE;
8004 src->is_video_codec_supported = FALSE;
8007 /* create streams */
8008 n_streams = gst_sdp_message_medias_len (sdp);
8009 for (i = 0; i < n_streams; i++) {
8010 gst_rtspsrc_create_stream (src, sdp, i, n_streams);
8013 src->state = GST_RTSP_STATE_INIT;
8014 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8015 /* Check for the support for the Media codecs */
8016 if ((!src->is_audio_codec_supported) && (!src->is_video_codec_supported)) {
8017 GST_ERROR_OBJECT (src, "UnSupported Media Type !!!! \n");
8018 goto unsupported_file_type;
8020 GST_DEBUG_OBJECT (src, "Supported Media Type. \n");
8024 if ((res = gst_rtspsrc_setup_streams_start (src, async)) < 0)
8027 /* reset our state */
8028 src->need_range = TRUE;
8031 src->state = GST_RTSP_STATE_READY;
8038 GST_ERROR_OBJECT (src, "setup failed");
8039 gst_rtspsrc_cleanup (src);
8042 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8043 unsupported_file_type:
8045 gst_rtspsrc_post_error_message (src,
8046 GST_RTSPSRC_ERROR_UNSUPPORTED_MEDIA_TYPE,
8047 "No supported stream was found");
8048 res = GST_RTSP_ERROR;
8049 gst_rtspsrc_cleanup (src);
8055 static GstRTSPResult
8056 gst_rtspsrc_retrieve_sdp (GstRTSPSrc * src, GstSDPMessage ** sdp,
8060 GstRTSPMessage request = { 0 };
8061 GstRTSPMessage response = { 0 };
8064 gchar *respcont = NULL;
8065 GstRTSPVersion versions[] =
8066 { GST_RTSP_VERSION_2_0, GST_RTSP_VERSION_INVALID };
8068 src->version = src->default_version;
8069 if (src->default_version == GST_RTSP_VERSION_2_0) {
8070 versions[0] = GST_RTSP_VERSION_1_0;
8074 src->need_redirect = FALSE;
8076 /* can't continue without a valid url */
8077 if (G_UNLIKELY (src->conninfo.url == NULL)) {
8078 res = GST_RTSP_EINVAL;
8081 src->tried_url_auth = FALSE;
8083 if ((res = gst_rtsp_conninfo_connect (src, &src->conninfo, async)) < 0)
8084 goto connect_failed;
8086 /* create OPTIONS */
8087 GST_DEBUG_OBJECT (src, "create options... (%s)", async ? "async" : "sync");
8089 gst_rtspsrc_init_request (src, &request, GST_RTSP_OPTIONS,
8090 src->conninfo.url_str);
8092 goto create_request_failed;
8095 request.type_data.request.version = src->version;
8096 GST_DEBUG_OBJECT (src, "send options...");
8099 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving server options"));
8102 gst_rtspsrc_send (src, &src->conninfo, &request, &response,
8103 NULL, versions)) < 0) {
8107 src->version = request.type_data.request.version;
8108 GST_INFO_OBJECT (src, "Now using version: %s",
8109 gst_rtsp_version_as_text (src->version));
8112 if (!gst_rtspsrc_parse_methods (src, &response))
8115 /* create DESCRIBE */
8116 GST_DEBUG_OBJECT (src, "create describe...");
8118 gst_rtspsrc_init_request (src, &request, GST_RTSP_DESCRIBE,
8119 src->conninfo.url_str);
8121 goto create_request_failed;
8123 /* we only accept SDP for now */
8124 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_ACCEPT,
8127 if (src->backchannel == BACKCHANNEL_ONVIF)
8128 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
8129 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
8130 /* TODO: Handle the case when backchannel is unsupported and goto restart */
8133 GST_DEBUG_OBJECT (src, "send describe...");
8136 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving media info"));
8139 gst_rtspsrc_send (src, &src->conninfo, &request, &response,
8143 /* we only perform redirect for describe and play, currently */
8144 if (src->need_redirect) {
8145 /* close connection, we don't have to send a TEARDOWN yet, ignore the
8147 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
8149 gst_rtsp_message_unset (&request);
8150 gst_rtsp_message_unset (&response);
8156 /* it could be that the DESCRIBE method was not implemented */
8157 if (!(src->methods & GST_RTSP_DESCRIBE))
8160 /* check if reply is SDP */
8161 gst_rtsp_message_get_header (&response, GST_RTSP_HDR_CONTENT_TYPE, &respcont,
8163 /* could not be set but since the request returned OK, we assume it
8164 * was SDP, else check it. */
8166 const gchar *props = strchr (respcont, ';');
8169 gchar *mimetype = g_strndup (respcont, props - respcont);
8171 mimetype = g_strstrip (mimetype);
8172 if (g_ascii_strcasecmp (mimetype, "application/sdp") != 0) {
8174 goto wrong_content_type;
8177 /* TODO: Check for charset property and do conversions of all messages if
8178 * needed. Some servers actually send that property */
8181 } else if (g_ascii_strcasecmp (respcont, "application/sdp") != 0) {
8182 goto wrong_content_type;
8186 /* get message body and parse as SDP */
8187 gst_rtsp_message_get_body (&response, &data, &size);
8188 if (data == NULL || size == 0)
8191 GST_DEBUG_OBJECT (src, "parse SDP...");
8192 gst_sdp_message_new (sdp);
8193 gst_sdp_message_parse_buffer (data, size, *sdp);
8195 /* clean up any messages */
8196 gst_rtsp_message_unset (&request);
8197 gst_rtsp_message_unset (&response);
8204 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8205 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_INVALID_URL,
8206 "No valid RTSP URL was provided");
8208 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
8209 ("No valid RTSP URL was provided"));
8215 gchar *str = gst_rtsp_strresult (res);
8217 if (res != GST_RTSP_EINTR) {
8218 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8219 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
8220 "Failed to connect.");
8222 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
8223 ("Failed to connect. (%s)", str));
8226 GST_WARNING_OBJECT (src, "connect interrupted");
8231 create_request_failed:
8233 gchar *str = gst_rtsp_strresult (res);
8235 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8236 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
8237 "Could not create request.");
8239 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8240 ("Could not create request. (%s)", str));
8247 /* Don't post a message - the rtsp_send method will have
8248 * taken care of it because we passed NULL for the response code */
8253 /* error was posted */
8254 res = GST_RTSP_ERROR;
8259 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8260 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_OPTION_NOT_SUPPORTED,
8261 "Server does not support SDP. ");
8263 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
8264 ("Server does not support SDP, got %s.", respcont));
8266 res = GST_RTSP_ERROR;
8271 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8272 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_METHOD_NOT_ALLOWED,
8273 "Server can not provide an SDP.");
8275 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
8276 ("Server can not provide an SDP."));
8278 res = GST_RTSP_ERROR;
8283 if (src->conninfo.connection) {
8284 GST_DEBUG_OBJECT (src, "free connection");
8285 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
8287 gst_rtsp_message_unset (&request);
8288 gst_rtsp_message_unset (&response);
8293 static GstRTSPResult
8294 gst_rtspsrc_open (GstRTSPSrc * src, gboolean async)
8299 GST_RTSP_SETUP | GST_RTSP_PLAY | GST_RTSP_PAUSE | GST_RTSP_TEARDOWN;
8301 if (src->sdp == NULL) {
8302 if ((ret = gst_rtspsrc_retrieve_sdp (src, &src->sdp, async)) < 0)
8306 if ((ret = gst_rtspsrc_open_from_sdp (src, src->sdp, async)) < 0)
8311 gst_rtspsrc_loop_end_cmd (src, CMD_OPEN, ret);
8318 GST_WARNING_OBJECT (src, "can't get sdp");
8319 src->open_error = TRUE;
8324 GST_WARNING_OBJECT (src, "can't setup streaming from sdp");
8325 src->open_error = TRUE;
8330 static GstRTSPResult
8331 gst_rtspsrc_close (GstRTSPSrc * src, gboolean async, gboolean only_close)
8333 GstRTSPMessage request = { 0 };
8334 GstRTSPMessage response = { 0 };
8335 GstRTSPResult res = GST_RTSP_OK;
8337 const gchar *control;
8339 GST_DEBUG_OBJECT (src, "TEARDOWN...");
8341 gst_rtspsrc_set_state (src, GST_STATE_READY);
8343 if (src->state < GST_RTSP_STATE_READY) {
8344 GST_DEBUG_OBJECT (src, "not ready, doing cleanup");
8351 /* construct a control url */
8352 control = get_aggregate_control (src);
8354 if (!(src->methods & (GST_RTSP_PLAY | GST_RTSP_TEARDOWN)))
8357 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8358 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8359 const gchar *setup_url;
8360 GstRTSPConnInfo *info;
8362 /* try aggregate control first but do non-aggregate control otherwise */
8364 setup_url = control;
8365 else if ((setup_url = stream->conninfo.location) == NULL)
8368 if (src->conninfo.connection) {
8369 info = &src->conninfo;
8370 } else if (stream->conninfo.connection) {
8371 info = &stream->conninfo;
8375 if (!info->connected)
8380 gst_rtspsrc_init_request (src, &request, GST_RTSP_TEARDOWN, setup_url);
8381 GST_LOG_OBJECT (src, "Teardown on %s", setup_url);
8383 goto create_request_failed;
8385 if (stream->is_backchannel && src->backchannel == BACKCHANNEL_ONVIF)
8386 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
8387 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
8390 GST_ELEMENT_PROGRESS (src, CONTINUE, "close", ("Closing stream"));
8393 gst_rtspsrc_send (src, info, &request, &response, NULL, NULL)) < 0)
8396 /* FIXME, parse result? */
8397 gst_rtsp_message_unset (&request);
8398 gst_rtsp_message_unset (&response);
8401 /* early exit when we did aggregate control */
8407 /* close connections */
8408 GST_DEBUG_OBJECT (src, "closing connection...");
8409 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
8410 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8411 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8412 gst_rtsp_conninfo_close (src, &stream->conninfo, TRUE);
8416 gst_rtspsrc_cleanup (src);
8418 src->state = GST_RTSP_STATE_INVALID;
8421 gst_rtspsrc_loop_end_cmd (src, CMD_CLOSE, res);
8426 create_request_failed:
8428 gchar *str = gst_rtsp_strresult (res);
8430 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8431 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
8432 "Could not create request.");
8434 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8435 ("Could not create request. (%s)", str));
8442 gchar *str = gst_rtsp_strresult (res);
8444 gst_rtsp_message_unset (&request);
8445 if (res != GST_RTSP_EINTR) {
8446 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8447 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
8448 "Could not send message.");
8450 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
8451 ("Could not send message. (%s)", str));
8454 GST_WARNING_OBJECT (src, "TEARDOWN interrupted");
8461 GST_DEBUG_OBJECT (src,
8462 "TEARDOWN and PLAY not supported, can't do TEARDOWN");
8467 /* RTP-Info is of the format:
8469 * url=<URL>;[seq=<seqbase>;rtptime=<timebase>] [, url=...]
8471 * rtptime corresponds to the timestamp for the NPT time given in the header
8472 * seqbase corresponds to the next sequence number we received. This number
8473 * indicates the first seqnum after the seek and should be used to discard
8474 * packets that are from before the seek.
8477 gst_rtspsrc_parse_rtpinfo (GstRTSPSrc * src, gchar * rtpinfo)
8482 GST_DEBUG_OBJECT (src, "parsing RTP-Info %s", rtpinfo);
8484 infos = g_strsplit (rtpinfo, ",", 0);
8485 for (i = 0; infos[i]; i++) {
8487 GstRTSPStream *stream;
8491 GST_DEBUG_OBJECT (src, "parsing info %s", infos[i]);
8493 /* init values, types of seqbase and timebase are bigger than needed so we
8494 * can store -1 as uninitialized values */
8499 /* parse url, find stream for url.
8500 * parse seq and rtptime. The seq number should be configured in the rtp
8501 * depayloader or session manager to detect gaps. Same for the rtptime, it
8502 * should be used to create an initial time newsegment. */
8503 fields = g_strsplit (infos[i], ";", 0);
8504 for (j = 0; fields[j]; j++) {
8505 GST_DEBUG_OBJECT (src, "parsing field %s", fields[j]);
8506 /* remove leading whitespace */
8507 fields[j] = g_strchug (fields[j]);
8508 if (g_str_has_prefix (fields[j], "url=")) {
8509 /* get the url and the stream */
8511 find_stream (src, (fields[j] + 4), (gpointer) find_stream_by_setup);
8512 } else if (g_str_has_prefix (fields[j], "seq=")) {
8513 seqbase = atoi (fields[j] + 4);
8514 } else if (g_str_has_prefix (fields[j], "rtptime=")) {
8515 timebase = g_ascii_strtoll (fields[j] + 8, NULL, 10);
8518 g_strfreev (fields);
8519 /* now we need to store the values for the caps of the stream */
8520 if (stream != NULL) {
8521 GST_DEBUG_OBJECT (src,
8522 "found stream %p, setting: seqbase %d, timebase %" G_GINT64_FORMAT,
8523 stream, seqbase, timebase);
8525 /* we have a stream, configure detected params */
8526 stream->seqbase = seqbase;
8527 stream->timebase = timebase;
8536 gst_rtspsrc_handle_rtcp_interval (GstRTSPSrc * src, gchar * rtcp)
8541 interval = strtoul (rtcp, NULL, 10);
8542 GST_DEBUG_OBJECT (src, "rtcp interval: %" G_GUINT64_FORMAT " ms", interval);
8547 interval *= GST_MSECOND;
8549 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8550 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8552 /* already (optionally) retrieved this when configuring manager */
8553 if (stream->session) {
8554 GObject *rtpsession = stream->session;
8556 GST_DEBUG_OBJECT (src, "configure rtcp interval in session %p",
8558 g_object_set (rtpsession, "rtcp-min-interval", interval, NULL);
8562 /* now it happens that (Xenon) server sending this may also provide bogus
8563 * RTCP SR sync data (i.e. with quite some jitter), so never mind those
8564 * and just use RTP-Info to sync */
8566 GObjectClass *klass;
8568 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
8569 if (g_object_class_find_property (klass, "rtcp-sync")) {
8570 GST_DEBUG_OBJECT (src, "configuring rtp sync method");
8571 g_object_set (src->manager, "rtcp-sync", RTCP_SYNC_RTP, NULL);
8577 gst_rtspsrc_get_float (const gchar * dstr)
8579 gchar s[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
8581 /* canonicalise floating point string so we can handle float strings
8582 * in the form "24.930" or "24,930" irrespective of the current locale */
8583 g_strlcpy (s, dstr, sizeof (s));
8584 g_strdelimit (s, ",", '.');
8585 return g_ascii_strtod (s, NULL);
8589 gen_range_header (GstRTSPSrc * src, GstSegment * segment)
8591 gchar val_str[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
8592 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8593 if (src->start_position != 0 && segment->position == 0) {
8594 segment->position = src->start_position;
8595 src->start_position = 0;
8598 if (src->range && src->range->min.type == GST_RTSP_TIME_NOW) {
8599 g_strlcpy (val_str, "now", sizeof (val_str));
8601 if (segment->position == 0) {
8602 g_strlcpy (val_str, "0", sizeof (val_str));
8604 g_ascii_dtostr (val_str, sizeof (val_str),
8605 ((gdouble) segment->position) / GST_SECOND);
8608 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8609 GST_DEBUG_OBJECT (src, "Range Header Added : npt=%s-", val_str);
8611 return g_strdup_printf ("npt=%s-", val_str);
8615 clear_rtp_base (GstRTSPSrc * src, GstRTSPStream * stream)
8619 stream->timebase = -1;
8620 stream->seqbase = -1;
8622 len = stream->ptmap->len;
8623 for (i = 0; i < len; i++) {
8624 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
8627 if (item->caps == NULL)
8630 item->caps = gst_caps_make_writable (item->caps);
8631 s = gst_caps_get_structure (item->caps, 0);
8632 gst_structure_remove_fields (s, "clock-base", "seqnum-base", NULL);
8633 if (item->pt == stream->default_pt && stream->udpsrc[0])
8634 g_object_set (stream->udpsrc[0], "caps", item->caps, NULL);
8636 stream->need_caps = TRUE;
8639 static GstRTSPResult
8640 gst_rtspsrc_ensure_open (GstRTSPSrc * src, gboolean async)
8642 GstRTSPResult res = GST_RTSP_OK;
8644 if (src->state < GST_RTSP_STATE_READY) {
8645 res = GST_RTSP_ERROR;
8646 if (src->open_error) {
8647 GST_DEBUG_OBJECT (src, "the stream was in error");
8651 gst_rtspsrc_loop_start_cmd (src, CMD_OPEN);
8653 if ((res = gst_rtspsrc_open (src, async)) < 0) {
8654 GST_DEBUG_OBJECT (src, "failed to open stream");
8663 static GstRTSPResult
8664 gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment, gboolean async,
8665 const gchar * seek_style)
8667 GstRTSPMessage request = { 0 };
8668 GstRTSPMessage response = { 0 };
8669 GstRTSPResult res = GST_RTSP_OK;
8673 const gchar *control;
8675 GST_DEBUG_OBJECT (src, "PLAY...");
8678 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
8681 if (!(src->methods & GST_RTSP_PLAY))
8684 if (src->state == GST_RTSP_STATE_PLAYING)
8687 if (!src->conninfo.connection || !src->conninfo.connected)
8690 /* send some dummy packets before we activate the receive in the
8692 gst_rtspsrc_send_dummy_packets (src);
8694 /* require new SR packets */
8696 g_signal_emit_by_name (src->manager, "reset-sync", NULL);
8698 /* construct a control url */
8699 control = get_aggregate_control (src);
8701 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8702 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8703 const gchar *setup_url;
8704 GstRTSPConnInfo *conninfo;
8706 /* try aggregate control first but do non-aggregate control otherwise */
8708 setup_url = control;
8709 else if ((setup_url = stream->conninfo.location) == NULL)
8712 if (src->conninfo.connection) {
8713 conninfo = &src->conninfo;
8714 } else if (stream->conninfo.connection) {
8715 conninfo = &stream->conninfo;
8721 res = gst_rtspsrc_init_request (src, &request, GST_RTSP_PLAY, setup_url);
8723 goto create_request_failed;
8725 if (src->need_range && src->seekable >= 0.0) {
8726 #ifndef TIZEN_FEATURE_RTSP_MODIFICATION
8727 hval = gen_range_header (src, segment);
8729 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_RANGE, hval);
8732 /* store the newsegment event so it can be sent from the streaming thread. */
8733 src->need_segment = TRUE;
8735 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8738 Updating position with the MSL current position as gst_rtspsrc_get_position() does not return correct position.
8740 GST_DEBUG_OBJECT (src,
8741 " During normal pause-resume , segment->position=%" GST_TIME_FORMAT
8742 ",src->start_position=%" GST_TIME_FORMAT,
8743 GST_TIME_ARGS (segment->position),
8744 GST_TIME_ARGS (src->start_position));
8745 segment->position = src->last_pos;
8749 Sending the npt range request for each play request for updating the segment position properly.
8751 hval = gen_range_header (src, segment);
8752 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_RANGE, hval);
8755 if (segment->rate != 1.0) {
8756 gchar hval[G_ASCII_DTOSTR_BUF_SIZE];
8758 g_ascii_dtostr (hval, sizeof (hval), segment->rate);
8760 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SCALE, hval);
8762 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SPEED, hval);
8766 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SEEK_STYLE,
8769 /* when we have an ONVIF audio backchannel, the PLAY request must have the
8770 * Require: header when doing either aggregate or non-aggregate control */
8771 if (src->backchannel == BACKCHANNEL_ONVIF &&
8772 (control || stream->is_backchannel))
8773 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
8774 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
8777 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("Sending PLAY request"));
8780 gst_rtspsrc_send (src, conninfo, &request, &response, NULL, NULL))
8784 if (src->need_redirect) {
8785 GST_DEBUG_OBJECT (src,
8786 "redirect: tearing down and restarting with new url");
8787 /* teardown and restart with new url */
8788 gst_rtspsrc_close (src, TRUE, FALSE);
8789 /* reset protocols to force re-negotiation with redirected url */
8790 src->cur_protocols = src->protocols;
8791 gst_rtsp_message_unset (&request);
8792 gst_rtsp_message_unset (&response);
8796 /* seek may have silently failed as it is not supported */
8797 if (!(src->methods & GST_RTSP_PLAY)) {
8798 GST_DEBUG_OBJECT (src, "PLAY Range not supported; re-enable PLAY");
8800 if (src->version >= GST_RTSP_VERSION_2_0 && src->seekable >= 0.0) {
8801 GST_WARNING_OBJECT (src, "Server declared stream as seekable but"
8802 " playing with range failed... Ignoring information.");
8804 /* obviously it is supported as we made it here */
8805 src->methods |= GST_RTSP_PLAY;
8806 src->seekable = -1.0;
8807 /* but there is nothing to parse in the response,
8808 * so convey we have no idea and not to expect anything particular */
8809 clear_rtp_base (src, stream);
8813 /* need to do for all streams */
8814 for (run = src->streams; run; run = g_list_next (run))
8815 clear_rtp_base (src, (GstRTSPStream *) run->data);
8817 /* NOTE the above also disables npt based eos detection */
8818 /* and below forces position to 0,
8819 * which is visible feedback we lost the plot */
8820 segment->start = segment->position = src->last_pos;
8823 gst_rtsp_message_unset (&request);
8825 /* parse RTP npt field. This is the current position in the stream (Normal
8826 * Play Time) and should be put in the NEWSEGMENT position field. */
8827 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RANGE, &hval,
8829 gst_rtspsrc_parse_range (src, hval, segment);
8831 /* assume 1.0 rate now, overwrite when the SCALE or SPEED headers are present. */
8832 segment->rate = 1.0;
8834 /* parse Speed header. This is the intended playback rate of the stream
8835 * and should be put in the NEWSEGMENT rate field. */
8836 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SPEED, &hval,
8837 0) == GST_RTSP_OK) {
8838 segment->rate = gst_rtspsrc_get_float (hval);
8839 } else if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SCALE,
8840 &hval, 0) == GST_RTSP_OK) {
8841 segment->rate = gst_rtspsrc_get_float (hval);
8844 /* parse the RTP-Info header field (if ANY) to get the base seqnum and timestamp
8845 * for the RTP packets. If this is not present, we assume all starts from 0...
8846 * This is info for the RTP session manager that we pass to it in caps. */
8848 while (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTP_INFO,
8849 &hval, hval_idx++) == GST_RTSP_OK)
8850 gst_rtspsrc_parse_rtpinfo (src, hval);
8852 /* some servers indicate RTCP parameters in PLAY response,
8853 * rather than properly in SDP */
8854 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTCP_INTERVAL,
8855 &hval, 0) == GST_RTSP_OK)
8856 gst_rtspsrc_handle_rtcp_interval (src, hval);
8858 gst_rtsp_message_unset (&response);
8860 /* early exit when we did aggregate control */
8864 /* configure the caps of the streams after we parsed all headers. Only reset
8865 * the manager object when we set a new Range header (we did a seek) */
8866 gst_rtspsrc_configure_caps (src, segment, src->need_range);
8868 /* set to PLAYING after we have configured the caps, otherwise we
8869 * might end up calling request_key (with SRTP) while caps are still
8870 * being configured. */
8871 gst_rtspsrc_set_state (src, GST_STATE_PLAYING);
8873 /* set again when needed */
8874 src->need_range = FALSE;
8876 src->running = TRUE;
8877 src->base_time = -1;
8878 src->state = GST_RTSP_STATE_PLAYING;
8881 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
8882 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8883 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8884 stream->discont = TRUE;
8889 gst_rtspsrc_loop_end_cmd (src, CMD_PLAY, res);
8896 GST_WARNING_OBJECT (src, "failed to open stream");
8901 GST_WARNING_OBJECT (src, "PLAY is not supported");
8906 GST_WARNING_OBJECT (src, "we were already PLAYING");
8909 create_request_failed:
8911 gchar *str = gst_rtsp_strresult (res);
8913 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8914 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
8915 "Could not create request. ");
8917 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8918 ("Could not create request. (%s)", str));
8925 gchar *str = gst_rtsp_strresult (res);
8927 gst_rtsp_message_unset (&request);
8928 if (res != GST_RTSP_EINTR) {
8929 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
8930 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
8931 "Could not send message.");
8933 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
8934 ("Could not send message. (%s)", str));
8937 GST_WARNING_OBJECT (src, "PLAY interrupted");
8944 static GstRTSPResult
8945 gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async)
8947 GstRTSPResult res = GST_RTSP_OK;
8948 GstRTSPMessage request = { 0 };
8949 GstRTSPMessage response = { 0 };
8951 const gchar *control;
8953 GST_DEBUG_OBJECT (src, "PAUSE...");
8955 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
8958 if (!(src->methods & GST_RTSP_PAUSE))
8961 if (src->state == GST_RTSP_STATE_READY)
8964 if (!src->conninfo.connection || !src->conninfo.connected)
8967 /* construct a control url */
8968 control = get_aggregate_control (src);
8970 /* loop over the streams. We might exit the loop early when we could do an
8971 * aggregate control */
8972 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8973 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8974 GstRTSPConnInfo *conninfo;
8975 const gchar *setup_url;
8977 /* try aggregate control first but do non-aggregate control otherwise */
8979 setup_url = control;
8980 else if ((setup_url = stream->conninfo.location) == NULL)
8983 if (src->conninfo.connection) {
8984 conninfo = &src->conninfo;
8985 } else if (stream->conninfo.connection) {
8986 conninfo = &stream->conninfo;
8992 GST_ELEMENT_PROGRESS (src, CONTINUE, "request",
8993 ("Sending PAUSE request"));
8996 gst_rtspsrc_init_request (src, &request, GST_RTSP_PAUSE,
8998 goto create_request_failed;
9000 /* when we have an ONVIF audio backchannel, the PAUSE request must have the
9001 * Require: header when doing either aggregate or non-aggregate control */
9002 if (src->backchannel == BACKCHANNEL_ONVIF &&
9003 (control || stream->is_backchannel))
9004 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
9005 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
9008 gst_rtspsrc_send (src, conninfo, &request, &response, NULL,
9012 gst_rtsp_message_unset (&request);
9013 gst_rtsp_message_unset (&response);
9015 /* exit early when we did agregate control */
9020 /* change element states now */
9021 gst_rtspsrc_set_state (src, GST_STATE_PAUSED);
9024 src->state = GST_RTSP_STATE_READY;
9028 gst_rtspsrc_loop_end_cmd (src, CMD_PAUSE, res);
9035 GST_DEBUG_OBJECT (src, "failed to open stream");
9040 GST_DEBUG_OBJECT (src, "PAUSE is not supported");
9045 GST_DEBUG_OBJECT (src, "we were already PAUSED");
9048 create_request_failed:
9050 gchar *str = gst_rtsp_strresult (res);
9052 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
9053 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_BAD_REQUEST,
9054 "Could not create request.");
9056 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
9057 ("Could not create request. (%s)", str));
9064 gchar *str = gst_rtsp_strresult (res);
9066 gst_rtsp_message_unset (&request);
9067 if (res != GST_RTSP_EINTR) {
9068 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
9069 gst_rtspsrc_post_error_message (src, GST_RTSPSRC_ERROR_CONNECTION_FAIL,
9070 "Could not send message.");
9072 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
9073 ("Could not send message. (%s)", str));
9076 GST_WARNING_OBJECT (src, "PAUSE interrupted");
9084 gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message)
9086 GstRTSPSrc *rtspsrc;
9088 rtspsrc = GST_RTSPSRC (bin);
9090 switch (GST_MESSAGE_TYPE (message)) {
9091 case GST_MESSAGE_EOS:
9092 gst_message_unref (message);
9094 case GST_MESSAGE_ELEMENT:
9096 const GstStructure *s = gst_message_get_structure (message);
9098 if (gst_structure_has_name (s, "GstUDPSrcTimeout")) {
9099 gboolean ignore_timeout;
9101 GST_DEBUG_OBJECT (bin, "timeout on UDP port");
9103 GST_OBJECT_LOCK (rtspsrc);
9104 ignore_timeout = rtspsrc->ignore_timeout;
9105 rtspsrc->ignore_timeout = TRUE;
9106 GST_OBJECT_UNLOCK (rtspsrc);
9108 /* we only act on the first udp timeout message, others are irrelevant
9109 * and can be ignored. */
9110 if (!ignore_timeout)
9111 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_RECONNECT, CMD_LOOP);
9113 gst_message_unref (message);
9116 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
9119 case GST_MESSAGE_ERROR:
9122 GstRTSPStream *stream;
9125 udpsrc = GST_MESSAGE_SRC (message);
9127 GST_DEBUG_OBJECT (rtspsrc, "got error from %s",
9128 GST_ELEMENT_NAME (udpsrc));
9130 stream = find_stream (rtspsrc, udpsrc, (gpointer) find_stream_by_udpsrc);
9134 /* we ignore the RTCP udpsrc */
9135 if (stream->udpsrc[1] == GST_ELEMENT_CAST (udpsrc))
9138 /* if we get error messages from the udp sources, that's not a problem as
9139 * long as not all of them error out. We also don't really know what the
9140 * problem is, the message does not give enough detail... */
9141 ret = gst_rtspsrc_combine_flows (rtspsrc, stream, GST_FLOW_NOT_LINKED);
9142 GST_DEBUG_OBJECT (rtspsrc, "combined flows: %s", gst_flow_get_name (ret));
9143 if (ret != GST_FLOW_OK)
9147 gst_message_unref (message);
9151 /* fatal but not our message, forward */
9152 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
9157 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
9163 /* the thread where everything happens */
9165 gst_rtspsrc_thread (GstRTSPSrc * src)
9168 ParameterRequest *req = NULL;
9170 GST_OBJECT_LOCK (src);
9171 cmd = src->pending_cmd;
9172 if (cmd == CMD_RECONNECT || cmd == CMD_PLAY || cmd == CMD_PAUSE
9173 || cmd == CMD_LOOP || cmd == CMD_OPEN || cmd == CMD_GET_PARAMETER
9174 || cmd == CMD_SET_PARAMETER) {
9175 if (g_queue_is_empty (&src->set_get_param_q)) {
9176 src->pending_cmd = CMD_LOOP;
9178 ParameterRequest *next_req;
9179 req = g_queue_pop_head (&src->set_get_param_q);
9180 next_req = g_queue_peek_head (&src->set_get_param_q);
9181 src->pending_cmd = next_req ? next_req->cmd : CMD_LOOP;
9184 src->pending_cmd = CMD_WAIT;
9185 GST_DEBUG_OBJECT (src, "got command %s", cmd_to_string (cmd));
9187 /* we got the message command, so ensure communication is possible again */
9188 gst_rtspsrc_connection_flush (src, FALSE);
9190 src->busy_cmd = cmd;
9191 GST_OBJECT_UNLOCK (src);
9195 gst_rtspsrc_open (src, TRUE);
9198 gst_rtspsrc_play (src, &src->segment, TRUE, NULL);
9201 gst_rtspsrc_pause (src, TRUE);
9204 gst_rtspsrc_close (src, TRUE, FALSE);
9206 case CMD_GET_PARAMETER:
9207 gst_rtspsrc_get_parameter (src, req);
9209 case CMD_SET_PARAMETER:
9210 gst_rtspsrc_set_parameter (src, req);
9213 gst_rtspsrc_loop (src);
9216 gst_rtspsrc_reconnect (src, FALSE);
9222 GST_OBJECT_LOCK (src);
9223 /* No more cmds, wake any waiters */
9224 g_cond_broadcast (&src->cmd_cond);
9225 /* and go back to sleep */
9226 if (src->pending_cmd == CMD_WAIT) {
9228 gst_task_pause (src->task);
9231 src->busy_cmd = CMD_WAIT;
9232 GST_OBJECT_UNLOCK (src);
9236 gst_rtspsrc_start (GstRTSPSrc * src)
9238 GST_DEBUG_OBJECT (src, "starting");
9240 GST_OBJECT_LOCK (src);
9242 src->pending_cmd = CMD_WAIT;
9244 if (src->task == NULL) {
9245 src->task = gst_task_new ((GstTaskFunction) gst_rtspsrc_thread, src, NULL);
9246 if (src->task == NULL)
9249 gst_task_set_lock (src->task, GST_RTSP_STREAM_GET_LOCK (src));
9251 GST_OBJECT_UNLOCK (src);
9258 GST_OBJECT_UNLOCK (src);
9259 GST_ERROR_OBJECT (src, "failed to create task");
9265 gst_rtspsrc_stop (GstRTSPSrc * src)
9269 GST_DEBUG_OBJECT (src, "stopping");
9271 /* also cancels pending task */
9272 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_ALL);
9274 GST_OBJECT_LOCK (src);
9275 if ((task = src->task)) {
9277 GST_OBJECT_UNLOCK (src);
9279 gst_task_stop (task);
9281 /* make sure it is not running */
9282 GST_RTSP_STREAM_LOCK (src);
9283 GST_RTSP_STREAM_UNLOCK (src);
9285 /* now wait for the task to finish */
9286 gst_task_join (task);
9288 /* and free the task */
9289 gst_object_unref (GST_OBJECT (task));
9291 GST_OBJECT_LOCK (src);
9293 GST_OBJECT_UNLOCK (src);
9295 /* ensure synchronously all is closed and clean */
9296 gst_rtspsrc_close (src, FALSE, TRUE);
9301 static GstStateChangeReturn
9302 gst_rtspsrc_change_state (GstElement * element, GstStateChange transition)
9304 GstRTSPSrc *rtspsrc;
9305 GstStateChangeReturn ret;
9306 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
9310 rtspsrc = GST_RTSPSRC (element);
9311 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
9312 GST_WARNING_OBJECT (rtspsrc, "State change transition: %d \n", transition);
9315 switch (transition) {
9316 case GST_STATE_CHANGE_NULL_TO_READY:
9317 if (!gst_rtspsrc_start (rtspsrc))
9320 case GST_STATE_CHANGE_READY_TO_PAUSED:
9321 /* init some state */
9322 rtspsrc->cur_protocols = rtspsrc->protocols;
9323 /* first attempt, don't ignore timeouts */
9324 rtspsrc->ignore_timeout = FALSE;
9325 rtspsrc->open_error = FALSE;
9326 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_OPEN, 0);
9328 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
9329 set_manager_buffer_mode (rtspsrc);
9331 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
9332 /* unblock the tcp tasks and make the loop waiting */
9333 if (gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_WAIT, CMD_LOOP)) {
9334 /* make sure it is waiting before we send PAUSE or PLAY below */
9335 GST_RTSP_STREAM_LOCK (rtspsrc);
9336 GST_RTSP_STREAM_UNLOCK (rtspsrc);
9339 case GST_STATE_CHANGE_PAUSED_TO_READY:
9345 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
9346 if (ret == GST_STATE_CHANGE_FAILURE)
9349 switch (transition) {
9350 case GST_STATE_CHANGE_NULL_TO_READY:
9351 ret = GST_STATE_CHANGE_SUCCESS;
9353 case GST_STATE_CHANGE_READY_TO_PAUSED:
9354 #ifdef TIZEN_FEATURE_RTSP_MODIFICATION
9355 /* don't change to PAUSE state before complete stream opend.
9356 see gst_rtspsrc_loop_complete_cmd() */
9357 g_mutex_lock (&(rtspsrc)->pause_lock);
9358 end_time = g_get_monotonic_time () + 10 * G_TIME_SPAN_SECOND;
9359 if (!g_cond_wait_until (&(rtspsrc)->open_end, &(rtspsrc)->pause_lock,
9361 GST_WARNING_OBJECT (rtspsrc,
9362 "time out: stream opend is not completed yet..");
9364 g_mutex_unlock (&(rtspsrc)->pause_lock);
9366 ret = GST_STATE_CHANGE_NO_PREROLL;
9368 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
9369 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PLAY, 0);
9370 ret = GST_STATE_CHANGE_SUCCESS;
9372 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
9373 /* send pause request and keep the idle task around */
9374 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PAUSE, CMD_LOOP);
9375 ret = GST_STATE_CHANGE_NO_PREROLL;
9377 case GST_STATE_CHANGE_PAUSED_TO_READY:
9378 gst_rtspsrc_loop_send_cmd_and_wait (rtspsrc, CMD_CLOSE, CMD_ALL,
9379 rtspsrc->teardown_timeout);
9380 ret = GST_STATE_CHANGE_SUCCESS;
9382 case GST_STATE_CHANGE_READY_TO_NULL:
9383 gst_rtspsrc_stop (rtspsrc);
9384 ret = GST_STATE_CHANGE_SUCCESS;
9387 /* Otherwise it's success, we don't want to return spurious
9388 * NO_PREROLL or ASYNC from internal elements as we care for
9389 * state changes ourselves here
9391 * This is to catch PAUSED->PAUSED and PLAYING->PLAYING transitions.
9393 if (GST_STATE_TRANSITION_NEXT (transition) == GST_STATE_PAUSED)
9394 ret = GST_STATE_CHANGE_NO_PREROLL;
9396 ret = GST_STATE_CHANGE_SUCCESS;
9405 GST_DEBUG_OBJECT (rtspsrc, "start failed");
9406 return GST_STATE_CHANGE_FAILURE;
9411 gst_rtspsrc_send_event (GstElement * element, GstEvent * event)
9414 GstRTSPSrc *rtspsrc;
9416 rtspsrc = GST_RTSPSRC (element);
9418 if (GST_EVENT_IS_DOWNSTREAM (event)) {
9419 res = gst_rtspsrc_push_event (rtspsrc, event);
9421 res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
9428 /*** GSTURIHANDLER INTERFACE *************************************************/
9431 gst_rtspsrc_uri_get_type (GType type)
9436 static const gchar *const *
9437 gst_rtspsrc_uri_get_protocols (GType type)
9439 static const gchar *protocols[] =
9440 { "rtsp", "rtspu", "rtspt", "rtsph", "rtsp-sdp",
9441 "rtsps", "rtspsu", "rtspst", "rtspsh", NULL
9448 gst_rtspsrc_uri_get_uri (GstURIHandler * handler)
9450 GstRTSPSrc *src = GST_RTSPSRC (handler);
9452 /* FIXME: make thread-safe */
9453 return g_strdup (src->conninfo.location);
9457 gst_rtspsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri,
9463 GstRTSPUrl *newurl = NULL;
9464 GstSDPMessage *sdp = NULL;
9466 src = GST_RTSPSRC (handler);
9468 /* same URI, we're fine */
9469 if (src->conninfo.location && uri && !strcmp (uri, src->conninfo.location))
9472 if (g_str_has_prefix (uri, "rtsp-sdp://")) {
9473 sres = gst_sdp_message_new (&sdp);
9477 GST_DEBUG_OBJECT (src, "parsing SDP message");
9478 sres = gst_sdp_message_parse_uri (uri, sdp);
9483 GST_DEBUG_OBJECT (src, "parsing URI");
9484 if ((res = gst_rtsp_url_parse (uri, &newurl)) < 0)
9488 /* if worked, free previous and store new url object along with the original
9490 GST_DEBUG_OBJECT (src, "configuring URI");
9491 g_free (src->conninfo.location);
9492 src->conninfo.location = g_strdup (uri);
9493 gst_rtsp_url_free (src->conninfo.url);
9494 src->conninfo.url = newurl;
9495 g_free (src->conninfo.url_str);
9497 src->conninfo.url_str = gst_rtsp_url_get_request_uri (src->conninfo.url);
9499 src->conninfo.url_str = NULL;
9502 gst_sdp_message_free (src->sdp);
9504 src->from_sdp = sdp != NULL;
9506 GST_DEBUG_OBJECT (src, "set uri: %s", GST_STR_NULL (uri));
9507 GST_DEBUG_OBJECT (src, "request uri is: %s",
9508 GST_STR_NULL (src->conninfo.url_str));
9515 GST_DEBUG_OBJECT (src, "URI was ok: '%s'", GST_STR_NULL (uri));
9520 GST_ERROR_OBJECT (src, "Could not create new SDP (%d)", sres);
9521 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
9522 "Could not create SDP");
9527 GST_ERROR_OBJECT (src, "Not a valid SDP (%d) '%s'", sres,
9528 GST_STR_NULL (uri));
9529 gst_sdp_message_free (sdp);
9530 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
9536 GST_ERROR_OBJECT (src, "Not a valid RTSP url '%s' (%d)",
9537 GST_STR_NULL (uri), res);
9538 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
9539 "Invalid RTSP URI");
9545 gst_rtspsrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
9547 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
9549 iface->get_type = gst_rtspsrc_uri_get_type;
9550 iface->get_protocols = gst_rtspsrc_uri_get_protocols;
9551 iface->get_uri = gst_rtspsrc_uri_get_uri;
9552 iface->set_uri = gst_rtspsrc_uri_set_uri;
9556 /* send GET_PARAMETER */
9557 static GstRTSPResult
9558 gst_rtspsrc_get_parameter (GstRTSPSrc * src, ParameterRequest * req)
9560 GstRTSPMessage request = { 0 };
9561 GstRTSPMessage response = { 0 };
9563 GstRTSPStatusCode code = GST_RTSP_STS_OK;
9564 const gchar *control;
9565 gchar *recv_body = NULL;
9566 guint recv_body_len;
9568 GST_DEBUG_OBJECT (src, "creating server get_parameter");
9570 if ((res = gst_rtspsrc_ensure_open (src, FALSE)) < 0)
9573 control = get_aggregate_control (src);
9574 if (control == NULL)
9577 if (!(src->methods & GST_RTSP_GET_PARAMETER))
9580 gst_rtspsrc_connection_flush (src, FALSE);
9582 res = gst_rtsp_message_init_request (&request, GST_RTSP_GET_PARAMETER,
9585 goto create_request_failed;
9587 res = gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CONTENT_TYPE,
9588 req->content_type == NULL ? "text/parameters" : req->content_type);
9590 goto add_content_hdr_failed;
9592 if (req->body && req->body->len) {
9594 gst_rtsp_message_set_body (&request, (guint8 *) req->body->str,
9597 goto set_body_failed;
9600 if ((res = gst_rtspsrc_send (src, &src->conninfo,
9601 &request, &response, &code, NULL)) < 0)
9604 res = gst_rtsp_message_get_body (&response, (guint8 **) & recv_body,
9607 goto get_body_failed;
9611 gst_promise_reply (req->promise,
9612 gst_structure_new ("get-parameter-reply",
9613 "rtsp-result", G_TYPE_INT, res,
9614 "rtsp-code", G_TYPE_INT, code,
9615 "rtsp-reason", G_TYPE_STRING, gst_rtsp_status_as_text (code),
9616 "body", G_TYPE_STRING, GST_STR_NULL (recv_body), NULL));
9617 free_param_data (req);
9620 gst_rtsp_message_unset (&request);
9621 gst_rtsp_message_unset (&response);
9629 GST_DEBUG_OBJECT (src, "failed to open stream");
9634 GST_DEBUG_OBJECT (src, "no control url to send GET_PARAMETER");
9635 res = GST_RTSP_ERROR;
9640 GST_DEBUG_OBJECT (src, "GET_PARAMETER is not supported");
9641 res = GST_RTSP_ERROR;
9644 create_request_failed:
9646 GST_DEBUG_OBJECT (src, "could not create GET_PARAMETER request");
9649 add_content_hdr_failed:
9651 GST_DEBUG_OBJECT (src, "could not add content header");
9656 GST_DEBUG_OBJECT (src, "could not set body");
9661 gchar *str = gst_rtsp_strresult (res);
9663 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
9664 ("Could not send get-parameter. (%s)", str));
9670 GST_DEBUG_OBJECT (src, "could not get body");
9675 /* send SET_PARAMETER */
9676 static GstRTSPResult
9677 gst_rtspsrc_set_parameter (GstRTSPSrc * src, ParameterRequest * req)
9679 GstRTSPMessage request = { 0 };
9680 GstRTSPMessage response = { 0 };
9681 GstRTSPResult res = GST_RTSP_OK;
9682 GstRTSPStatusCode code = GST_RTSP_STS_OK;
9683 const gchar *control;
9685 GST_DEBUG_OBJECT (src, "creating server set_parameter");
9687 if ((res = gst_rtspsrc_ensure_open (src, FALSE)) < 0)
9690 control = get_aggregate_control (src);
9691 if (control == NULL)
9694 if (!(src->methods & GST_RTSP_SET_PARAMETER))
9697 gst_rtspsrc_connection_flush (src, FALSE);
9700 gst_rtsp_message_init_request (&request, GST_RTSP_SET_PARAMETER, control);
9704 res = gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CONTENT_TYPE,
9705 req->content_type == NULL ? "text/parameters" : req->content_type);
9707 goto add_content_hdr_failed;
9709 if (req->body && req->body->len) {
9711 gst_rtsp_message_set_body (&request, (guint8 *) req->body->str,
9715 goto set_body_failed;
9718 if ((res = gst_rtspsrc_send (src, &src->conninfo,
9719 &request, &response, &code, NULL)) < 0)
9724 gst_promise_reply (req->promise, gst_structure_new ("set-parameter-reply",
9725 "rtsp-result", G_TYPE_INT, res,
9726 "rtsp-code", G_TYPE_INT, code,
9727 "rtsp-reason", G_TYPE_STRING, gst_rtsp_status_as_text (code),
9729 free_param_data (req);
9731 gst_rtsp_message_unset (&request);
9732 gst_rtsp_message_unset (&response);
9740 GST_DEBUG_OBJECT (src, "failed to open stream");
9745 GST_DEBUG_OBJECT (src, "no control url to send SET_PARAMETER");
9746 res = GST_RTSP_ERROR;
9751 GST_DEBUG_OBJECT (src, "SET_PARAMETER is not supported");
9752 res = GST_RTSP_ERROR;
9755 add_content_hdr_failed:
9757 GST_DEBUG_OBJECT (src, "could not add content header");
9762 GST_DEBUG_OBJECT (src, "could not set body");
9767 gchar *str = gst_rtsp_strresult (res);
9769 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
9770 ("Could not send set-parameter. (%s)", str));
9776 typedef struct _RTSPKeyValue
9778 GstRTSPHeaderField field;
9780 gchar *custom_key; /* custom header string (field is INVALID then) */
9784 key_value_foreach (GArray * array, GFunc func, gpointer user_data)
9788 g_return_if_fail (array != NULL);
9790 for (i = 0; i < array->len; i++) {
9791 (*func) (&g_array_index (array, RTSPKeyValue, i), user_data);
9796 dump_key_value (gpointer data, gpointer user_data G_GNUC_UNUSED)
9798 RTSPKeyValue *key_value = (RTSPKeyValue *) data;
9799 GstRTSPSrc *src = GST_RTSPSRC (user_data);
9800 const gchar *key_string;
9802 if (key_value->custom_key != NULL)
9803 key_string = key_value->custom_key;
9805 key_string = gst_rtsp_header_as_text (key_value->field);
9807 GST_LOG_OBJECT (src, " key: '%s', value: '%s'", key_string,
9812 gst_rtspsrc_print_rtsp_message (GstRTSPSrc * src, const GstRTSPMessage * msg)
9816 GString *body_string = NULL;
9818 g_return_if_fail (src != NULL);
9819 g_return_if_fail (msg != NULL);
9821 if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) < GST_LEVEL_LOG)
9824 GST_LOG_OBJECT (src, "--------------------------------------------");
9825 switch (msg->type) {
9826 case GST_RTSP_MESSAGE_REQUEST:
9827 GST_LOG_OBJECT (src, "RTSP request message %p", msg);
9828 GST_LOG_OBJECT (src, " request line:");
9829 GST_LOG_OBJECT (src, " method: '%s'",
9830 gst_rtsp_method_as_text (msg->type_data.request.method));
9831 GST_LOG_OBJECT (src, " uri: '%s'", msg->type_data.request.uri);
9832 GST_LOG_OBJECT (src, " version: '%s'",
9833 gst_rtsp_version_as_text (msg->type_data.request.version));
9834 GST_LOG_OBJECT (src, " headers:");
9835 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9836 GST_LOG_OBJECT (src, " body:");
9837 gst_rtsp_message_get_body (msg, &data, &size);
9839 body_string = g_string_new_len ((const gchar *) data, size);
9840 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9841 g_string_free (body_string, TRUE);
9845 case GST_RTSP_MESSAGE_RESPONSE:
9846 GST_LOG_OBJECT (src, "RTSP response message %p", msg);
9847 GST_LOG_OBJECT (src, " status line:");
9848 GST_LOG_OBJECT (src, " code: '%d'", msg->type_data.response.code);
9849 GST_LOG_OBJECT (src, " reason: '%s'", msg->type_data.response.reason);
9850 GST_LOG_OBJECT (src, " version: '%s",
9851 gst_rtsp_version_as_text (msg->type_data.response.version));
9852 GST_LOG_OBJECT (src, " headers:");
9853 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9854 gst_rtsp_message_get_body (msg, &data, &size);
9855 GST_LOG_OBJECT (src, " body: length %d", size);
9857 body_string = g_string_new_len ((const gchar *) data, size);
9858 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9859 g_string_free (body_string, TRUE);
9863 case GST_RTSP_MESSAGE_HTTP_REQUEST:
9864 GST_LOG_OBJECT (src, "HTTP request message %p", msg);
9865 GST_LOG_OBJECT (src, " request line:");
9866 GST_LOG_OBJECT (src, " method: '%s'",
9867 gst_rtsp_method_as_text (msg->type_data.request.method));
9868 GST_LOG_OBJECT (src, " uri: '%s'", msg->type_data.request.uri);
9869 GST_LOG_OBJECT (src, " version: '%s'",
9870 gst_rtsp_version_as_text (msg->type_data.request.version));
9871 GST_LOG_OBJECT (src, " headers:");
9872 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9873 GST_LOG_OBJECT (src, " body:");
9874 gst_rtsp_message_get_body (msg, &data, &size);
9876 body_string = g_string_new_len ((const gchar *) data, size);
9877 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9878 g_string_free (body_string, TRUE);
9882 case GST_RTSP_MESSAGE_HTTP_RESPONSE:
9883 GST_LOG_OBJECT (src, "HTTP response message %p", msg);
9884 GST_LOG_OBJECT (src, " status line:");
9885 GST_LOG_OBJECT (src, " code: '%d'", msg->type_data.response.code);
9886 GST_LOG_OBJECT (src, " reason: '%s'", msg->type_data.response.reason);
9887 GST_LOG_OBJECT (src, " version: '%s'",
9888 gst_rtsp_version_as_text (msg->type_data.response.version));
9889 GST_LOG_OBJECT (src, " headers:");
9890 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9891 gst_rtsp_message_get_body (msg, &data, &size);
9892 GST_LOG_OBJECT (src, " body: length %d", size);
9894 body_string = g_string_new_len ((const gchar *) data, size);
9895 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9896 g_string_free (body_string, TRUE);
9900 case GST_RTSP_MESSAGE_DATA:
9901 GST_LOG_OBJECT (src, "RTSP data message %p", msg);
9902 GST_LOG_OBJECT (src, " channel: '%d'", msg->type_data.data.channel);
9903 GST_LOG_OBJECT (src, " size: '%d'", msg->body_size);
9904 gst_rtsp_message_get_body (msg, &data, &size);
9906 body_string = g_string_new_len ((const gchar *) data, size);
9907 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9908 g_string_free (body_string, TRUE);
9913 GST_LOG_OBJECT (src, "unsupported message type %d", msg->type);
9916 GST_LOG_OBJECT (src, "--------------------------------------------");
9920 gst_rtspsrc_print_sdp_media (GstRTSPSrc * src, GstSDPMedia * media)
9922 GST_LOG_OBJECT (src, " media: '%s'", GST_STR_NULL (media->media));
9923 GST_LOG_OBJECT (src, " port: '%u'", media->port);
9924 GST_LOG_OBJECT (src, " num_ports: '%u'", media->num_ports);
9925 GST_LOG_OBJECT (src, " proto: '%s'", GST_STR_NULL (media->proto));
9926 if (media->fmts && media->fmts->len > 0) {
9929 GST_LOG_OBJECT (src, " formats:");
9930 for (i = 0; i < media->fmts->len; i++) {
9931 GST_LOG_OBJECT (src, " format '%s'", g_array_index (media->fmts,
9935 GST_LOG_OBJECT (src, " information: '%s'",
9936 GST_STR_NULL (media->information));
9937 if (media->connections && media->connections->len > 0) {
9940 GST_LOG_OBJECT (src, " connections:");
9941 for (i = 0; i < media->connections->len; i++) {
9942 GstSDPConnection *conn =
9943 &g_array_index (media->connections, GstSDPConnection, i);
9945 GST_LOG_OBJECT (src, " nettype: '%s'",
9946 GST_STR_NULL (conn->nettype));
9947 GST_LOG_OBJECT (src, " addrtype: '%s'",
9948 GST_STR_NULL (conn->addrtype));
9949 GST_LOG_OBJECT (src, " address: '%s'",
9950 GST_STR_NULL (conn->address));
9951 GST_LOG_OBJECT (src, " ttl: '%u'", conn->ttl);
9952 GST_LOG_OBJECT (src, " addr_number: '%u'", conn->addr_number);
9955 if (media->bandwidths && media->bandwidths->len > 0) {
9958 GST_LOG_OBJECT (src, " bandwidths:");
9959 for (i = 0; i < media->bandwidths->len; i++) {
9960 GstSDPBandwidth *bw =
9961 &g_array_index (media->bandwidths, GstSDPBandwidth, i);
9963 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (bw->bwtype));
9964 GST_LOG_OBJECT (src, " bandwidth: '%u'", bw->bandwidth);
9967 GST_LOG_OBJECT (src, " key:");
9968 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (media->key.type));
9969 GST_LOG_OBJECT (src, " data: '%s'", GST_STR_NULL (media->key.data));
9970 if (media->attributes && media->attributes->len > 0) {
9973 GST_LOG_OBJECT (src, " attributes:");
9974 for (i = 0; i < media->attributes->len; i++) {
9975 GstSDPAttribute *attr =
9976 &g_array_index (media->attributes, GstSDPAttribute, i);
9978 GST_LOG_OBJECT (src, " attribute '%s' : '%s'", attr->key, attr->value);
9984 gst_rtspsrc_print_sdp_message (GstRTSPSrc * src, const GstSDPMessage * msg)
9986 g_return_if_fail (src != NULL);
9987 g_return_if_fail (msg != NULL);
9989 if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) < GST_LEVEL_LOG)
9992 GST_LOG_OBJECT (src, "--------------------------------------------");
9993 GST_LOG_OBJECT (src, "sdp packet %p:", msg);
9994 GST_LOG_OBJECT (src, " version: '%s'", GST_STR_NULL (msg->version));
9995 GST_LOG_OBJECT (src, " origin:");
9996 GST_LOG_OBJECT (src, " username: '%s'",
9997 GST_STR_NULL (msg->origin.username));
9998 GST_LOG_OBJECT (src, " sess_id: '%s'",
9999 GST_STR_NULL (msg->origin.sess_id));
10000 GST_LOG_OBJECT (src, " sess_version: '%s'",
10001 GST_STR_NULL (msg->origin.sess_version));
10002 GST_LOG_OBJECT (src, " nettype: '%s'",
10003 GST_STR_NULL (msg->origin.nettype));
10004 GST_LOG_OBJECT (src, " addrtype: '%s'",
10005 GST_STR_NULL (msg->origin.addrtype));
10006 GST_LOG_OBJECT (src, " addr: '%s'", GST_STR_NULL (msg->origin.addr));
10007 GST_LOG_OBJECT (src, " session_name: '%s'",
10008 GST_STR_NULL (msg->session_name));
10009 GST_LOG_OBJECT (src, " information: '%s'", GST_STR_NULL (msg->information));
10010 GST_LOG_OBJECT (src, " uri: '%s'", GST_STR_NULL (msg->uri));
10012 if (msg->emails && msg->emails->len > 0) {
10015 GST_LOG_OBJECT (src, " emails:");
10016 for (i = 0; i < msg->emails->len; i++) {
10017 GST_LOG_OBJECT (src, " email '%s'", g_array_index (msg->emails, gchar *,
10021 if (msg->phones && msg->phones->len > 0) {
10024 GST_LOG_OBJECT (src, " phones:");
10025 for (i = 0; i < msg->phones->len; i++) {
10026 GST_LOG_OBJECT (src, " phone '%s'", g_array_index (msg->phones, gchar *,
10030 GST_LOG_OBJECT (src, " connection:");
10031 GST_LOG_OBJECT (src, " nettype: '%s'",
10032 GST_STR_NULL (msg->connection.nettype));
10033 GST_LOG_OBJECT (src, " addrtype: '%s'",
10034 GST_STR_NULL (msg->connection.addrtype));
10035 GST_LOG_OBJECT (src, " address: '%s'",
10036 GST_STR_NULL (msg->connection.address));
10037 GST_LOG_OBJECT (src, " ttl: '%u'", msg->connection.ttl);
10038 GST_LOG_OBJECT (src, " addr_number: '%u'", msg->connection.addr_number);
10039 if (msg->bandwidths && msg->bandwidths->len > 0) {
10042 GST_LOG_OBJECT (src, " bandwidths:");
10043 for (i = 0; i < msg->bandwidths->len; i++) {
10044 GstSDPBandwidth *bw =
10045 &g_array_index (msg->bandwidths, GstSDPBandwidth, i);
10047 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (bw->bwtype));
10048 GST_LOG_OBJECT (src, " bandwidth: '%u'", bw->bandwidth);
10051 GST_LOG_OBJECT (src, " key:");
10052 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (msg->key.type));
10053 GST_LOG_OBJECT (src, " data: '%s'", GST_STR_NULL (msg->key.data));
10054 if (msg->attributes && msg->attributes->len > 0) {
10057 GST_LOG_OBJECT (src, " attributes:");
10058 for (i = 0; i < msg->attributes->len; i++) {
10059 GstSDPAttribute *attr =
10060 &g_array_index (msg->attributes, GstSDPAttribute, i);
10062 GST_LOG_OBJECT (src, " attribute '%s' : '%s'", attr->key, attr->value);
10065 if (msg->medias && msg->medias->len > 0) {
10068 GST_LOG_OBJECT (src, " medias:");
10069 for (i = 0; i < msg->medias->len; i++) {
10070 GST_LOG_OBJECT (src, " media %u:", i);
10071 gst_rtspsrc_print_sdp_media (src, &g_array_index (msg->medias,
10075 GST_LOG_OBJECT (src, "--------------------------------------------");