[vlc-devel] [PATCH 1/2] demux: wav: refactor function ChunkGetNext

Zhao, Gang gang.zhao.42 at gmail.com
Tue Sep 15 16:26:38 CEST 2020


Prepare for parsing INFO chunk.

Signed-off-by: Zhao, Gang <gang.zhao.42 at gmail.com>
---
 modules/demux/wav.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git modules/demux/wav.c modules/demux/wav.c
index 4b0623412f..52f9639ef9 100644
--- modules/demux/wav.c
+++ modules/demux/wav.c
@@ -66,11 +66,13 @@ enum wav_chunk_id {
     wav_chunk_id_fmt,
 };
 
-static const struct wav_chunk_id_key
+struct wav_chunk_id_key
 {
     enum wav_chunk_id id;
     char key[5];
-} wav_chunk_id_key_list[] =  {
+};
+
+static const struct wav_chunk_id_key wav_chunk_id_key_list[] =  {
     /* Alphabetical order */
     { wav_chunk_id_data, "data" },
     { wav_chunk_id_ds64, "ds64" },
@@ -190,13 +192,14 @@ static int ChunkSkip( demux_t *p_demux, uint32_t i_size )
 }
 
 static int ChunkGetNext( demux_t *p_demux, enum wav_chunk_id *p_id,
-                         uint32_t *pi_size )
+                         uint32_t *pi_size,
+                         const struct wav_chunk_id_key *id_key_list, size_t count )
 {
 #ifndef NDEBUG
     /* assert that keys are in alphabetical order */
-    for( size_t i = 0; i < wav_chunk_id_key_count - 1; ++i )
-        assert( strcmp( wav_chunk_id_key_list[i].key,
-                        wav_chunk_id_key_list[i + 1].key ) < 0 );
+    for( size_t i = 0; i < count - 1; ++i )
+        assert( strcmp( id_key_list[i].key,
+                        id_key_list[i + 1].key ) < 0 );
 #endif
 
     for( ;; )
@@ -206,8 +209,8 @@ static int ChunkGetNext( demux_t *p_demux, enum wav_chunk_id *p_id,
             return VLC_EGENERIC;
 
         const struct wav_chunk_id_key *id =
-            bsearch( p_peek, wav_chunk_id_key_list, wav_chunk_id_key_count,
-                     sizeof(*wav_chunk_id_key_list), wav_chunk_CompareCb );
+            bsearch( p_peek, id_key_list, count,
+                     sizeof(*id_key_list), wav_chunk_CompareCb );
         uint32_t i_size = GetDWLE( p_peek + 4 );
 
         if( id == NULL )
@@ -629,8 +632,13 @@ static int Open( vlc_object_t * p_this )
 
     bool eof = false;
     enum wav_chunk_id id;
-    while( !eof && ( ChunkGetNext( p_demux, &id, &i_size ) ) == VLC_SUCCESS )
+    while( !eof )
     {
+        int ret = ChunkGetNext( p_demux, &id, &i_size,
+                                wav_chunk_id_key_list, wav_chunk_id_key_count );
+        if (ret != VLC_SUCCESS )
+            break;
+
         if( i_size == 0 )
         {
             msg_Err( p_demux, "invalid chunk with a size 0");
-- 
2.25.1



More information about the vlc-devel mailing list