[vlc-commits] nuv: use unsigned 64-bits file offsets

Rémi Denis-Courmont git at videolan.org
Sun Mar 3 10:25:07 CET 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  3 10:22:29 2019 +0200| [a49f0849aca0e08f6f07b1d76ec5e0ba05c9750a] | committer: Rémi Denis-Courmont

nuv: use unsigned 64-bits file offsets

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

 modules/demux/Makefile.am |  1 +
 modules/demux/nuv.c       | 74 +++++++++++++++++++++++++----------------------
 2 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 8ea2e01683..2ae21f99d0 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -80,6 +80,7 @@ libxa_plugin_la_SOURCES = demux/xa.c
 demux_LTLIBRARIES += libxa_plugin.la
 
 libnuv_plugin_la_SOURCES = demux/nuv.c
+libnuv_plugin_la_LIBADD = $(LIBM)
 demux_LTLIBRARIES += libnuv_plugin.la
 
 libnsc_plugin_la_SOURCES = demux/nsc.c
diff --git a/modules/demux/nuv.c b/modules/demux/nuv.c
index c0b947c161..4a43304c69 100644
--- a/modules/demux/nuv.c
+++ b/modules/demux/nuv.c
@@ -28,6 +28,8 @@
 # include "config.h"
 #endif
 
+#include <math.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_demux.h>
@@ -62,8 +64,7 @@ static int Control( demux_t *, int, va_list );
 typedef struct
 {
     vlc_tick_t i_time;
-    int64_t i_offset;
-
+    uint64_t i_offset;
 } demux_index_entry_t;
 
 typedef struct
@@ -80,9 +81,9 @@ static void demux_IndexClean( demux_index_t * );
 static void demux_IndexAppend( demux_index_t *,
                                int64_t i_time, int64_t i_offset );
 /* Convert a time into offset */
-static int64_t demux_IndexConvertTime( demux_index_t *, vlc_tick_t i_time );
+static uint64_t demux_IndexConvertTime(demux_index_t *, vlc_tick_t time);
 /* Find the nearest offset in the index */
-static int64_t demux_IndexFindOffset( demux_index_t *, int64_t i_offset );
+static uint64_t demux_IndexFindOffset(demux_index_t *, uint64_t offset);
 
 
 /* */
@@ -190,14 +191,14 @@ typedef struct
     int64_t i_total_frames;
     vlc_tick_t i_total_length;
     /* first frame position (used for calculating size without seektable) */
-    int i_first_frame_offset;
+    uint64_t i_first_frame_offset;
 } demux_sys_t;
 
 static int HeaderLoad( demux_t *, header_t *h );
 static int FrameHeaderLoad( demux_t *, frame_header_t *h );
 static int ExtendedHeaderLoad( demux_t *, extended_header_t *h );
 static int SeekTableLoad( demux_t *, demux_sys_t * );
-static int ControlSetPosition( demux_t *p_demux, int64_t i_pos, bool b_guess );
+static int ControlSetPosition(demux_t *demux, uint64_t offset, bool guess);
 
 /*****************************************************************************
  * Open: initializes ES structures
@@ -446,8 +447,7 @@ static int Demux( demux_t *p_demux )
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
     demux_sys_t *p_sys  = p_demux->p_sys;
-
-    double   f, *pf;
+    double *pf;
     int64_t i64;
 
     switch( i_query )
@@ -480,25 +480,30 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_SET_POSITION:
         {
-            int64_t i_pos;
-
-            f = va_arg( args, double );
+            double f = va_arg(args, double);
+            uint64_t offset;
 
             p_sys->i_pcr = -1;
 
             /* first try to see if we can seek based on time (== GET_LENGTH works) */
