]> git.sesse.net Git - vlc/commitdiff
Split FLAC picture parsing from flac.c
authorJean-Baptiste Kempf <jb@videolan.org>
Thu, 5 Apr 2012 15:25:18 +0000 (17:25 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Thu, 5 Apr 2012 19:41:56 +0000 (21:41 +0200)
modules/demux/flac.c
modules/demux/vorbis.h

index 5434dd0cab1aff17fc779273890c222622b88973..d7da7aa9e07fcfaba71c5aaddc32168834388886 100644 (file)
@@ -572,7 +572,6 @@ static void ParseSeekTable( demux_t *p_demux, const uint8_t *p_data, int i_data,
     /* TODO sort it by size and remove wrong seek entry (time not increasing) */
 }
 
-#define RM(x) do { i_data -= (x); p_data += (x); } while(0)
 static void ParseComment( demux_t *p_demux, const uint8_t *p_data, int i_data )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
@@ -600,43 +599,13 @@ static void ParsePicture( demux_t *p_demux, const uint8_t *p_data, int i_data )
     };
     demux_sys_t *p_sys = p_demux->p_sys;
     int i_type;
-    int i_len;
-    char *psz_mime = NULL;
-    char *psz_description = NULL;
-    input_attachment_t *p_attachment;
-    char psz_name[128];
 
-    if( i_data < 4 + 3*4 )
+    i_data -= 4; p_data += 4;
+
+    input_attachment_t *p_attachment = ParseFlacPicture( p_data, i_data, p_sys->i_attachments, &i_type );
+    if( p_attachment == NULL )
         return;
-#define RM(x) do { i_data -= (x); p_data += (x); } while(0)
-    RM(4);
-
-    i_type = GetDWBE( p_data ); RM(4);
-    i_len = GetDWBE( p_data ); RM(4);
-    if( i_len < 0 || i_data < i_len + 4 )
-        goto error;
-    psz_mime = strndup( (const char*)p_data, i_len ); RM(i_len);
-    i_len = GetDWBE( p_data ); RM(4);
-    if( i_len < 0 || i_data < i_len + 4*4 + 4)
-        goto error;
-    psz_description = strndup( (const char*)p_data, i_len ); RM(i_len);
-    EnsureUTF8( psz_description );
-    RM(4*4);
-    i_len = GetDWBE( p_data ); RM(4);
-    if( i_len < 0 || i_len > i_data )
-        goto error;
-
-    msg_Dbg( p_demux, "Picture type=%d mime=%s description='%s' file length=%d",
-             i_type, psz_mime, psz_description, i_len );
-
-    snprintf( psz_name, sizeof(psz_name), "picture%d", p_sys->i_attachments );
-    if( !strcasecmp( psz_mime, "image/jpeg" ) )
-        strcat( psz_name, ".jpg" );
-    else if( !strcasecmp( psz_mime, "image/png" ) )
-        strcat( psz_name, ".png" );
-
-    p_attachment = vlc_input_attachment_New( psz_name, psz_mime, psz_description,
-                                             p_data, i_data );
+
     TAB_APPEND( p_sys->i_attachments, p_sys->attachments, p_attachment );
 
     if( i_type >= 0 && (unsigned int)i_type < sizeof(pi_cover_score)/sizeof(pi_cover_score[0]) &&
@@ -645,9 +614,5 @@ static void ParsePicture( demux_t *p_demux, const uint8_t *p_data, int i_data )
         p_sys->i_cover_idx = p_sys->i_attachments-1;
         p_sys->i_cover_score = pi_cover_score[i_type];
     }
-error:
-    free( psz_mime );
-    free( psz_description );
 }
-#undef RM
 
index 0654083c7d22176fa7743349c28dc6887521a31d..9770e886177fa093b5c5f242c5889f681e03d19e 100644 (file)
 
 #include <vlc_charset.h>
 
+static input_attachment_t* ParseFlacPicture( const uint8_t *p_data, int i_data, int i_attachments, int *i_type )
+{
+    int i_len;
+    char *psz_mime = NULL;
+    char psz_name[128];
+    char *psz_description = NULL;
+    input_attachment_t *p_attachment = NULL;
+
+    if( i_data < 4 + 3*4 )
+        return NULL;
+#define RM(x) do { i_data -= (x); p_data += (x); } while(0)
+
+    *i_type = GetDWBE( p_data ); RM(4);
+    i_len = GetDWBE( p_data ); RM(4);
+
+    if( i_len < 0 || i_data < i_len + 4 )
+        goto error;
+    psz_mime = strndup( (const char*)p_data, i_len ); RM(i_len);
+    i_len = GetDWBE( p_data ); RM(4);
+    if( i_len < 0 || i_data < i_len + 4*4 + 4)
+        goto error;
+    psz_description = strndup( (const char*)p_data, i_len ); RM(i_len);
+    EnsureUTF8( psz_description );
+    RM(4*4);
+    i_len = GetDWBE( p_data ); RM(4);
+    if( i_len < 0 || i_len > i_data )
+        goto error;
+
+    /* printf( "Picture type=%d mime=%s description='%s' file length=%d\n",
+             *i_type, psz_mime, psz_description, i_len ); */
+
+    snprintf( psz_name, sizeof(psz_name), "picture%d", i_attachments );
+    if( !strcasecmp( psz_mime, "image/jpeg" ) )
+        strcat( psz_name, ".jpg" );
+    else if( !strcasecmp( psz_mime, "image/png" ) )
+        strcat( psz_name, ".png" );
+
+    p_attachment = vlc_input_attachment_New( psz_name, psz_mime,
+            psz_description, p_data, i_data );
+
+error:
+    free( psz_mime );
+    free( psz_description );
+    return p_attachment;
+}
+
 static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_data, int i_data )
 {
     int n;
@@ -30,7 +76,6 @@ static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_d
     if( i_data < 8 )
         return;
 
-#define RM(x) do { i_data -= (x); p_data += (x); } while(0)
     n = GetDWLE(p_data); RM(4);
     if( n < 0 || n > i_data )
         return;