[vlc-devel] [PATCH] udp: add timeout parameter

Ilkka Ollakka ileoo at videolan.org
Tue Mar 15 17:16:00 CET 2016


By default we wait -1 as previously, but you can give --udp-timeout as timeout in seconds
how long we wait for next packet before deciding that input has ended.
---
 modules/access/udp.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/modules/access/udp.c b/modules/access/udp.c
index b243fce..84f7918 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -43,6 +43,9 @@
 #include <vlc_network.h>
 #include <vlc_block.h>
 #include <vlc_interrupt.h>
+#ifdef HAVE_POLL
+# include <poll.h>
+#endif
 #include <fcntl.h>
 
 /*****************************************************************************
@@ -53,6 +56,7 @@ static void Close( vlc_object_t * );
 
 #define BUFFER_TEXT N_("Receive buffer")
 #define BUFFER_LONGTEXT N_("UDP receive buffer size (bytes)" )
+#define TIMEOUT_TEXT N_("UDP Source timeout (sec)")
 
 vlc_module_begin ()
     set_shortname( N_("UDP" ) )
@@ -62,6 +66,9 @@ vlc_module_begin ()
 
     add_obsolete_integer( "server-port" ) /* since 2.0.0 */
     add_integer( "udp-buffer", 0x400000, BUFFER_TEXT, BUFFER_LONGTEXT, true )
+#ifdef HAVE_POLL
+    add_integer( "udp-timeout", -1, TIMEOUT_TEXT, NULL, true )
+#endif
 
     set_capability( "access", 0 )
     add_shortcut( "udp", "udpstream", "udp4", "udp6" )
@@ -72,6 +79,7 @@ vlc_module_end ()
 struct access_sys_t
 {
     int fd;
+    int timeout;
     size_t mtu;
     size_t fifo_size;
     block_fifo_t *fifo;
@@ -181,6 +189,12 @@ static int Open( vlc_object_t *p_this )
     sys->fifo_size = var_InheritInteger( p_access, "udp-buffer");
     vlc_sem_init( &sys->semaphore, 0 );
 
+#ifdef HAVE_POLL
+    sys->timeout = var_InheritInteger( p_access, "udp-timeout");
+    if( sys->timeout > 0)
+        sys->timeout *= 1000;
+#endif
+
     if( vlc_clone( &sys->thread, ThreadRead, p_access,
                    VLC_THREAD_PRIORITY_INPUT ) )
     {
@@ -291,9 +305,20 @@ static void* ThreadRead( void *data )
         block_cleanup_push(pkt);
         do
         {
-#ifndef LIBVLC_USE_PTHREAD
-            struct pollfd ufd = { .fd = sys->fd, .events = POLLIN };
-            while (poll(&ufd, 1, -1) <= 0); /* cancellation point */
+#ifdef HAVE_POLL
+            int poll_return=0;
+            struct pollfd ufd[1];
+            ufd[0].fd = sys->fd;
+            ufd[0].events = POLLIN;
+
+            while ((poll_return = poll(ufd, 1, sys->timeout)) < 0); /* cancellation point */
+            if (unlikely( poll_return == 0))
+            {
+                msg_Err( access, "Timeout on receiving, timeout %d seconds", sys->timeout/1000 );
+                access->info.b_eof=1;
+                len = 0;
+                break;
+            }
 #endif
             len = recvmsg(sys->fd, &msg, 0);
         }
-- 
2.6.2



More information about the vlc-devel mailing list