/*****************************************************************************
* id3tag.c: id3 tag parser/skipper based on libid3tag
*****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: id3tag.c,v 1.14 2003/10/29 17:32:54 zorglub Exp $
+ * Copyright (C) 2002-2004 VideoLAN
+ * $Id$
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
*
#include <sys/types.h>
+#include "vlc_meta.h"
+
#include <id3tag.h>
#include "id3genres.h"
* 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();
/*****************************************************************************
* ParseID3Tag : parse an id3tag into the info structures
*****************************************************************************/
-static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
+static void ParseID3Tag( demux_t *p_demux, 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;
- int i_strings;
- char * psz_temp;
- int i;
+ struct id3_tag *p_id3_tag;
+ struct id3_frame *p_frame;
+ input_thread_t *p_input;
vlc_value_t val;
+ int i = 0;
- var_Get( p_input, "demuxed-id3", &val );
+ p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
+ if( !p_input) return;
+ var_Get( p_input, "demuxed-id3", &val );
if( val.b_bool )
{
- msg_Dbg( p_input, "The ID3 tag was already parsed" );
+ msg_Dbg( p_demux, "the ID3 tag was already parsed" );
+ vlc_object_release( p_input );
return;
}
- val.b_bool = VLC_FALSE;
+ val.b_bool = VLC_TRUE;
+ var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
+
p_id3_tag = id3_tag_parse( p_data, i_size );
- p_category = input_InfoCategory( p_input, "ID3" );
- i = 0;
+ if( !p_id3_tag ) return;
- while ( ( p_frame = id3_tag_findframe( p_id3_tag , "T", i ) ) )
+ while( ( p_frame = id3_tag_findframe( p_id3_tag , "T", i ) ) )
{
- i_strings = id3_field_getnstrings( &p_frame->fields[1] );
- while ( i_strings > 0 )
+ int i_strings = id3_field_getnstrings( &p_frame->fields[1] );
+
+ while( i_strings > 0 )
{
- psz_temp = id3_ucs4_utf8duplicate( id3_field_getstrings( &p_frame->fields[1], --i_strings ) );
- if ( !strcmp(p_frame->id, ID3_FRAME_GENRE ) )
+ char *psz_temp = id3_ucs4_utf8duplicate(
+ id3_field_getstrings( &p_frame->fields[1], --i_strings ) );
+
+ if( !strcmp( p_frame->id, ID3_FRAME_GENRE ) )
{
- int i_genre;
char *psz_endptr;
- i_genre = strtol( psz_temp, &psz_endptr, 10 );
- if( psz_temp != psz_endptr && i_genre >= 0 && i_genre < NUM_GENRES )
+ int 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,
- ppsz_genres[atoi(psz_temp)]);
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ VLC_META_GENRE, ppsz_genres[atoi(psz_temp)]);
}
else
{
- input_AddInfo( p_category, (char *)p_frame->description,
- psz_temp );
+ /* Unknown genre */
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ VLC_META_GENRE, psz_temp );
}
}
- else if ( !strcmp(p_frame->id, ID3_FRAME_TITLE ) )
+ else if( !strcmp(p_frame->id, ID3_FRAME_TITLE ) )
{
- p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
- FIND_PARENT );
- if( p_playlist )
- {
- p_playlist->pp_items[p_playlist->i_index]->psz_name =
- strdup( psz_temp );
- val.b_bool = VLC_TRUE;
- vlc_object_release( p_playlist );
- }
- input_AddInfo( p_category, (char *)p_frame->description,
- psz_temp );
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ VLC_META_TITLE, psz_temp );
}
- else if ( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) )
+ else if( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) )
{
- p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
- FIND_PARENT );
- if( p_playlist )
- {
- p_playlist->pp_items[p_playlist->i_index]->psz_author =
- strdup( psz_temp );
- val.b_bool = VLC_TRUE;
- vlc_object_release( p_playlist );
- }
- input_AddInfo( p_category, (char *)p_frame->description,
- psz_temp );
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ VLC_META_ARTIST, psz_temp );
}
else
{
- input_AddInfo( p_category, (char *)p_frame->description,
- psz_temp );
+ /* Unknown meta info */
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ (char *)p_frame->description, psz_temp );
}
free( psz_temp );
}
i++;
}
id3_tag_delete( p_id3_tag );
- if(val.b_bool == VLC_TRUE )
- {
- p_playlist = vlc_object_find( p_input,
- VLC_OBJECT_PLAYLIST, FIND_PARENT );
- if( p_playlist )
- {
- val.b_bool = VLC_TRUE;
- var_Set( p_playlist, "intf-change", val );
- vlc_object_release( p_playlist );
- }
- }
- val.b_bool = VLC_TRUE;
- var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
+
+ vlc_object_release( p_input );
}
/*****************************************************************************
****************************************************************************/
static int ParseID3Tags( vlc_object_t *p_this )
{
- input_thread_t *p_input;
+ demux_t *p_demux = (demux_t *)p_this;
uint8_t *p_peek;
int i_size;
int i_size2;
+ vlc_bool_t b_seekable;
- if ( p_this->i_object_type != VLC_OBJECT_INPUT )
- {
- return( VLC_EGENERIC );
- }
- p_input = (input_thread_t *)p_this;
+ p_demux->p_private = (void *)vlc_meta_New();
- msg_Dbg( p_input, "Checking for ID3 tag" );
+ msg_Dbg( p_demux, "checking for ID3 tag" );
- if ( p_input->stream.b_seekable &&
- p_input->stream.i_method != INPUT_METHOD_NETWORK )
+ stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &b_seekable );
+ if( b_seekable )
{
- stream_position_t pos;
+ int64_t i_init;
+ int64_t i_pos;
- /*look for a id3v1 tag at the end of the file*/
- input_Tell( p_input, &pos );
- if ( pos.i_size >128 )
+ /*look for a ID3v1 tag at the end of the file*/
+ i_init = stream_Tell( p_demux->s );
+ i_pos = stream_Size( p_demux->s );
+
+ if ( i_pos >128 )
{
- input_AccessReinit( p_input );
- p_input->pf_seek( p_input, pos.i_size - 128 );
+ stream_Seek( p_demux->s, i_pos - 128 );
/* get 10 byte id3 header */
- if( input_Peek( p_input, &p_peek, 10 ) < 10 )
+ if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
{
- msg_Err( p_input, "cannot peek()" );
- return( VLC_EGENERIC );
+ msg_Err( p_demux, "cannot peek()" );
+ return VLC_EGENERIC;
}
+
i_size2 = id3_tag_query( p_peek, 10 );
if ( i_size2 == 128 )
{
/* peek the entire tag */
- if ( input_Peek( p_input, &p_peek, i_size2 ) < i_size2 )
+ if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 )
{
- msg_Err( p_input, "cannot peek()" );
- return( VLC_EGENERIC );
+ msg_Err( p_demux, "cannot peek()" );
+ return VLC_EGENERIC;
}
- ParseID3Tag( p_input, p_peek, i_size2 );
+ msg_Dbg( p_demux, "found ID3v1 tag" );
+ ParseID3Tag( p_demux, p_peek, i_size2 );
}
- /* look for id3v2.4 tag at end of file */
- /* get 10 byte id3 footer */
- if( input_Peek( p_input, &p_peek, 128 ) < 128 )
+ /* look for ID3v2.4 tag at end of file */
+ /* get 10 byte ID3 footer */
+ if( stream_Peek( p_demux->s, &p_peek, 128 ) < 128 )
{
- msg_Err( p_input, "cannot peek()" );
- return( VLC_EGENERIC );
+ msg_Err( p_demux, "cannot peek()" );
+ return VLC_EGENERIC;
}
i_size2 = id3_tag_query( p_peek + 118, 10 );
- if ( i_size2 < 0 && pos.i_size > -i_size2 )
+ if ( i_size2 < 0 && i_pos > -i_size2 )
{ /* id3v2.4 footer found */
- input_AccessReinit( p_input );
- p_input->pf_seek( p_input, pos.i_size + i_size2 );
+ stream_Seek( p_demux->s , i_pos + i_size2 );
/* peek the entire tag */
- if ( input_Peek( p_input, &p_peek, i_size2 ) < i_size2 )
+ if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 )
{
- msg_Err( p_input, "cannot peek()" );
- return( VLC_EGENERIC );
+ msg_Err( p_demux, "cannot peek()" );
+ return VLC_EGENERIC;
}
- ParseID3Tag( p_input, p_peek, i_size2 );
+ msg_Dbg( p_demux, "found ID3v2 tag at end of file" );
+ ParseID3Tag( p_demux, p_peek, i_size2 );
}
}
- input_AccessReinit( p_input );
- p_input->pf_seek( p_input, 0 );
+ stream_Seek( p_demux->s, i_init );
}
/* get 10 byte id3 header */
- if( input_Peek( p_input, &p_peek, 10 ) < 10 )
+ if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
{
- msg_Err( p_input, "cannot peek()" );
- return( VLC_EGENERIC );
+ msg_Err( p_demux, "cannot peek()" );
+ return VLC_EGENERIC;
}
i_size = id3_tag_query( p_peek, 10 );
if ( i_size <= 0 )
{
- return( VLC_SUCCESS );
+ return VLC_SUCCESS;
}
- /* peek the entire tag */
- if ( input_Peek( p_input, &p_peek, i_size ) < i_size )
+ /* Read the entire tag */
+ p_peek = malloc( i_size );
+ if( !p_peek || stream_Read( p_demux->s, p_peek, i_size ) < i_size )
{
- msg_Err( p_input, "cannot peek()" );
- return( VLC_EGENERIC );
+ msg_Err( p_demux, "cannot read ID3 tag" );
+ if( p_peek ) free( p_peek );
+ return VLC_EGENERIC;
}
- ParseID3Tag( p_input, p_peek, i_size );
- msg_Dbg( p_input, "ID3 tag found, skiping %d bytes", i_size );
- p_input->p_current_data += i_size; /* seek passed end of ID3 tag */
- return( VLC_SUCCESS );
+ msg_Dbg( p_demux, "found ID3v2 tag" );
+ ParseID3Tag( p_demux, p_peek, i_size );
+
+ free( p_peek );
+ return VLC_SUCCESS;
}