[dvblast-devel] Handle correctly the poll timeout value, especially when negative ( may happen when in late)

Sebastien RAILLARD git at videolan.org
Mon Mar 30 00:00:21 CEST 2015


dvblast | branch: master | Sebastien RAILLARD <sr at coexsi.fr> | Wed Mar 25 21:40:04 2015 +0100| [df2c1b9fdce8bdf503e4902e8db187f3e0f43cde] | committer: Christophe Massiot

Handle correctly the poll timeout value, especially when negative (may happen when in late)

> http://git.videolan.org/gitweb.cgi/dvblast.git/?a=commit;h=df2c1b9fdce8bdf503e4902e8db187f3e0f43cde
---

 config.h  |    1 +
 dvblast.c |    2 --
 output.c  |   16 +++++++++++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/config.h b/config.h
index 112b7c7..249cbf5 100644
--- a/config.h
+++ b/config.h
@@ -44,6 +44,7 @@
 #define MAX_ERRORS 1000
 #define DEFAULT_VERBOSITY 4
 #define MAX_POLL_TIMEOUT 100000 /* 100 ms */
+#define MIN_POLL_TIMEOUT 100 /* 100 us */
 #define DEFAULT_OUTPUT_LATENCY 200000 /* 200 ms */
 #define DEFAULT_MAX_RETENTION 40000 /* 40 ms */
 #define MAX_EIT_RETENTION 500000 /* 500 ms */
diff --git a/dvblast.c b/dvblast.c
index ebd4992..8c20aed 100644
--- a/dvblast.c
+++ b/dvblast.c
@@ -1163,8 +1163,6 @@ int main( int i_argc, char **pp_argv )
             demux_Run( p_ts );
         }
         i_poll_timeout = output_Send();
-        if ( i_poll_timeout == -1 || i_poll_timeout > MAX_POLL_TIMEOUT )
-            i_poll_timeout = MAX_POLL_TIMEOUT;
     }
 
     mrtgClose();
diff --git a/output.c b/output.c
index 1605425..790ffb8 100644
--- a/output.c
+++ b/output.c
@@ -470,6 +470,7 @@ void output_Put( output_t *p_output, block_t *p_block )
 mtime_t output_Send( void )
 {
     mtime_t i_earliest_dts = -1;
+    mtime_t i_poll_timeout;
     int i;
 
     if ( output_dup.config.i_config & OUTPUT_VALID )
@@ -502,7 +503,20 @@ mtime_t output_Send( void )
                               + p_output->config.i_output_latency;
     }
 
-    return i_earliest_dts == -1 ? -1 : i_earliest_dts - i_wallclock;
+    /* Calculate the maximum time to wait before sending the next packet */
+    if ( i_earliest_dts == -1 ) {
+        return (MAX_POLL_TIMEOUT);
+    } else {
+        i_poll_timeout = i_earliest_dts - i_wallclock;
+        if (i_poll_timeout > MAX_POLL_TIMEOUT) {
+            return (MAX_POLL_TIMEOUT);
+        } else if (i_poll_timeout < MIN_POLL_TIMEOUT) {
+            return (MIN_POLL_TIMEOUT);
+        } else {
+            return (i_poll_timeout);
+        }
+    }
+
 }
 
 /*****************************************************************************



More information about the dvblast-devel mailing list