#include <vlc/intf.h>
#include <vlc/input.h>
-#include "ninput.h"
-
#include <sys/types.h>
+#include "vlc_meta.h"
+
#include <id3tag.h>
#include "id3genres.h"
/*****************************************************************************
* 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 )
{
struct id3_tag *p_id3_tag;
struct id3_frame *p_frame;
char *psz_temp;
vlc_value_t val;
int i;
+ input_thread_t *p_input;
+
+ p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT,
+ FIND_PARENT );
+ if( !p_input)
+ {
+ return VLC_EGENERIC;
+ }
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" );
return;
}
val.b_bool = VLC_FALSE;
+
p_id3_tag = id3_tag_parse( p_data, i_size );
i = 0;
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 )
+ if( psz_temp != psz_endptr && i_genre >= 0 &&
+ i_genre < NUM_GENRES )
{
- input_Control( p_input, INPUT_ADD_INFO, "ID3",
- (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_Control( p_input, INPUT_ADD_INFO, "ID3",
- (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 ) )
{
- input_Control( p_input, INPUT_SET_NAME, psz_temp );
- input_Control( p_input, INPUT_ADD_INFO, "ID3",
- (char *)p_frame->description, psz_temp );
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ VLC_META_TITLE, psz_temp );
+// input_Control( p_demux, INPUT_SET_NAME, psz_temp );
}
else if ( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) )
{
- 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 );
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
+ VLC_META_ARTIST, psz_temp );
}
else
{
- input_Control( p_input, INPUT_ADD_INFO, "ID3",
+ /* Unknown meta info */
+ vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
(char *)p_frame->description, psz_temp );
}
free( psz_temp );
id3_tag_delete( p_id3_tag );
val.b_bool = VLC_TRUE;
- var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
+ var_Change( p_demux, "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 = NULL;
+ 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 )
- {
- 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_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 )
{
+ int64_t i_init;
int64_t i_pos;
/*look for a ID3v1 tag at the end of the file*/
- i_pos = stream_Size( p_input->s );
+ 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, i_pos - 128 );
+ stream_Seek( p_demux->s, i_pos - 128 );
/* get 10 byte id3 header */
- if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 )
+ if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
{
- msg_Err( p_input, "cannot peek()" );
- vlc_object_release( p_input );
+ msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC );
}
if ( i_size2 == 128 )
{
/* peek the entire tag */
- if ( stream_Peek( p_input->s, &p_peek, i_size2 ) < i_size2 )
+ if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 )
{
- msg_Err( p_input, "cannot peek()" );
- vlc_object_release( p_input );
+ msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC );
}
- msg_Dbg( p_input, "found ID3v1 tag" );
- 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( stream_Peek( p_input->s, &p_peek, 128 ) < 128 )
+ if( stream_Peek( p_demux->s, &p_peek, 128 ) < 128 )
{
- msg_Err( p_input, "cannot peek()" );
- vlc_object_release( p_input );
+ msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC );
}
i_size2 = id3_tag_query( p_peek + 118, 10 );
if ( i_size2 < 0 && i_pos > -i_size2 )
{ /* id3v2.4 footer found */
- input_AccessReinit( p_input );
- p_input->pf_seek( p_input, i_pos + i_size2 );
+ stream_Seek( p_demux->s , i_pos + i_size2 );
/* peek the entire tag */
- if ( stream_Peek( p_input->s, &p_peek, i_size2 ) < i_size2 )
+ if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 )
{
- msg_Err( p_input, "cannot peek()" );
- vlc_object_release( p_input );
+ msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC );
}
- msg_Dbg( p_input, "found ID3v2 tag at end of file" );
- 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( stream_Peek( p_input->s, &p_peek, 10 ) < 10 )
+ if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
{
- msg_Err( p_input, "cannot peek()" );
- vlc_object_release( p_input );
+ msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC );
}
i_size = id3_tag_query( p_peek, 10 );
if ( i_size <= 0 )
{
- vlc_object_release( p_input );
return( VLC_SUCCESS );
}
/* Read the entire tag */
p_peek = malloc( i_size );
- if( !p_peek || stream_Read( p_input->s, p_peek, i_size ) < i_size )
+ if( !p_peek || stream_Read( p_demux->s, p_peek, i_size ) < i_size )
{
- msg_Err( p_input, "cannot read ID3 tag" );
+ msg_Err( p_demux, "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" );
+ ParseID3Tag( p_demux, p_peek, i_size );
+ msg_Dbg( p_demux, "found ID3v2 tag" );
free( p_peek );
- vlc_object_release( p_input );
return( VLC_SUCCESS );
}