[vlc-commits] demux: wav: refactor chunk skip

Thomas Guillem git at videolan.org
Mon Mar 16 13:31:28 CET 2020


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Mar  3 09:25:38 2020 +0100| [fd15e5a03f87f67c5202c6322677e394c690a1e6] | committer: Thomas Guillem

demux: wav: refactor chunk skip

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

 modules/demux/wav.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/modules/demux/wav.c b/modules/demux/wav.c
index c68f5e916e..0b78d775fc 100644
--- a/modules/demux/wav.c
+++ b/modules/demux/wav.c
@@ -29,6 +29,7 @@
 #endif
 
 #include <assert.h>
+#include <limits.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
@@ -116,6 +117,24 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                                    i_query, args );
 }
 
+static int ChunkSkip( demux_t *p_demux, uint32_t i_size )
+{
+    i_size += i_size & 1;
+
+    if( unlikely( i_size >= 65536 ) )
+    {
+        /* Arbitrary size where a seek should be performed instead of skipping
+         * by reading NULL. Non data chunks are generally smaller than this.
+         * This seek may be used to skip the data chunk if there is an other
+         * chunk after it (unlikely). */
+        return vlc_stream_Seek( p_demux->s,
+                                vlc_stream_Tell( p_demux->s ) + i_size );
+    }
+
+    ssize_t i_ret = vlc_stream_Read( p_demux->s, NULL, i_size );
+    return i_ret < 0 || (size_t) i_ret != i_size ? VLC_EGENERIC : VLC_SUCCESS;
+}
+
 static int ChunkFind( demux_t *p_demux, const char *fcc, unsigned int *pi_size )
 {
     const uint8_t *p_peek;
@@ -143,10 +162,7 @@ static int ChunkFind( demux_t *p_demux, const char *fcc, unsigned int *pi_size )
             return VLC_SUCCESS;
         }
 
-        /* Skip chunk */
-        if( vlc_stream_Read( p_demux->s, NULL, 8 ) != 8 ||
-            vlc_stream_Read( p_demux->s, NULL, i_size ) != (int)i_size ||
-            ( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
+        if( ChunkSkip( p_demux, i_size + 8 ) != VLC_SUCCESS )
             return VLC_EGENERIC;
     }
 }
@@ -302,8 +318,7 @@ static int Open( vlc_object_t * p_this )
             p_sys->i_data_size = (int64_t)1 << 62;
         else
             p_sys->i_data_size = i_data_size;
-        if( vlc_stream_Read( p_demux->s, NULL, i_size ) != (int)i_size ||
-            ( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
+        if( ChunkSkip( p_demux, i_size ) != VLC_SUCCESS )
             goto error;
     }
 



More information about the vlc-commits mailing list