[vlc-commits] demux: wav: move fmt parsing in a new function

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


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Mar 11 17:10:55 2020 +0100| [8d23f7427420f77526311fee6770bb06e8543594] | committer: Thomas Guillem

demux: wav: move fmt parsing in a new function

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

 modules/demux/wav.c | 150 ++++++++++++++++++++++++++++------------------------
 1 file changed, 81 insertions(+), 69 deletions(-)

diff --git a/modules/demux/wav.c b/modules/demux/wav.c
index 64be5b08fa..de39684422 100644
--- a/modules/demux/wav.c
+++ b/modules/demux/wav.c
@@ -256,78 +256,14 @@ static void Close ( vlc_object_t * p_this )
     free( p_sys );
 }
 
-static int Open( vlc_object_t * p_this )
+static int ChunkParseFmt( demux_t *p_demux, uint32_t i_size )
 {
-    demux_t     *p_demux = (demux_t*)p_this;
-    demux_sys_t *p_sys;
-
-    const uint8_t *p_peek;
-    bool           b_is_rf64;
-    unsigned int   i_size;
-    uint64_t       i_data_size;
-    unsigned int   i_extended;
-    const char    *psz_name;
-
+    demux_sys_t *p_sys = p_demux->p_sys;
     WAVEFORMATEXTENSIBLE *p_wf_ext = NULL;
     WAVEFORMATEX         *p_wf = NULL;
+    const char *psz_name;
+    unsigned int i_extended;
 
-    /* Is it a wav file ? */
-    if( vlc_stream_Peek( p_demux->s, &p_peek, 12 ) < 12 )
-        return VLC_EGENERIC;
-
-    b_is_rf64 = ( memcmp( p_peek, "RF64", 4 ) == 0 );
-    if( ( !b_is_rf64 && memcmp( p_peek, "RIFF", 4 ) ) ||
-          memcmp( &p_peek[8], "WAVE", 4 ) )
-    {
-        return VLC_EGENERIC;
-    }
-
-    p_demux->pf_demux     = Demux;
-    p_demux->pf_control   = Control;
-    p_demux->p_sys        = p_sys = malloc( sizeof( *p_sys ) );
-    if( unlikely(!p_sys) )
-        return VLC_ENOMEM;
-
-    es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );
-    p_sys->p_es           = NULL;
-    p_sys->i_data_size    = 0;
-    p_sys->i_chans_to_reorder = 0;
-    p_sys->i_channel_mask = 0;
-
-    /* skip riff header */
-    if( vlc_stream_Read( p_demux->s, NULL, 12 ) != 12 )
-        goto error;
-
-    if( b_is_rf64 )
-    {
-        /* search datasize64 chunk */
-        if( ChunkFind( p_demux, "ds64", &i_size ) )
-        {
-            msg_Err( p_demux, "cannot find 'ds64' chunk" );
-            goto error;
-        }
-        if( i_size < 24 )
-        {
-            msg_Err( p_demux, "invalid 'ds64' chunk" );
-            goto error;
-        }
-        if( vlc_stream_Peek( p_demux->s, &p_peek, 24 ) < 24 )
-            goto error;
-        i_data_size = GetQWLE( &p_peek[8] );
-        if( i_data_size >> 62 )
-            p_sys->i_data_size = (int64_t)1 << 62;
-        else
-            p_sys->i_data_size = i_data_size;
-        if( ChunkSkip( p_demux, i_size ) != VLC_SUCCESS )
-            goto error;
-    }
-
-    /* search fmt chunk */
-    if( ChunkFind( p_demux, "fmt ", &i_size ) )
-    {
-        msg_Err( p_demux, "cannot find 'fmt ' chunk" );
-        goto error;
-    }
     i_size += 2;
     if( i_size < sizeof( WAVEFORMATEX ) )
     {
@@ -565,6 +501,83 @@ static int Open( vlc_object_t * p_this )
 
     msg_Dbg( p_demux, "found %s audio format", psz_name );
 
+    return VLC_SUCCESS;
+
+error:
+    free( p_wf );
+    return VLC_EGENERIC;
+}
+
+static int Open( vlc_object_t * p_this )
+{
+    demux_t     *p_demux = (demux_t*)p_this;
+    demux_sys_t *p_sys;
+
+    const uint8_t *p_peek;
+    bool           b_is_rf64;
+    unsigned int   i_size;
+    uint64_t       i_data_size;
+
+    /* Is it a wav file ? */
+    if( vlc_stream_Peek( p_demux->s, &p_peek, 12 ) < 12 )
+        return VLC_EGENERIC;
+
+    b_is_rf64 = ( memcmp( p_peek, "RF64", 4 ) == 0 );
+    if( ( !b_is_rf64 && memcmp( p_peek, "RIFF", 4 ) ) ||
+          memcmp( &p_peek[8], "WAVE", 4 ) )
+    {
+        return VLC_EGENERIC;
+    }
+
+    p_demux->pf_demux     = Demux;
+    p_demux->pf_control   = Control;
+    p_demux->p_sys        = p_sys = malloc( sizeof( *p_sys ) );
+    if( unlikely(!p_sys) )
+        return VLC_ENOMEM;
+
+    es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );
+    p_sys->p_es           = NULL;
+    p_sys->i_data_size    = 0;
+    p_sys->i_chans_to_reorder = 0;
+    p_sys->i_channel_mask = 0;
+
+    /* skip riff header */
+    if( vlc_stream_Read( p_demux->s, NULL, 12 ) != 12 )
+        goto error;
+
+    if( b_is_rf64 )
+    {
+        /* search datasize64 chunk */
+        if( ChunkFind( p_demux, "ds64", &i_size ) )
+        {
+            msg_Err( p_demux, "cannot find 'ds64' chunk" );
+            goto error;
+        }
+        if( i_size < 24 )
+        {
+            msg_Err( p_demux, "invalid 'ds64' chunk" );
+            goto error;
+        }
+        if( vlc_stream_Peek( p_demux->s, &p_peek, 24 ) < 24 )
+            goto error;
+        i_data_size = GetQWLE( &p_peek[8] );
+        if( i_data_size >> 62 )
+            p_sys->i_data_size = (int64_t)1 << 62;
+        else
+            p_sys->i_data_size = i_data_size;
+        if( ChunkSkip( p_demux, i_size ) != VLC_SUCCESS )
+            goto error;
+    }
+
+    /* search fmt chunk */
+    if( ChunkFind( p_demux, "fmt ", &i_size ) )
+    {
+        msg_Err( p_demux, "cannot find 'fmt ' chunk" );
+        goto error;
+    }
+    if( ChunkParseFmt( p_demux, i_size ) != VLC_SUCCESS )
+        goto error;
+
     if( ChunkFind( p_demux, "data", &i_size ) )
     {
         msg_Err( p_demux, "cannot find 'data' chunk" );
@@ -598,7 +611,6 @@ static int Open( vlc_object_t * p_this )
 
 error:
     msg_Err( p_demux, "An error occurred during wav demuxing" );
-    free( p_wf );
     es_format_Clean( &p_sys->fmt );
     free( p_sys );
     return VLC_EGENERIC;



More information about the vlc-commits mailing list