]> git.sesse.net Git - vlc/blobdiff - modules/demux/util/id3tag.c
* all: do not use input_Clock* anymore (use ES_OUT_SET_PCR instead).
[vlc] / modules / demux / util / id3tag.c
index 516b412dd81d74ce9289be8c0b8529201563ab05..5f07c1295995a596cb963f24b8e7ec943279aeb4 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * id3tag.c: id3 tag parser/skipper based on libid3tag
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: id3tag.c,v 1.17 2003/12/22 22:37:01 hartman Exp $
+ * Copyright (C) 2002-2004 VideoLAN
+ * $Id$
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
@@ -47,7 +47,7 @@ static int  ParseID3Tags ( vlc_object_t * );
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-set_description( _("id3 tag parser using libid3tag" ) );
+set_description( _("ID3 tag parser using libid3tag" ) );
 set_capability( "id3", 70 );
 set_callbacks( ParseID3Tags, NULL );
 vlc_module_end();
@@ -61,10 +61,8 @@ vlc_module_end();
  *****************************************************************************/
 static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
 {
-    playlist_t            *p_playlist;
     struct id3_tag        *p_id3_tag;
     struct id3_frame      *p_frame;
-    input_info_category_t *p_category;
     char                  *psz_temp;
     vlc_value_t val;
     int i;
@@ -72,21 +70,19 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
     var_Get( p_input, "demuxed-id3", &val );
     if( val.b_bool )
     {
-        msg_Dbg( p_input, "The ID3 tag was already parsed" );
+        msg_Dbg( p_input, "the ID3 tag was already parsed" );
         return;
     }
 
-    p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
-
     val.b_bool = VLC_FALSE;
     p_id3_tag = id3_tag_parse( p_data, i_size );
-    p_category = input_InfoCategory( p_input, "ID3" );
     i = 0;
 
     while ( ( p_frame = id3_tag_findframe( p_id3_tag , "T", i ) ) )
     {
-        playlist_item_t *p_item = p_playlist ? p_playlist->pp_items[p_playlist->i_index] : NULL;
-        int i_strings = id3_field_getnstrings( &p_frame->fields[1] );
+        int i_strings;
+
+        i_strings = id3_field_getnstrings( &p_frame->fields[1] );
 
         while ( i_strings > 0 )
         {
@@ -98,70 +94,42 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
                 i_genre = strtol( psz_temp, &psz_endptr, 10 );
                 if( psz_temp != psz_endptr && i_genre >= 0 && i_genre < NUM_GENRES )
                 {
-                    input_AddInfo( p_category, (char *)p_frame->description,
+                    input_Control( p_input, INPUT_ADD_INFO, "ID3",
+                                   (char *)p_frame->description,
                                    ppsz_genres[atoi(psz_temp)]);
                 }
                 else
                 {
-                    input_AddInfo( p_category, (char *)p_frame->description,
-                                                psz_temp );
+                    input_Control( p_input, INPUT_ADD_INFO, "ID3",
+                                   (char *)p_frame->description, psz_temp);
                 }
             }
             else if ( !strcmp(p_frame->id, ID3_FRAME_TITLE ) )
             {
-                if( p_item )
-                {
-                    if( p_item->psz_name )
-                    {
-                        free( p_item->psz_name );
-                    }
-                    p_item->psz_name = strdup( psz_temp );;
-
-                    val.b_bool = VLC_TRUE;
-                }
-                input_AddInfo( p_category, (char *)p_frame->description,
-                                            psz_temp );
+                input_Control( p_input, INPUT_SET_NAME, psz_temp );
+                input_Control( p_input, INPUT_ADD_INFO, "ID3",
+                               (char *)p_frame->description, psz_temp );
             }
             else if ( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) )
             {
-                if( p_item )
-                {
-                    if( p_item->psz_author )
-                    {
-                        free( p_item->psz_author );
-                    }
-                    p_item->psz_author = strdup( psz_temp );
-
-                    val.b_bool = VLC_TRUE;
-                }
-                input_AddInfo( p_category, (char *)p_frame->description,
-                                            psz_temp );
+                input_Control( p_input, INPUT_ADD_INFO,
+                               _("General"), _("Author"), psz_temp );
+                input_Control( p_input, INPUT_ADD_INFO, "ID3",
+                               (char *)p_frame->description, psz_temp );
             }
             else
             {
-                input_AddInfo( p_category, (char *)p_frame->description,
-                                            psz_temp );
+                input_Control( p_input, INPUT_ADD_INFO, "ID3",
+                               (char *)p_frame->description, psz_temp );
             }
             free( psz_temp );
         }
         i++;
     }
     id3_tag_delete( p_id3_tag );
