Commit 33fbe581 authored by Gildas Bazin's avatar Gildas Bazin

* modules/demux/util/id3tag.c: fixed a few bugs.

parent fac7e3a2
...@@ -63,46 +63,43 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size ) ...@@ -63,46 +63,43 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size )
{ {
struct id3_tag *p_id3_tag; struct id3_tag *p_id3_tag;
struct id3_frame *p_frame; struct id3_frame *p_frame;
char *psz_temp;
vlc_value_t val;
int i;
input_thread_t *p_input; input_thread_t *p_input;
vlc_value_t val;
int i = 0;
p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
FIND_PARENT ); if( !p_input) return;
if( !p_input)
{
return;
}
var_Get( p_input, "demuxed-id3", &val ); var_Get( p_input, "demuxed-id3", &val );
if( val.b_bool ) if( val.b_bool )
{ {
msg_Dbg( p_demux, "the ID3 tag was already parsed" ); msg_Dbg( p_demux, "the ID3 tag was already parsed" );
vlc_object_release( p_input );
return; 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_id3_tag = id3_tag_parse( p_data, i_size );
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 ) ) )
{ {
int i_strings; int i_strings = id3_field_getnstrings( &p_frame->fields[1] );
i_strings = id3_field_getnstrings( &p_frame->fields[1] ); while( i_strings > 0 )
while ( i_strings > 0 )
{ {
psz_temp = id3_ucs4_utf8duplicate( id3_field_getstrings( &p_frame->fields[1], --i_strings ) ); char *psz_temp = id3_ucs4_utf8duplicate(
if ( !strcmp(p_frame->id, ID3_FRAME_GENRE ) ) id3_field_getstrings( &p_frame->fields[1], --i_strings ) );
if( !strcmp( p_frame->id, ID3_FRAME_GENRE ) )
{ {
int i_genre;
char *psz_endptr; char *psz_endptr;
i_genre = strtol( psz_temp, &psz_endptr, 10 ); int 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 )
{ {
vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
VLC_META_GENRE, ppsz_genres[atoi(psz_temp)]); VLC_META_GENRE, ppsz_genres[atoi(psz_temp)]);
...@@ -114,13 +111,12 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size ) ...@@ -114,13 +111,12 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size )
VLC_META_GENRE, psz_temp ); VLC_META_GENRE, psz_temp );
} }
} }
else if ( !strcmp(p_frame->id, ID3_FRAME_TITLE ) ) else if( !strcmp(p_frame->id, ID3_FRAME_TITLE ) )
{ {
vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
VLC_META_TITLE, psz_temp ); VLC_META_TITLE, psz_temp );
// input_Control( p_demux, INPUT_SET_NAME, psz_temp );
} }
else if ( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) ) else if( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) )
{ {
vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, vlc_meta_Add( (vlc_meta_t *)p_demux->p_private,
VLC_META_ARTIST, psz_temp ); VLC_META_ARTIST, psz_temp );
...@@ -137,9 +133,6 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size ) ...@@ -137,9 +133,6 @@ static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size )
} }
id3_tag_delete( p_id3_tag ); id3_tag_delete( p_id3_tag );
val.b_bool = VLC_TRUE;
var_Change( p_demux, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
vlc_object_release( p_input ); vlc_object_release( p_input );
} }
...@@ -177,7 +170,7 @@ static int ParseID3Tags( vlc_object_t *p_this ) ...@@ -177,7 +170,7 @@ static int ParseID3Tags( vlc_object_t *p_this )
if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
{ {
msg_Err( p_demux, "cannot peek()" ); msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
i_size2 = id3_tag_query( p_peek, 10 ); i_size2 = id3_tag_query( p_peek, 10 );
...@@ -187,7 +180,7 @@ static int ParseID3Tags( vlc_object_t *p_this ) ...@@ -187,7 +180,7 @@ static int ParseID3Tags( vlc_object_t *p_this )
if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 ) if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 )
{ {
msg_Err( p_demux, "cannot peek()" ); msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
msg_Dbg( p_demux, "found ID3v1 tag" ); msg_Dbg( p_demux, "found ID3v1 tag" );
ParseID3Tag( p_demux, p_peek, i_size2 ); ParseID3Tag( p_demux, p_peek, i_size2 );
...@@ -198,7 +191,7 @@ static int ParseID3Tags( vlc_object_t *p_this ) ...@@ -198,7 +191,7 @@ static int ParseID3Tags( vlc_object_t *p_this )
if( stream_Peek( p_demux->s, &p_peek, 128 ) < 128 ) if( stream_Peek( p_demux->s, &p_peek, 128 ) < 128 )
{ {
msg_Err( p_demux, "cannot peek()" ); msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
i_size2 = id3_tag_query( p_peek + 118, 10 ); i_size2 = id3_tag_query( p_peek + 118, 10 );
if ( i_size2 < 0 && i_pos > -i_size2 ) if ( i_size2 < 0 && i_pos > -i_size2 )
...@@ -208,7 +201,7 @@ static int ParseID3Tags( vlc_object_t *p_this ) ...@@ -208,7 +201,7 @@ static int ParseID3Tags( vlc_object_t *p_this )
if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 ) if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 )
{ {
msg_Err( p_demux, "cannot peek()" ); msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
msg_Dbg( p_demux, "found ID3v2 tag at end of file" ); msg_Dbg( p_demux, "found ID3v2 tag at end of file" );
ParseID3Tag( p_demux, p_peek, i_size2 ); ParseID3Tag( p_demux, p_peek, i_size2 );
...@@ -220,13 +213,13 @@ static int ParseID3Tags( vlc_object_t *p_this ) ...@@ -220,13 +213,13 @@ static int ParseID3Tags( vlc_object_t *p_this )
if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
{ {
msg_Err( p_demux, "cannot peek()" ); msg_Err( p_demux, "cannot peek()" );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
i_size = id3_tag_query( p_peek, 10 ); i_size = id3_tag_query( p_peek, 10 );
if ( i_size <= 0 ) if ( i_size <= 0 )
{ {
return( VLC_SUCCESS ); return VLC_SUCCESS;
} }
/* Read the entire tag */ /* Read the entire tag */
...@@ -235,12 +228,12 @@ static int ParseID3Tags( vlc_object_t *p_this ) ...@@ -235,12 +228,12 @@ static int ParseID3Tags( vlc_object_t *p_this )
{ {
msg_Err( p_demux, "cannot read ID3 tag" ); msg_Err( p_demux, "cannot read ID3 tag" );
if( p_peek ) free( p_peek ); if( p_peek ) free( p_peek );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
ParseID3Tag( p_demux, p_peek, i_size );
msg_Dbg( p_demux, "found ID3v2 tag" ); msg_Dbg( p_demux, "found ID3v2 tag" );
ParseID3Tag( p_demux, p_peek, i_size );
free( p_peek ); free( p_peek );
return( VLC_SUCCESS ); return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment