]> git.sesse.net Git - vlc/blobdiff - modules/meta_engine/id3tag.c
macosx: Fix controller playlist toggling to use the contentRect and not the window...
[vlc] / modules / meta_engine / id3tag.c
index c2a1c30862c33196fd52d3b0dbf4975e9a14822d..45d33fc0482ee94c0f33e4ecc04698bb0c5f18b7 100644 (file)
 #include <config.h>
 
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_demux.h>
 #include <vlc_playlist.h>
@@ -49,7 +54,7 @@ static int  ParseTags ( vlc_object_t * );
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("ID3v1/2 and APEv1/2 tags parser" ) );
+    set_description( N_("ID3v1/2 and APEv1/2 tags parser" ) );
     set_capability( "meta reader", 70 );
     set_callbacks( ParseTags, NULL );
 vlc_module_end();
@@ -57,22 +62,21 @@ vlc_module_end();
 /*****************************************************************************
  * ParseID3Tag : parse an id3tag into the info structures
  *****************************************************************************/
-static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size )
+static void ParseID3Tag( demux_t *p_demux, const uint8_t *p_data, int i_size )
 {
     struct id3_tag   *p_id3_tag;
     struct id3_frame *p_frame;
-    demux_meta_t     *p_demux_meta = p_demux->p_private;
+    demux_meta_t     *p_demux_meta = (demux_meta_t*)p_demux->p_private;
     vlc_meta_t       *p_meta;
     int i;
 
-    TAB_INIT( p_demux_meta->i_attachments, p_demux_meta->attachments );
-    p_demux_meta->p_meta = NULL;
-
     p_id3_tag = id3_tag_parse( p_data, i_size );
     if( !p_id3_tag )
         return;
 
-    p_demux_meta->p_meta = p_meta = vlc_meta_New();
+    if( !p_demux_meta->p_meta )
+        p_demux_meta->p_meta = vlc_meta_New();
+    p_meta = p_demux_meta->p_meta;
 
 #define ID_IS( a ) (!strcmp(  p_frame->id, a ))
 #define DESCR_IS( a) strstr( (char*)p_frame->description, a )
@@ -242,10 +246,10 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size )
  * APEv1/2
  *****************************************************************************/
 #define APE_TAG_HEADERSIZE (32)
-static int GetAPEvXSize( const uint8_t *p_data, int i_data )
+static size_t GetAPEvXSize( const uint8_t *p_data, int i_data )
 {
     uint32_t flags;
-    int i_body;
+    size_t i_body;
 
     if( i_data < APE_TAG_HEADERSIZE ||
         ( GetDWLE( &p_data[8] ) != 1000 && GetDWLE( &p_data[8] ) != 2000 ) || /* v1/v2 only */
@@ -263,12 +267,13 @@ static int GetAPEvXSize( const uint8_t *p_data, int i_data )
     /* it is the footer */
     return i_body + ( (flags&(1<<31)) ? APE_TAG_HEADERSIZE : 0 );
 }
-static void ParseAPEvXTag( demux_t *p_demux, uint8_t *p_data, int i_data )
+static void ParseAPEvXTag( demux_t *p_demux, const uint8_t *p_data, int i_data )
 {
-    vlc_meta_t *p_meta = (vlc_meta_t *)p_demux->p_private;
-    vlc_bool_t b_start;
-    vlc_bool_t b_end;
-    uint8_t *p_header = NULL;
+    demux_meta_t     *p_demux_meta = (demux_meta_t*)p_demux->p_private;
+    vlc_meta_t       *p_meta;
+    bool b_start;
+    bool b_end;
+    const uint8_t *p_header = NULL;
     int i_entry;
 
     if( i_data < APE_TAG_HEADERSIZE )
@@ -279,6 +284,10 @@ static void ParseAPEvXTag( demux_t *p_demux, uint8_t *p_data, int i_data )
     if( !b_end && !b_start )
         return;
 
+    if( !p_demux_meta->p_meta )
+        p_demux_meta->p_meta = vlc_meta_New();
+    p_meta = p_demux_meta->p_meta;
+
     if( b_start )
     {
         p_header = &p_data[0];
@@ -297,9 +306,6 @@ static void ParseAPEvXTag( demux_t *p_demux, uint8_t *p_data, int i_data )
     if( i_entry <= 0 )
         return;
 
-    if( !p_meta )
-        p_demux->p_private = p_meta = vlc_meta_New();
-
     while( i_entry > 0 && i_data >= 10 )
     {
         const int i_size = GetDWLE( &p_data[0] );
@@ -370,14 +376,14 @@ static void ParseAPEvXTag( demux_t *p_demux, uint8_t *p_data, int i_data )
 static void CheckFooter( demux_t *p_demux )
 {
     const int64_t i_pos = stream_Size( p_demux->s );
-    const int i_peek = 128+APE_TAG_HEADERSIZE;
-    uint8_t *p_peek;
-    uint8_t *p_peek_id3;
+    const size_t i_peek = 128+APE_TAG_HEADERSIZE;
+    const uint8_t *p_peek;
+    const uint8_t *p_peek_id3;
     int64_t i_id3v2_pos = -1;
     int64_t i_apevx_pos = -1;
     int i_id3v2_size;
     int i_apevx_size;
-    int i_id3v1_size;
+    size_t i_id3v1_size;
 
     if( i_pos < i_peek )
         return;
@@ -446,7 +452,7 @@ static void CheckFooter( demux_t *p_demux )
 }
 static void CheckHeader( demux_t *p_demux )
 {
-    uint8_t *p_peek;
+    const uint8_t *p_peek;
     int i_size;
 
     if( stream_Seek( p_demux->s, 0 ) )
@@ -481,20 +487,21 @@ static void CheckHeader( demux_t *p_demux )
  ****************************************************************************/
 static int ParseTags( vlc_object_t *p_this )
 {
-    demux_t *p_demux = (demux_t *)p_this;
-    vlc_bool_t b_seekable;
-    int64_t i_init;
-
-    p_demux->p_private = NULL;
+    demux_t      *p_demux = (demux_t *)p_this;
+    demux_meta_t *p_demux_meta = (demux_meta_t*)p_demux->p_private;
+    bool    b_seekable;
+    int64_t       i_init;
 
     msg_Dbg( p_demux, "checking for ID3v1/2 and APEv1/2 tags" );
-
     stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &b_seekable );
     if( !b_seekable )
-        return VLC_SUCCESS;
+        return VLC_EGENERIC;
 
     i_init = stream_Tell( p_demux->s );
 
+    TAB_INIT( p_demux_meta->i_attachments, p_demux_meta->attachments );
+    p_demux_meta->p_meta = NULL;
+
     /* */
     CheckFooter( p_demux );
 
@@ -506,5 +513,8 @@ static int ParseTags( vlc_object_t *p_this )
      *  for them
      */
     stream_Seek( p_demux->s, i_init );
+    if( !p_demux_meta->p_meta && p_demux_meta->i_attachments <= 0 )
+        return VLC_EGENERIC;
     return VLC_SUCCESS;
 }
+