-    if(val.b_bool == VLC_TRUE )
-    {
-        if( p_playlist )
-        {
-            val.b_bool = VLC_TRUE;
-            var_Set( p_playlist, "intf-change", val );
-        }
-    }
+
     val.b_bool = VLC_TRUE;
     var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
-
-    if( p_playlist )
-    {
-        vlc_object_release( p_playlist );
-    }
 }
 
 /*****************************************************************************
@@ -170,18 +138,25 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
  ****************************************************************************/
 static int ParseID3Tags( vlc_object_t *p_this )
 {
-    input_thread_t *p_input;
+    input_thread_t *p_input = NULL;
     uint8_t *p_peek;
     int i_size;
     int i_size2;
 
-    if ( p_this->i_object_type != VLC_OBJECT_INPUT )
+    if ( p_this->i_object_type == VLC_OBJECT_INPUT )
     {
-        return( VLC_EGENERIC );
+        p_input = (input_thread_t *)p_this;
+    }
+    if( p_input == NULL )
+    {
+        p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
+        if( p_input == NULL )
+        {
+            return VLC_EGENERIC;
+        }
     }
-    p_input = (input_thread_t *)p_this;
 
-    msg_Dbg( p_input, "Checking for ID3 tag" );
+    msg_Dbg( p_input, "checking for ID3 tag" );
 
     if ( p_input->stream.b_seekable &&
          p_input->stream.i_method != INPUT_METHOD_NETWORK )
@@ -200,6 +175,7 @@ static int ParseID3Tags( vlc_object_t *p_this )
             if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 )
             {
                 msg_Err( p_input, "cannot peek()" );
+                vlc_object_release( p_input );
                 return( VLC_EGENERIC );
             }
 
@@ -210,9 +186,10 @@ static int ParseID3Tags( vlc_object_t *p_this )
                 if ( stream_Peek( p_input->s, &p_peek, i_size2 ) < i_size2 )
                 {
                     msg_Err( p_input, "cannot peek()" );
+                    vlc_object_release( p_input );
                     return( VLC_EGENERIC );
                 }
-                msg_Dbg( p_input, "Found ID3v1 tag" );
+                msg_Dbg( p_input, "found ID3v1 tag" );
                 ParseID3Tag( p_input, p_peek, i_size2 );
             }
 
@@ -221,6 +198,7 @@ static int ParseID3Tags( vlc_object_t *p_this )
             if( stream_Peek( p_input->s, &p_peek, 128 ) < 128 )
             {
                 msg_Err( p_input, "cannot peek()" );
+                vlc_object_release( p_input );
                 return( VLC_EGENERIC );
             }
             i_size2 = id3_tag_query( p_peek + 118, 10 );
@@ -232,9 +210,10 @@ static int ParseID3Tags( vlc_object_t *p_this )
                 if ( stream_Peek( p_input->s, &p_peek, i_size2 ) < i_size2 )
                 {
                     msg_Err( p_input, "cannot peek()" );
+                    vlc_object_release( p_input );
                     return( VLC_EGENERIC );
                 }
-                msg_Dbg( p_input, "Found ID3v2 tag at end of file" );
+                msg_Dbg( p_input, "found ID3v2 tag at end of file" );
                 ParseID3Tag( p_input, p_peek, i_size2 );
             }
         }
@@ -245,12 +224,14 @@ static int ParseID3Tags( vlc_object_t *p_this )
     if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 )
     {
         msg_Err( p_input, "cannot peek()" );
+        vlc_object_release( p_input );
         return( VLC_EGENERIC );
     }
 
     i_size = id3_tag_query( p_peek, 10 );
     if ( i_size <= 0 )
     {
+        vlc_object_release( p_input );
         return( VLC_SUCCESS );
     }
 
@@ -258,14 +239,16 @@ static int ParseID3Tags( vlc_object_t *p_this )
     p_peek = malloc( i_size );
     if( !p_peek || stream_Read( p_input->s, p_peek, i_size ) < i_size )
     {
-        msg_Err( p_input, "Cannot read ID3 tag" );
+        msg_Err( p_input, "cannot read ID3 tag" );
         if( p_peek ) free( p_peek );
+        vlc_object_release( p_input );
         return( VLC_EGENERIC );
     }
 
     ParseID3Tag( p_input, p_peek, i_size );
-    msg_Dbg( p_input, "Found ID3v2 tag" );
+    msg_Dbg( p_input, "found ID3v2 tag" );
 
     free( p_peek );
+    vlc_object_release( p_input );
     return( VLC_SUCCESS );
 }