]> git.sesse.net Git - vlc/blobdiff - modules/demux/vorbis.h
skins2: fix memory leak
[vlc] / modules / demux / vorbis.h
index e3c07bd8eaf2ced02b69dcf8bdb2833425ba77b5..2642c4b7934ccca0d84d84434de4eb3628b36edd 100644 (file)
@@ -1,28 +1,29 @@
 /*****************************************************************************
  * vorbis.h: Vorbis Comment parser
  *****************************************************************************
- * Copyright (C) 2008 the VideoLAN team
+ * Copyright (C) 2008 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include <vlc_charset.h>
 #include <vlc_strings.h>
+#include <vlc_input.h>
 
 static input_attachment_t* ParseFlacPicture( const uint8_t *p_data, int i_data, int i_attachments, int *i_type )
 {
@@ -70,12 +71,16 @@ error:
     return p_attachment;
 }
 
-static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_data, int i_data,
-        int *i_attachments, input_attachment_t ***attachments)
+static inline void vorbis_ParseComment( vlc_meta_t **pp_meta,
+        const uint8_t *p_data, int i_data,
+        int *i_attachments, input_attachment_t ***attachments,
+        int *i_seekpoint, seekpoint_t ***ppp_seekpoint )
 {
     int n;
     int i_comment;
     int i_attach = 0;
+    seekpoint_t *sk = NULL;
+
     if( i_data < 8 )
         return;
 
@@ -106,19 +111,21 @@ static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_d
     if( !p_meta )
         return;
 
-    bool hasTitle = false;
-    bool hasAlbum = false;
-    bool hasTrackNumber = false;
-    bool hasArtist = false;
-    bool hasCopyright = false;
-    bool hasDescription = false;
-    bool hasGenre = false;
-    bool hasDate = false;
-    bool hasPublisher = false;
+    /* */
+    bool hasTitle        = false;
+    bool hasAlbum        = false;
+    bool hasTrackNumber  = false;
+    bool hasTrackTotal   = false;
+    bool hasArtist       = false;
+    bool hasCopyright    = false;
+    bool hasDescription  = false;
+    bool hasGenre        = false;
+    bool hasDate         = false;
+    bool hasPublisher    = false;
 
     for( ; i_comment > 0; i_comment-- )
     {
-        char *psz;
+        char *psz_comment;
         if( i_data < 4 )
             break;
         n = GetDWLE(p_data); RM(4);
@@ -127,44 +134,50 @@ static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_d
         if( n <= 0 )
             continue;
 
-        psz = strndup( (const char*)p_data, n );
+        psz_comment = strndup( (const char*)p_data, n );
         RM(n);
 
-        EnsureUTF8( psz );
+        EnsureUTF8( psz_comment );
 
 #define IF_EXTRACT(txt,var) \
-    if( !strncasecmp(psz, txt, strlen(txt)) ) \
+    if( !strncasecmp(psz_comment, txt, strlen(txt)) ) \
     { \
         const char *oldval = vlc_meta_Get( p_meta, vlc_meta_ ## var ); \
         if( oldval && has##var) \
         { \
             char * newval; \
-            if( asprintf( &newval, "%s,%s", oldval, &psz[strlen(txt)] ) == -1 ) \
+            if( asprintf( &newval, "%s,%s", oldval, &psz_comment[strlen(txt)] ) == -1 ) \
                 newval = NULL; \
             vlc_meta_Set( p_meta, vlc_meta_ ## var, newval ); \
             free( newval ); \
         } \
         else \
-            vlc_meta_Set( p_meta, vlc_meta_ ## var, &psz[strlen(txt)] ); \
+            vlc_meta_Set( p_meta, vlc_meta_ ## var, &psz_comment[strlen(txt)] ); \
         has##var = true; \
     }
         IF_EXTRACT("TITLE=", Title )
         else IF_EXTRACT("ALBUM=", Album )
         else IF_EXTRACT("TRACKNUMBER=", TrackNumber )
+        else if( !strncasecmp(psz_comment, "TRACKTOTAL=", strlen("TRACKTOTAL=")))
+            vlc_meta_Set( p_meta, vlc_meta_TrackTotal, &psz_comment[strlen("TRACKTOTAL=")] );
+        else if( !strncasecmp(psz_comment, "TOTALTRACKS=", strlen("TOTALTRACKS=")))
+            vlc_meta_Set( p_meta, vlc_meta_TrackTotal, &psz_comment[strlen("TOTALTRACKS=")] );
+        else IF_EXTRACT("TOTALTRACKS=", TrackTotal )
         else IF_EXTRACT("ARTIST=", Artist )
         else IF_EXTRACT("COPYRIGHT=", Copyright )
         else IF_EXTRACT("ORGANIZATION=", Publisher )
         else IF_EXTRACT("DESCRIPTION=", Description )
+        else IF_EXTRACT("COMMENTS=", Description )
         else IF_EXTRACT("GENRE=", Genre )
         else IF_EXTRACT("DATE=", Date )
-        else if( !strncasecmp( psz, "METADATA_BLOCK_PICTURE=", strlen("METADATA_BLOCK_PICTURE=")))
+        else if( !strncasecmp( psz_comment, "METADATA_BLOCK_PICTURE=", strlen("METADATA_BLOCK_PICTURE=")))
         {
             if( attachments == NULL )
                 continue;
 
             int i;
             uint8_t *p_picture;
-            size_t i_size = vlc_b64_decode_binary( &p_picture, &psz[strlen("METADATA_BLOCK_PICTURE=")]);
+            size_t i_size = vlc_b64_decode_binary( &p_picture, &psz_comment[strlen("METADATA_BLOCK_PICTURE=")]);
             input_attachment_t *p_attachment = ParseFlacPicture( p_picture, i_size, i_attach, &i );
             if( p_attachment )
             {
@@ -172,19 +185,46 @@ static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_d
                 snprintf( psz_url, sizeof(psz_url), "attachment://%s", p_attachment->psz_name );
                 vlc_meta_Set( p_meta, vlc_meta_ArtworkURL, psz_url );
                 i_attach++;
-                TAB_APPEND( *i_attachments, *attachments, p_attachment );
+                TAB_APPEND_CAST( (input_attachment_t**),
+                    *i_attachments, *attachments, p_attachment );
+            }
+        }
+        else if( !strncasecmp(psz_comment, "chapter", strlen("chapter")) )
+        {
+            if( ppp_seekpoint == NULL )
+                continue;
+
+            int i_chapt;
+            if( strstr( psz_comment, "name") && sscanf( psz_comment, "chapter%i=", &i_chapt ) == 1 )
+            {
+                char *p = strchr( psz_comment, '=' );
+                *p++ = '\0';
+                sk->psz_name = strdup( p );
+            }
+            else if( sscanf( psz_comment, "chapter %i=", &i_chapt ) == 1 )
+            {
+                int h, m, s, ms;
+                char *p = strchr( psz_comment, '=' );
+                *p++ = '\0';
+
+                if( sscanf( p, "%d:%d:%d.%d", &h, &m, &s, &ms ) == 4 )
+                {
+                    sk = vlc_seekpoint_New();
+                    sk->i_time_offset = ((h * 3600 + m * 60 + s) *1000 + ms) * 1000;
+                    TAB_APPEND_CAST( (seekpoint_t**), *i_seekpoint, *ppp_seekpoint, sk );
+                }
             }
         }
-        else if( strchr( psz, '=' ) )
+        else if( strchr( psz_comment, '=' ) )
         {
             /* generic (PERFORMER/LICENSE/ORGANIZATION/LOCATION/CONTACT/ISRC,
              * undocumented tags and replay gain ) */
-            char *p = strchr( psz, '=' );
+            char *p = strchr( psz_comment, '=' );
             *p++ = '\0';
-            vlc_meta_AddExtra( p_meta, psz, p );
+            vlc_meta_AddExtra( p_meta, psz_comment, p );
         }
 #undef IF_EXTRACT
-        free( psz );
+        free( psz_comment );
     }
 #undef RM
 }