-            if( p_sys->i_total_length > 0 && ( i_pos = demux_IndexConvertTime( &p_sys->idx, p_sys->i_total_length * f ) ) > 0 )
-                return ControlSetPosition( p_demux, i_pos, false );
+            if (p_sys->i_total_length > 0) {
+                vlc_tick_t t = llround(p_sys->i_total_length * f);
 
-            /* if not search based on total stream size */
-            else if( ( i_pos = demux_IndexFindOffset( &p_sys->idx, stream_Size( p_demux->s ) * f ) ) >= 0 )
-                return ControlSetPosition( p_demux, i_pos, false );
-
-            else if( ( i_pos =  p_sys->i_first_frame_offset + ( stream_Size( p_demux->s ) - p_sys->i_first_frame_offset ) * f ) >= 0 )
-                return ControlSetPosition( p_demux, i_pos, true );
+                offset = demux_IndexConvertTime(&p_sys->idx, t);
+                if (offset != UINT64_C(-1))
+                    return ControlSetPosition(p_demux, offset, false);
+            }
 
-            else
-                return VLC_EGENERIC;
+            /* if not search based on total stream size */
+            offset = stream_Size(p_demux->s) * f;
+            offset = demux_IndexFindOffset(&p_sys->idx, offset);
+            if (offset != UINT64_C(-1))
+                return ControlSetPosition(p_demux, offset, false);
+
+            offset = p_sys->i_first_frame_offset
+                     + (uint64_t)((stream_Size(p_demux->s)
+                                   - p_sys->i_first_frame_offset) * f);
+            return ControlSetPosition(p_demux, offset, true);
         }
 
         case DEMUX_GET_TIME:
@@ -507,15 +512,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_SET_TIME:
         {
-            int64_t i_pos;
+            uint64_t i_pos;
 
             p_sys->i_pcr = -1;
 
             i_pos = demux_IndexConvertTime( &p_sys->idx, va_arg( args, vlc_tick_t ) );
-            if( i_pos < 0 )
-                return VLC_EGENERIC;
-            else
+            if (i_pos != UINT64_C(-1))
                 return ControlSetPosition( p_demux, i_pos, false );
+            return VLC_EGENERIC;
         }
 
         case DEMUX_GET_LENGTH:
@@ -558,23 +562,21 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
     }
 }
-static int ControlSetPosition( demux_t *p_demux, int64_t i_pos, bool b_guess )
+
+static int ControlSetPosition(demux_t *p_demux, uint64_t offset, bool b_guess)
 {
     demux_sys_t *p_sys  = p_demux->p_sys;
 
-    if( i_pos < 0 )
-        return VLC_EGENERIC;
-
     /* if we can seek in the stream */
     if( p_sys->b_seekable && !b_guess )
     {
-        if( vlc_stream_Seek( p_demux->s, i_pos ) )
+        if (vlc_stream_Seek(p_demux->s, offset))
             return VLC_EGENERIC;
     }
     else
     {
         /* forward seek */
-        if( i_pos > vlc_stream_Tell( p_demux->s ) )
+        if (offset > vlc_stream_Tell(p_demux->s))
         {
             msg_Dbg( p_demux, "unable to seek, skipping frames (slow)" );
         }
@@ -589,9 +591,9 @@ static int ControlSetPosition( demux_t *p_demux, int64_t i_pos, bool b_guess )
     for( ;; )
     {
         frame_header_t fh;
-        int64_t i_tell;
+        uint64_t i_tell;
 
-        if( ( i_tell = vlc_stream_Tell( p_demux->s ) ) >= i_pos )
+        if ((i_tell = vlc_stream_Tell(p_demux->s)) >= offset)
             break;
 
         if( FrameHeaderLoad( p_demux, &fh ) )
@@ -955,7 +957,9 @@ static void demux_IndexAppend( demux_index_t *p_idx,
 
     p_idx->i_idx++;
 }
-static int64_t demux_IndexConvertTime( demux_index_t *p_idx, vlc_tick_t i_time )
+
+static uint64_t demux_IndexConvertTime(demux_index_t *p_idx,
+                                       vlc_tick_t i_time)
 {
     int i_min = 0;
     int i_max = p_idx->i_idx-1;
@@ -995,7 +999,7 @@ static int64_t demux_IndexConvertTime( demux_index_t *p_idx, vlc_tick_t i_time )
 }
 
 
-static int64_t demux_IndexFindOffset( demux_index_t *p_idx, int64_t i_offset )
+static uint64_t demux_IndexFindOffset(demux_index_t *p_idx, uint64_t i_offset)
 {
     int i_min = 0;
     int i_max = p_idx->i_idx-1;



More information about the vlc-commits mailing list