Commit 2d109a77 authored by Clément Stenac's avatar Clément Stenac

Fix id3 and id3tag (using meta)

parent 0011cc99
......@@ -29,6 +29,8 @@
#include <vlc/vlc.h>
#include <vlc/input.h>
#include "vlc_meta.h"
/*****************************************************************************
* Module descriptor
*****************************************************************************/
......@@ -59,6 +61,8 @@ struct demux_sys_t
int i_bitrate_avg; /* extracted from Xing header */
vlc_meta_t *meta;
es_out_id_t *p_es;
};
......@@ -165,9 +169,19 @@ static int Open( vlc_object_t * p_this )
}
}
/* skip possible id3 header */
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->i_time = 1;
p_sys->i_bitrate_avg = 0;
p_sys->meta = NULL;
/* skip/parse possible id3 header */
if( ( p_id3 = module_Need( p_demux, "id3", NULL, 0 ) ) )
{
p_sys->meta = (vlc_meta_t *)p_demux->p_private;
/* temporary */
msg_Dbg( p_demux, "Title : %s",
vlc_meta_GetValue( p_sys->meta,VLC_META_TITLE ) );
p_demux->p_private = NULL;
module_Unneed( p_demux, p_id3 );
}
......@@ -209,9 +223,6 @@ static int Open( vlc_object_t * p_this )
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->i_time = 1;
p_sys->i_bitrate_avg = 0;
es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'm', 'p', 'g', 'a' ) );
......@@ -388,8 +399,21 @@ static void Close( vlc_object_t * p_this )
static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
return demux2_vaControlHelper( p_demux->s,
0, -1,
p_sys->i_bitrate_avg, 1, i_query, args );
vlc_meta_t **pp_meta;
switch( i_query )
{
case DEMUX_GET_META:
pp_meta = (vlc_meta_t **)va_arg( args, vlc_meta_t** );
*pp_meta = vlc_meta_Duplicate( p_sys->meta );
return VLC_SUCCESS;
default:
return demux2_vaControlHelper( p_demux->s,
0, -1,
p_sys->i_bitrate_avg, 1, i_query,
args );
}
}
......@@ -49,38 +49,25 @@ vlc_module_end();
****************************************************************************/
static int SkipID3Tag( 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;
uint8_t version, revision;
int b_footer;
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 = NULL;
msg_Dbg( p_input, "checking for ID3 tag" );
msg_Dbg( p_demux, "checking for ID3 tag" );
/* 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( p_peek[0] != 'I' || p_peek[1] != 'D' || p_peek[2] != '3' )
{
vlc_object_release( p_input );
return VLC_SUCCESS;
}
......@@ -98,11 +85,10 @@ static int SkipID3Tag( vlc_object_t *p_this )
i_size += 10;
/* Skip the entire tag */
stream_Read( p_input->s, NULL, i_size );
stream_Read( p_demux->s, NULL, i_size );
msg_Dbg( p_input, "ID3v2.%d revision %d tag found, skiping %d bytes",
msg_Dbg( p_demux, "ID3v2.%d revision %d tag found, skiping %d bytes",
version, revision, i_size );
vlc_object_release( p_input );
return VLC_SUCCESS;
}
......@@ -31,10 +31,10 @@
#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"
......@@ -59,22 +59,31 @@ 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 )
{
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;
......@@ -92,34 +101,34 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
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 );
......@@ -129,7 +138,9 @@ static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size )
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 );
}
/*****************************************************************************
......@@ -138,44 +149,34 @@ 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 = 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 );
}
......@@ -183,72 +184,63 @@ static int ParseID3Tags( vlc_object_t *p_this )
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 );
}
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