*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* <refsect2>
* <title>Example launch line</title>
* |[
- * gst-launch rtspsrc location=rtsp://some.server/url ! fakesink
+ * gst-launch-1.0 rtspsrc location=rtsp://some.server/url ! fakesink
* ]| Establish a connection to an RTSP server and send the raw RTP packets to a
* fakesink.
* </refsect2>
#endif /* HAVE_UNISTD_H */
#include <stdlib.h>
#include <string.h>
-#include <locale.h>
#include <stdio.h>
#include <stdarg.h>
#define DEFAULT_UDP_BUFFER_SIZE 0x80000
#define DEFAULT_TCP_TIMEOUT 20000000
#define DEFAULT_LATENCY_MS 2000
+#define DEFAULT_DROP_ON_LATENCY FALSE
#define DEFAULT_CONNECTION_SPEED 0
#define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY
#define DEFAULT_DO_RTCP TRUE
#define DEFAULT_BUFFER_MODE BUFFER_MODE_AUTO
#define DEFAULT_PORT_RANGE NULL
#define DEFAULT_SHORT_HEADER FALSE
+#define DEFAULT_PROBATION 2
+#define DEFAULT_UDP_RECONNECT TRUE
enum
{
PROP_TIMEOUT,
PROP_TCP_TIMEOUT,
PROP_LATENCY,
+ PROP_DROP_ON_LATENCY,
PROP_CONNECTION_SPEED,
PROP_NAT_METHOD,
PROP_DO_RTCP,
PROP_PORT_RANGE,
PROP_UDP_BUFFER_SIZE,
PROP_SHORT_HEADER,
+ PROP_PROBATION,
+ PROP_UDP_RECONNECT,
PROP_LAST
};
static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
const gchar * uri, GError ** error);
+static gchar *gst_rtspsrc_uri_get_uri (GstURIHandler * handler);
static gboolean gst_rtspsrc_activate_streams (GstRTSPSrc * src);
static gboolean gst_rtspsrc_loop (GstRTSPSrc * src);
"Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
+ g_param_spec_boolean ("drop-on-latency",
+ "Drop buffers when maximum latency is reached",
+ "Tells the jitterbuffer to never exceed the given latency in size",
+ DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
g_param_spec_uint64 ("connection-speed", "Connection Speed",
"Network connection speed in kbps (0 = unknown)",
"Only send the basic RTSP headers for broken encoders",
DEFAULT_SHORT_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_PROBATION,
+ g_param_spec_uint ("probation", "Number of probations",
+ "Consecutive packet sequence numbers to accept the source",
+ 0, G_MAXUINT, DEFAULT_PROBATION,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_UDP_RECONNECT,
+ g_param_spec_boolean ("udp-reconnect", "Reconnect to the server",
+ "Reconnect to the server if RTSP connection is closed when doing UDP",
+ DEFAULT_UDP_RECONNECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
gstelement_class->send_event = gst_rtspsrc_send_event;
gstelement_class->change_state = gst_rtspsrc_change_state;
src->udp_timeout = DEFAULT_TIMEOUT;
gst_rtspsrc_set_tcp_timeout (src, DEFAULT_TCP_TIMEOUT);
src->latency = DEFAULT_LATENCY_MS;
+ src->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
src->connection_speed = DEFAULT_CONNECTION_SPEED;
src->nat_method = DEFAULT_NAT_METHOD;
src->do_rtcp = DEFAULT_DO_RTCP;
src->client_port_range.max = 0;
src->udp_buffer_size = DEFAULT_UDP_BUFFER_SIZE;
src->short_header = DEFAULT_SHORT_HEADER;
+ src->probation = DEFAULT_PROBATION;
+ src->udp_reconnect = DEFAULT_UDP_RECONNECT;
/* get a list of all extensions */
src->extensions = gst_rtsp_ext_list_get ();
case PROP_LATENCY:
rtspsrc->latency = g_value_get_uint (value);
break;
+ case PROP_DROP_ON_LATENCY:
+ rtspsrc->drop_on_latency = g_value_get_boolean (value);
+ break;
case PROP_CONNECTION_SPEED:
rtspsrc->connection_speed = g_value_get_uint64 (value);
break;
case PROP_SHORT_HEADER:
rtspsrc->short_header = g_value_get_boolean (value);
break;
+ case PROP_PROBATION:
+ rtspsrc->probation = g_value_get_uint (value);
+ break;
+ case PROP_UDP_RECONNECT:
+ rtspsrc->udp_reconnect = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_LATENCY:
g_value_set_uint (value, rtspsrc->latency);
break;
+ case PROP_DROP_ON_LATENCY:
+ g_value_set_boolean (value, rtspsrc->drop_on_latency);
+ break;
case PROP_CONNECTION_SPEED:
g_value_set_uint64 (value, rtspsrc->connection_speed);
break;
case PROP_SHORT_HEADER:
g_value_set_boolean (value, rtspsrc->short_header);
break;
+ case PROP_PROBATION:
+ g_value_set_uint (value, rtspsrc->probation);
+ break;
+ case PROP_UDP_RECONNECT:
+ g_value_set_boolean (value, rtspsrc->udp_reconnect);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
gst_sdp_message_free (src->sdp);
src->sdp = NULL;
}
+ if (src->start_segment) {
+ gst_event_unref (src->start_segment);
+ src->start_segment = NULL;
+ }
}
#define PARSE_INT(p, del, res) \
GST_DEBUG_OBJECT (src, "free RTP udpsrc");
gst_element_set_state (udpsrc0, GST_STATE_NULL);
gst_object_unref (udpsrc0);
+ udpsrc0 = NULL;
GST_DEBUG_OBJECT (src, "retry %d", count);
goto again;
GST_DEBUG_OBJECT (src, "free RTP udpsrc");
gst_element_set_state (udpsrc0, GST_STATE_NULL);
gst_object_unref (udpsrc0);
+ udpsrc0 = NULL;
GST_DEBUG_OBJECT (src, "retry %d", count);
tmp_rtp++;
/* set port */
tmp_rtcp = tmp_rtp + 1;
- if (src->client_port_range.max > 0 && tmp_rtcp >= src->client_port_range.max)
+ if (src->client_port_range.max > 0 && tmp_rtcp > src->client_port_range.max)
goto no_ports;
g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, "reuse", FALSE, NULL);
GST_DEBUG_OBJECT (src, "free RTP udpsrc");
gst_element_set_state (udpsrc0, GST_STATE_NULL);
gst_object_unref (udpsrc0);
+ udpsrc0 = NULL;
GST_DEBUG_OBJECT (src, "free RTCP udpsrc");
gst_element_set_state (udpsrc1, GST_STATE_NULL);
GST_DEBUG_OBJECT (src, "Creating newsegment from %" G_GINT64_FORMAT
" to %" G_GINT64_FORMAT, src->segment.position, stop);
- /* store the newsegment event so it can be sent from the streaming thread. */
- if (src->start_segment)
- gst_event_unref (src->start_segment);
- src->start_segment = gst_event_new_segment (&src->segment);
-
/* mark discont */
GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
for (walk = src->streams; walk; walk = g_list_next (walk)) {
}
break;
}
+ case GST_QUERY_URI:
+ {
+ gchar *uri;
+
+ uri = gst_rtspsrc_uri_get_uri (GST_URI_HANDLER (src));
+ if (uri != NULL) {
+ gst_query_set_uri (query, uri);
+ g_free (uri);
+ res = TRUE;
+ }
+ break;
+ }
default:
{
GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad));
gchar *name;
GstPadTemplate *template;
gint id, ssrc, pt;
- GList *lstream;
+ GList *ostreams;
GstRTSPStream *stream;
gboolean all_added;
if (sscanf (name, "recv_rtp_src_%u_%u_%u", &id, &ssrc, &pt) != 3)
goto unknown_stream;
- GST_DEBUG_OBJECT (src, "stream: %u, SSRC %d, PT %d", id, ssrc, pt);
+ GST_DEBUG_OBJECT (src, "stream: %u, SSRC %08x, PT %d", id, ssrc, pt);
stream = find_stream (src, &id, (gpointer) find_stream_by_id);
if (stream == NULL)
goto unknown_stream;
- /* create a new pad we will use to stream to */
- template = gst_static_pad_template_get (&rtptemplate);
- stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
- gst_object_unref (template);
- g_free (name);
-
+ /* we'll add it later see below */
stream->added = TRUE;
- gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
- gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
- gst_pad_set_active (stream->srcpad, TRUE);
- gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
/* check if we added all streams */
all_added = TRUE;
- for (lstream = src->streams; lstream; lstream = g_list_next (lstream)) {
- stream = (GstRTSPStream *) lstream->data;
+ for (ostreams = src->streams; ostreams; ostreams = g_list_next (ostreams)) {
+ GstRTSPStream *ostream = (GstRTSPStream *) ostreams->data;
GST_DEBUG_OBJECT (src, "stream %p, container %d, disabled %d, added %d",
- stream, stream->container, stream->disabled, stream->added);
+ ostream, ostream->container, ostream->disabled, ostream->added);
/* a container stream only needs one pad added. Also disabled streams don't
* count */
- if (!stream->container && !stream->disabled && !stream->added) {
+ if (!ostream->container && !ostream->disabled && !ostream->added) {
all_added = FALSE;
break;
}
}
GST_RTSP_STATE_UNLOCK (src);
+ /* create a new pad we will use to stream to */
+ template = gst_static_pad_template_get (&rtptemplate);
+ stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
+ gst_object_unref (template);
+ g_free (name);
+
+ gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
+ gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
+ gst_pad_set_active (stream->srcpad, TRUE);
+ gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
+
if (all_added) {
GST_DEBUG_OBJECT (src, "We added all streams");
/* when we get here, all stream are added and we can fire the no-more-pads
g_object_set (src->manager, "latency", src->latency, NULL);
klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
+ if (g_object_class_find_property (klass, "drop-on-latency")) {
+ g_object_set (src->manager, "drop-on-latency", src->drop_on_latency,
+ NULL);
+ }
+
if (g_object_class_find_property (klass, "buffer-mode")) {
if (src->buffer_mode != BUFFER_MODE_AUTO) {
g_object_set (src->manager, "buffer-mode", src->buffer_mode, NULL);
g_object_set (rtpsession, "rtcp-rs-bandwidth", stream->rs_bandwidth,
NULL);
}
+
+ g_object_set (rtpsession, "probation", src->probation, NULL);
+
g_signal_connect (rtpsession, "on-bye-ssrc", (GCallback) on_bye_ssrc,
stream);
g_signal_connect (rtpsession, "on-bye-timeout", (GCallback) on_timeout,
for (i = 0; i < 2; i++) {
if (stream->udpsrc[i]) {
+ GST_DEBUG ("free UDP source %d for stream %p", i, stream);
gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
gst_object_unref (stream->udpsrc[i]);
stream->udpsrc[i] = NULL;
/* configure a timeout on the UDP port. When the timeout message is
* posted, we assume UDP transport is not possible. We reconnect using TCP
* if we can. */
- g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout", src->udp_timeout,
- NULL);
+ g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout",
+ src->udp_timeout * 1000, NULL);
/* get output pad of the UDP source. */
*outpad = gst_element_get_static_pad (stream->udpsrc[0], "src");
gboolean res = TRUE;
/* only streams that have a connection to the outside world */
- if (stream->srcpad == NULL)
+ if (stream->container || stream->disabled)
goto done;
if (stream->udpsrc[0]) {
gst_rtsp_conninfo_close (GstRTSPSrc * src, GstRTSPConnInfo * info,
gboolean free)
{
+ GST_RTSP_STATE_LOCK (src);
if (info->connected) {
GST_DEBUG_OBJECT (src, "closing connection...");
gst_rtsp_connection_close (info->connection);
gst_rtsp_connection_free (info->connection);
info->connection = NULL;
}
+ GST_RTSP_STATE_UNLOCK (src);
return GST_RTSP_OK;
}
GList *walk;
GST_DEBUG_OBJECT (src, "set flushing %d", flush);
+ GST_RTSP_STATE_LOCK (src);
if (src->conninfo.connection) {
GST_DEBUG_OBJECT (src, "connection flush");
gst_rtsp_connection_flush (src->conninfo.connection, flush);
if (stream->conninfo.connection)
gst_rtsp_connection_flush (stream->conninfo.connection, flush);
}
+ GST_RTSP_STATE_UNLOCK (src);
}
/* FIXME, handle server request, reply with OK, for now */
GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *buf;
gboolean is_rtcp, have_data;
+ GstEvent *event;
/* here we are only interested in data messages */
have_data = FALSE;
gst_rtspsrc_activate_streams (src);
src->need_activate = FALSE;
}
+ if ((event = src->start_segment) != NULL) {
+ src->start_segment = NULL;
+ gst_rtspsrc_push_event (src, event);
+ }
if (src->base_time == -1) {
/* Take current running_time. This timestamp will be put on
* see what happens. */
GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
("The server closed the connection."));
- if ((res =
- gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) < 0)
- goto connect_error;
-
+ if (src->udp_reconnect) {
+ if ((res =
+ gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) < 0)
+ goto connect_error;
+ } else {
+ goto server_eof;
+ }
continue;
case GST_RTSP_ENET:
GST_DEBUG_OBJECT (src, "An ethernet problem occured.");
GST_OBJECT_LOCK (src);
old = src->pending_cmd;
+ if (old == CMD_RECONNECT) {
+ GST_DEBUG_OBJECT (src, "ignore, we were reconnecting");
+ cmd = CMD_RECONNECT;
+ }
if (old != CMD_WAIT) {
src->pending_cmd = CMD_WAIT;
GST_OBJECT_UNLOCK (src);
("streaming task paused, reason %s (%d)", reason, ret));
gst_rtspsrc_push_event (src, gst_event_new_eos ());
}
+ gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_LOOP);
return FALSE;
}
}
{
switch (res) {
case GST_RTSP_EEOF:
- GST_WARNING_OBJECT (src, "server closed connection, doing reconnect");
- if (try == 0) {
+ GST_WARNING_OBJECT (src, "server closed connection");
+ if ((try == 0) && !src->interleaved && src->udp_reconnect) {
try++;
/* if reconnect succeeds, try again */
if ((res =
{
GstRTSPHeaderField field;
gchar *respoptions;
- gchar **options;
gint indx = 0;
- gint i;
/* reset supported methods */
src->methods = 0;
if (!respoptions)
break;
- /* If we get here, the server gave a list of supported methods, parse
- * them here. The string is like:
- *
- * OPTIONS, DESCRIBE, ANNOUNCE, PLAY, SETUP, ...
- */
- options = g_strsplit (respoptions, ",", 0);
-
- for (i = 0; options[i]; i++) {
- gchar *stripped;
- gint method;
-
- stripped = g_strstrip (options[i]);
- method = gst_rtsp_find_method (stripped);
-
- /* keep bitfield of supported methods */
- if (method != GST_RTSP_INVALID)
- src->methods |= method;
- }
- g_strfreev (options);
+ src->methods |= gst_rtsp_options_from_text (respoptions);
indx++;
}
if (add_udp_str)
g_string_append (result, "/UDP");
g_string_append (result, ";multicast");
+ if (src->next_port_num != 0) {
+ if (src->client_port_range.max > 0 &&
+ src->next_port_num >= src->client_port_range.max)
+ goto no_ports;
+
+ g_string_append_printf (result, ";client_port=%d-%d",
+ src->next_port_num, src->next_port_num + 1);
+ }
} else if (protocols & GST_RTSP_LOWER_TRANS_TCP) {
GST_DEBUG_OBJECT (src, "adding TCP");
/* ERRORS */
failed:
{
+ GST_ERROR ("extension gave error %d", res);
return res;
}
+no_ports:
+ {
+ GST_ERROR ("no more ports available");
+ return GST_RTSP_ERROR;
+ }
}
static GstRTSPResult
/* ERRORS */
failed:
{
+ GST_ERROR ("failed to allocate udp ports");
return GST_RTSP_ERROR;
}
}
/* only allow multicast for other streams */
GST_DEBUG_OBJECT (src, "stream %p as UDP multicast", stream);
protocols = GST_RTSP_LOWER_TRANS_UDP_MCAST;
+ /* if the server selected our ports, increment our counters so that
+ * we select a new port later */
+ if (src->next_port_num == transport.port.min &&
+ src->next_port_num + 1 == transport.port.max) {
+ src->next_port_num += 2;
+ }
break;
case GST_RTSP_LOWER_TRANS_UDP:
/* only allow unicast for other streams */
setup_failed:
{
GST_ERROR_OBJECT (src, "setup failed");
+ gst_rtspsrc_cleanup (src);
return res;
}
}
* only in async case, since receive elements may not have been affected
* by overall state change (e.g. not around yet),
* do not mess with state in sync case (e.g. seeking) */
- if (async)
- gst_element_set_state (GST_ELEMENT_CAST (src), GST_STATE_PLAYING);
+ if (async) {
+ /* state change might be happening in the application thread. A
+ * specific case is when chaging state to NULL where we will wait
+ * for this task to finish (gst_rtspsrc_stop). However this task
+ * will try to change the state to PLAYING causing a deadlock. */
+
+ /* make sure we are not in the middle of a state change. The
+ * state lock is a recursive lock so it's safe to lock twice from
+ * the same thread */
+ if (GST_STATE_TRYLOCK (src)) {
+ gst_element_set_state (GST_ELEMENT_CAST (src), GST_STATE_PLAYING);
+ GST_STATE_UNLOCK (src);
+ } else {
+ res = GST_RTSP_ERROR;
+ goto changing_state;
+ }
+ }
/* construct a control url */
if (src->control)
gst_rtsp_message_add_header (&request, GST_RTSP_HDR_RANGE, hval);
g_free (hval);
+
+ /* store the newsegment event so it can be sent from the streaming thread. */
+ if (src->start_segment)
+ gst_event_unref (src->start_segment);
+ src->start_segment = gst_event_new_segment (&src->segment);
}
if (segment->rate != 1.0) {
GST_DEBUG_OBJECT (src, "we were already PLAYING");
goto done;
}
+changing_state:
+ {
+ GST_DEBUG_OBJECT (src, "failed going to PLAYING, already changing state");
+ goto done;
+ }
create_request_failed:
{
gchar *str = gst_rtsp_strresult (res);
GST_OBJECT_LOCK (src);
cmd = src->pending_cmd;
- src->pending_cmd = CMD_WAIT;
+ if (cmd == CMD_RECONNECT || CMD_PLAY || cmd == CMD_LOOP)
+ src->pending_cmd = CMD_LOOP;
+ else
+ src->pending_cmd = CMD_WAIT;
GST_DEBUG_OBJECT (src, "got command %d", cmd);
/* we got the message command, so ensure communication is possible again */