From: <wt...@ke...> - 2007-05-18 11:39:33
|
CVS Root: /cvs/gstreamer Module: gst-plugins-good Changes by: wtay Date: Fri May 18 2007 11:39:25 UTC Log message: * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_class_init), (gst_rtspsrc_set_property), (gst_rtspsrc_get_property), (gst_rtspsrc_stream_configure_udp), (gst_rtspsrc_loop_interleaved), (gst_rtspsrc_loop_udp), (gst_rtspsrc_try_send), (gst_rtspsrc_send), (gst_rtspsrc_setup_streams), (gst_rtspsrc_open): * gst/rtsp/gstrtspsrc.h: Add TCP timeout property and use it for all TCP connection. * gst/rtsp/rtspconnection.c: (rtsp_connection_connect), (rtsp_connection_write), (rtsp_connection_next_timeout), (rtsp_connection_reset_timeout): Make connect and writes cancelable and make them use the timeout. Modified files: . : ChangeLog gst/rtsp : gstrtspsrc.c gstrtspsrc.h rtspconnection.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-good/ChangeLog.diff?r1=1.2932&r2=1.2933 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-good/gst/rtsp/gstrtspsrc.c.diff?r1=1.86&r2=1.87 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-good/gst/rtsp/gstrtspsrc.h.diff?r1=1.34&r2=1.35 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-good/gst/rtsp/rtspconnection.c.diff?r1=1.35&r2=1.36 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-plugins-good/ChangeLog,v retrieving revision 1.2932 retrieving revision 1.2933 diff -u -d -r1.2932 -r1.2933 --- ChangeLog 18 May 2007 10:36:12 -0000 1.2932 +++ ChangeLog 18 May 2007 11:39:11 -0000 1.2933 @@ -1,5 +1,20 @@ 2007-05-18 Wim Taymans <wi...@fl...> + * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_class_init), + (gst_rtspsrc_set_property), (gst_rtspsrc_get_property), + (gst_rtspsrc_stream_configure_udp), (gst_rtspsrc_loop_interleaved), + (gst_rtspsrc_loop_udp), (gst_rtspsrc_try_send), (gst_rtspsrc_send), + (gst_rtspsrc_setup_streams), (gst_rtspsrc_open): + * gst/rtsp/gstrtspsrc.h: + Add TCP timeout property and use it for all TCP connection. + + * gst/rtsp/rtspconnection.c: (rtsp_connection_connect), + (rtsp_connection_write), (rtsp_connection_next_timeout), + (rtsp_connection_reset_timeout): + Make connect and writes cancelable and make them use the timeout. +2007-05-18 Wim Taymans <wi...@fl...> * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_send_keep_alive), (gst_rtspsrc_loop_interleaved), (gst_rtspsrc_loop_udp), (gst_rtspsrc_try_send), (gst_rtspsrc_send), Index: gstrtspsrc.c RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtsp/gstrtspsrc.c,v retrieving revision 1.86 retrieving revision 1.87 diff -u -d -r1.86 -r1.87 --- gstrtspsrc.c 18 May 2007 10:36:12 -0000 1.86 +++ gstrtspsrc.c 18 May 2007 11:39:12 -0000 1.87 @@ -145,6 +145,7 @@ #define DEFAULT_DEBUG FALSE #define DEFAULT_RETRY 20 #define DEFAULT_TIMEOUT 5000000 +#define DEFAULT_TCP_TIMEOUT 20000000 #define DEFAULT_LATENCY_MS 3000 enum @@ -155,6 +156,7 @@ PROP_DEBUG, PROP_RETRY, PROP_TIMEOUT, + PROP_TCP_TIMEOUT, PROP_LATENCY, }; @@ -279,10 +281,16 @@ g_object_class_install_property (gobject_class, PROP_TIMEOUT, g_param_spec_uint64 ("timeout", "Timeout", - "Retry TCP transport after timeout microseconds (0 = disabled)", + "Retry TCP transport after UDP timeout microseconds (0 = disabled)", 0, G_MAXUINT64, DEFAULT_TIMEOUT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (gobject_class, PROP_TCP_TIMEOUT, + g_param_spec_uint64 ("tcp-timeout", "TCP Timeout", + "Fail after timeout microseconds on TCP connections (0 = disabled)", + 0, G_MAXUINT64, DEFAULT_TCP_TIMEOUT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_LATENCY, g_param_spec_uint ("latency", "Buffer latency in ms", "Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS, @@ -365,8 +373,16 @@ rtspsrc->retry = g_value_get_uint (value); break; case PROP_TIMEOUT: - rtspsrc->timeout = g_value_get_uint64 (value); + rtspsrc->udp_timeout = g_value_get_uint64 (value); + case PROP_TCP_TIMEOUT: + { + guint64 timeout = g_value_get_uint64 (value); + rtspsrc->tcp_timeout.tv_sec = timeout / G_USEC_PER_SEC; + rtspsrc->tcp_timeout.tv_usec = timeout % G_USEC_PER_SEC; + break; + } case PROP_LATENCY: rtspsrc->latency = g_value_get_uint (value); @@ -398,8 +414,17 @@ g_value_set_uint (value, rtspsrc->retry); - g_value_set_uint64 (value, rtspsrc->timeout); + g_value_set_uint64 (value, rtspsrc->udp_timeout); + guint64 timeout; + timeout = rtspsrc->tcp_timeout.tv_sec * G_USEC_PER_SEC + + rtspsrc->tcp_timeout.tv_usec; + g_value_set_uint64 (value, timeout); g_value_set_uint (value, rtspsrc->latency); @@ -1688,7 +1713,8 @@ /* 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->timeout, NULL); + g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout", src->udp_timeout, + NULL); /* get output pad of the UDP source. */ *outpad = gst_element_get_pad (stream->udpsrc[0], "src"); @@ -2137,7 +2163,7 @@ have_data = FALSE; do { - GTimeVal tv_timeout; + GTimeVal tv_timeout, *tv; /* get the next timeout interval */ rtsp_connection_next_timeout (src->connection, &tv_timeout); @@ -2149,9 +2175,14 @@ res = gst_rtspsrc_send_keep_alive (src); } + if ((src->tcp_timeout.tv_sec | src->tcp_timeout.tv_usec)) + tv = &src->tcp_timeout; + else + tv = NULL; GST_DEBUG_OBJECT (src, "doing receive"); - res = rtsp_connection_receive (src->connection, &message, NULL); + res = rtsp_connection_receive (src->connection, &message, tv); switch (res) { case RTSP_OK: @@ -2425,7 +2456,7 @@ GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL), ("Could not receive any UDP packets for %.4f seconds, maybe your " "firewall is blocking it. Retrying using a TCP connection.", - gst_guint64_to_gdouble (src->timeout / 1000000))); + gst_guint64_to_gdouble (src->udp_timeout / 1000000))); /* we can try only TCP now */ src->cur_protocols = RTSP_LOWER_TRANS_TCP; @@ -2685,6 +2716,7 @@ RTSPResult res; RTSPStatusCode thecode; gchar *content_base = NULL; + GTimeVal *tv; if (src->extension && src->extension->before_send) src->extension->before_send (src->extension, request); @@ -2694,13 +2726,18 @@ if (src->debug) rtsp_message_dump (request); - if ((res = rtsp_connection_send (src->connection, request, NULL)) < 0) + if ((src->tcp_timeout.tv_sec | src->tcp_timeout.tv_usec)) + tv = &src->tcp_timeout; + else + tv = NULL; + if ((res = rtsp_connection_send (src->connection, request, tv)) < 0) goto send_error; rtsp_connection_reset_timeout (src->connection); next: - if ((res = rtsp_connection_receive (src->connection, response, NULL)) < 0) + if ((res = rtsp_connection_receive (src->connection, response, tv)) < 0) goto receive_error; @@ -3338,7 +3375,7 @@ /* connect */ GST_DEBUG_OBJECT (src, "connecting (%s)...", src->req_location); - if ((res = rtsp_connection_connect (src->connection, NULL)) < 0) + if ((res = rtsp_connection_connect (src->connection, &src->tcp_timeout)) < 0) goto could_not_connect; /* create OPTIONS */ Index: gstrtspsrc.h RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtsp/gstrtspsrc.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- gstrtspsrc.h 12 May 2007 16:37:50 -0000 1.34 +++ gstrtspsrc.h 18 May 2007 11:39:12 -0000 1.35 @@ -147,7 +147,8 @@ RTSPLowerTrans protocols; gboolean debug; guint retry; - guint64 timeout; + guint64 udp_timeout; + GTimeVal tcp_timeout; guint latency; /* state */ Index: rtspconnection.c RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtsp/rtspconnection.c,v retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- rtspconnection.c 18 May 2007 10:36:12 -0000 1.35 +++ rtspconnection.c 18 May 2007 11:39:12 -0000 1.36 @@ -172,6 +172,10 @@ gint ret; guint16 port; RTSPUrl *url; + fd_set writefds; + fd_set readfds; + struct timeval tv, *tvp; + gint max_fd, retval; g_return_val_if_fail (conn != NULL, RTSP_EINVAL); g_return_val_if_fail (conn->url != NULL, RTSP_EINVAL); @@ -207,12 +211,42 @@ goto sys_error; /* set to non-blocking mode so that we can cancel the connect */ - //fcntl (fd, F_SETFL, O_NONBLOCK); + fcntl (fd, F_SETFL, O_NONBLOCK); + /* we are going to connect ASYNC now */ ret = connect (fd, (struct sockaddr *) &sin, sizeof (sin)); - if (ret != 0) + if (ret == 0) + goto done; + if (errno != EINPROGRESS) + goto sys_error; + /* wait for connect to complete up to the specified timeout or until we got + * interrupted. */ + FD_ZERO (&writefds); + FD_SET (fd, &writefds); + FD_ZERO (&readfds); + FD_SET (READ_SOCKET (conn), &readfds); + if (timeout->tv_sec != 0 || timeout->tv_usec != 0) { + tv.tv_sec = timeout->tv_sec; + tv.tv_usec = timeout->tv_usec; + tvp = &tv; + } else { + tvp = NULL; + } + max_fd = MAX (fd, READ_SOCKET (conn)); + do { + retval = select (max_fd + 1, &readfds, &writefds, NULL, tvp); + } while ((retval == -1 && errno == EINTR)); + if (retval == 0) + goto timeout; + else if (retval == -1) +done: conn->fd = fd; conn->ip = ip; @@ -232,6 +266,10 @@ { return RTSP_ENOTIP; } +timeout: + { + return RTSP_ETIMEOUT; } static void @@ -270,15 +308,61 @@ GTimeVal * timeout) { guint towrite; + int max_fd; + gint retval; g_return_val_if_fail (data != NULL || size == 0, RTSP_EINVAL); + FD_SET (conn->fd, &writefds); + max_fd = MAX (conn->fd, READ_SOCKET (conn)); + if (timeout) { towrite = size; while (towrite > 0) { gint written; + do { + retval = select (max_fd + 1, &readfds, &writefds, NULL, tvp); + } while ((retval == -1 && errno == EINTR)); + if (retval == 0) + goto timeout; + if (retval == -1) + goto select_error; + if (FD_ISSET (READ_SOCKET (conn), &readfds)) { + /* read all stop commands */ + while (TRUE) { + gchar command; + int res; + READ_COMMAND (conn, command, res); + if (res <= 0) { + /* no more commands */ + break; + } + } + goto stopped; + /* now we can write */ written = write (conn->fd, data, towrite); if (written < 0) { if (errno != EAGAIN && errno != EINTR) @@ -291,6 +375,18 @@ return RTSP_OK; /* ERRORS */ +select_error: + return RTSP_ESYS; +stopped: + return RTSP_EINTR; write_error: return RTSP_ESYS; |