Changeset 2d109a7702135ed31aa8e466ea9534abac9d2fd8
- Timestamp:
- 23/06/04 12:00:21
(4 years ago)
- Author:
- Clément Stenac <zorglub@videolan.org>
- git-committer:
- Clément Stenac <zorglub@videolan.org> 1087984821 +0000
- git-parent:
[0011cc995beacfd93385fa9c17fdd096b7267285]
- git-author:
- Clément Stenac <zorglub@videolan.org> 1087984821 +0000
- Message:
Fix id3 and id3tag (using meta)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3bcdafa |
r2d109a7 |
|
| 30 | 30 | #include <vlc/input.h> |
|---|
| 31 | 31 | |
|---|
| | 32 | #include "vlc_meta.h" |
|---|
| | 33 | |
|---|
| 32 | 34 | /***************************************************************************** |
|---|
| 33 | 35 | * Module descriptor |
|---|
| … | … | |
| 59 | 61 | |
|---|
| 60 | 62 | int i_bitrate_avg; /* extracted from Xing header */ |
|---|
| | 63 | |
|---|
| | 64 | vlc_meta_t *meta; |
|---|
| 61 | 65 | |
|---|
| 62 | 66 | es_out_id_t *p_es; |
|---|
| … | … | |
| 166 | 170 | } |
|---|
| 167 | 171 | |
|---|
| 168 | | /* skip possible id3 header */ |
|---|
| | 172 | p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); |
|---|
| | 173 | p_sys->i_time = 1; |
|---|
| | 174 | p_sys->i_bitrate_avg = 0; |
|---|
| | 175 | p_sys->meta = NULL; |
|---|
| | 176 | |
|---|
| | 177 | /* skip/parse possible id3 header */ |
|---|
| 169 | 178 | if( ( p_id3 = module_Need( p_demux, "id3", NULL, 0 ) ) ) |
|---|
| 170 | 179 | { |
|---|
| | 180 | p_sys->meta = (vlc_meta_t *)p_demux->p_private; |
|---|
| | 181 | /* temporary */ |
|---|
| | 182 | msg_Dbg( p_demux, "Title : %s", |
|---|
| | 183 | vlc_meta_GetValue( p_sys->meta,VLC_META_TITLE ) ); |
|---|
| | 184 | p_demux->p_private = NULL; |
|---|
| 171 | 185 | module_Unneed( p_demux, p_id3 ); |
|---|
| 172 | 186 | } |
|---|
| … | … | |
| 210 | 224 | p_demux->pf_demux = Demux; |
|---|
| 211 | 225 | p_demux->pf_control = Control; |
|---|
| 212 | | p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); |
|---|
| 213 | | p_sys->i_time = 1; |
|---|
| 214 | | p_sys->i_bitrate_avg = 0; |
|---|
| 215 | 226 | |
|---|
| 216 | 227 | es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'm', 'p', 'g', 'a' ) ); |
|---|
| … | … | |
| 389 | 400 | { |
|---|
| 390 | 401 | demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 391 | | return demux2_vaControlHelper( p_demux->s, |
|---|
| 392 | | 0, -1, |
|---|
| 393 | | p_sys->i_bitrate_avg, 1, i_query, args ); |
|---|
| 394 | | } |
|---|
| 395 | | |
|---|
| | 402 | |
|---|
| | 403 | vlc_meta_t **pp_meta; |
|---|
| | 404 | |
|---|
| | 405 | switch( i_query ) |
|---|
| | 406 | { |
|---|
| | 407 | case DEMUX_GET_META: |
|---|
| | 408 | pp_meta = (vlc_meta_t **)va_arg( args, vlc_meta_t** ); |
|---|
| | 409 | *pp_meta = vlc_meta_Duplicate( p_sys->meta ); |
|---|
| | 410 | return VLC_SUCCESS; |
|---|
| | 411 | |
|---|
| | 412 | default: |
|---|
| | 413 | return demux2_vaControlHelper( p_demux->s, |
|---|
| | 414 | 0, -1, |
|---|
| | 415 | p_sys->i_bitrate_avg, 1, i_query, |
|---|
| | 416 | args ); |
|---|
| | 417 | } |
|---|
| | 418 | } |
|---|
| | 419 | |
|---|
| rd82e9eb |
r2d109a7 |
|
| 50 | 50 | static int SkipID3Tag( vlc_object_t *p_this ) |
|---|
| 51 | 51 | { |
|---|
| 52 | | input_thread_t *p_input = NULL; |
|---|
| | 52 | demux_t *p_demux = (demux_t *)p_this; |
|---|
| 53 | 53 | uint8_t *p_peek; |
|---|
| 54 | 54 | int i_size; |
|---|
| … | … | |
| 56 | 56 | int b_footer; |
|---|
| 57 | 57 | |
|---|
| 58 | | if ( p_this->i_object_type == VLC_OBJECT_INPUT ) |
|---|
| 59 | | { |
|---|
| 60 | | p_input = (input_thread_t *)p_this; |
|---|
| 61 | | } |
|---|
| 62 | | if( p_input == NULL ) |
|---|
| 63 | | { |
|---|
| 64 | | p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE ); |
|---|
| 65 | | if( p_input == NULL ) |
|---|
| 66 | | { |
|---|
| 67 | | return VLC_EGENERIC; |
|---|
| 68 | | } |
|---|
| 69 | | } |
|---|
| | 58 | p_demux->p_private = NULL; |
|---|
| 70 | 59 | |
|---|
| 71 | | msg_Dbg( p_input, "checking for ID3 tag" ); |
|---|
| | 60 | msg_Dbg( p_demux, "checking for ID3 tag" ); |
|---|
| 72 | 61 | |
|---|
| 73 | 62 | /* get 10 byte id3 header */ |
|---|
| 74 | | if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 ) |
|---|
| | 63 | if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) |
|---|
| 75 | 64 | { |
|---|
| 76 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| 77 | | vlc_object_release( p_input ); |
|---|
| | 65 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 78 | 66 | return VLC_EGENERIC; |
|---|
| 79 | 67 | } |
|---|
| … | … | |
| 81 | 69 | if( p_peek[0] != 'I' || p_peek[1] != 'D' || p_peek[2] != '3' ) |
|---|
| 82 | 70 | { |
|---|
| 83 | | vlc_object_release( p_input ); |
|---|
| 84 | 71 | return VLC_SUCCESS; |
|---|
| 85 | 72 | } |
|---|
| … | … | |
| 99 | 86 | |
|---|
| 100 | 87 | /* Skip the entire tag */ |
|---|
| 101 | | stream_Read( p_input->s, NULL, i_size ); |
|---|
| | 88 | stream_Read( p_demux->s, NULL, i_size ); |
|---|
| 102 | 89 | |
|---|
| 103 | | msg_Dbg( p_input, "ID3v2.%d revision %d tag found, skiping %d bytes", |
|---|
| | 90 | msg_Dbg( p_demux, "ID3v2.%d revision %d tag found, skiping %d bytes", |
|---|
| 104 | 91 | version, revision, i_size ); |
|---|
| 105 | 92 | |
|---|
| 106 | | vlc_object_release( p_input ); |
|---|
| 107 | 93 | return VLC_SUCCESS; |
|---|
| 108 | 94 | } |
|---|
| r562ab59 |
r2d109a7 |
|
| 32 | 32 | #include <vlc/input.h> |
|---|
| 33 | 33 | |
|---|
| 34 | | #include "ninput.h" |
|---|
| 35 | | |
|---|
| 36 | 34 | #include <sys/types.h> |
|---|
| | 35 | |
|---|
| | 36 | #include "vlc_meta.h" |
|---|
| 37 | 37 | |
|---|
| 38 | 38 | #include <id3tag.h> |
|---|
| … | … | |
| 60 | 60 | * ParseID3Tag : parse an id3tag into the info structures |
|---|
| 61 | 61 | *****************************************************************************/ |
|---|
| 62 | | static void ParseID3Tag( input_thread_t *p_input, uint8_t *p_data, int i_size ) |
|---|
| | 62 | static void ParseID3Tag( demux_t *p_demux, uint8_t *p_data, int i_size ) |
|---|
| 63 | 63 | { |
|---|
| 64 | 64 | struct id3_tag *p_id3_tag; |
|---|
| … | … | |
| 67 | 67 | vlc_value_t val; |
|---|
| 68 | 68 | int i; |
|---|
| | 69 | input_thread_t *p_input; |
|---|
| | 70 | |
|---|
| | 71 | p_input = vlc_object_find( p_demux, VLC_OBJECT_INPUT, |
|---|
| | 72 | FIND_PARENT ); |
|---|
| | 73 | if( !p_input) |
|---|
| | 74 | { |
|---|
| | 75 | return VLC_EGENERIC; |
|---|
| | 76 | } |
|---|
| 69 | 77 | |
|---|
| 70 | 78 | var_Get( p_input, "demuxed-id3", &val ); |
|---|
| 71 | 79 | if( val.b_bool ) |
|---|
| 72 | 80 | { |
|---|
| 73 | | msg_Dbg( p_input, "the ID3 tag was already parsed" ); |
|---|
| | 81 | msg_Dbg( p_demux, "the ID3 tag was already parsed" ); |
|---|
| 74 | 82 | return; |
|---|
| 75 | 83 | } |
|---|
| 76 | 84 | |
|---|
| 77 | 85 | val.b_bool = VLC_FALSE; |
|---|
| | 86 | |
|---|
| 78 | 87 | p_id3_tag = id3_tag_parse( p_data, i_size ); |
|---|
| 79 | 88 | i = 0; |
|---|
| … | … | |
| 93 | 102 | char *psz_endptr; |
|---|
| 94 | 103 | i_genre = strtol( psz_temp, &psz_endptr, 10 ); |
|---|
| 95 | | if( psz_temp != psz_endptr && i_genre >= 0 && i_genre < NUM_GENRES ) |
|---|
| 96 | | { |
|---|
| 97 | | input_Control( p_input, INPUT_ADD_INFO, "ID3", |
|---|
| 98 | | (char *)p_frame->description, |
|---|
| 99 | | ppsz_genres[atoi(psz_temp)]); |
|---|
| | 104 | if( psz_temp != psz_endptr && i_genre >= 0 && |
|---|
| | 105 | i_genre < NUM_GENRES ) |
|---|
| | 106 | { |
|---|
| | 107 | vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, |
|---|
| | 108 | VLC_META_GENRE, ppsz_genres[atoi(psz_temp)]); |
|---|
| 100 | 109 | } |
|---|
| 101 | 110 | else |
|---|
| 102 | 111 | { |
|---|
| 103 | | input_Control( p_input, INPUT_ADD_INFO, "ID3", |
|---|
| 104 | | (char *)p_frame->description, psz_temp); |
|---|
| | 112 | /* Unknown genre */ |
|---|
| | 113 | vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, |
|---|
| | 114 | VLC_META_GENRE, psz_temp ); |
|---|
| 105 | 115 | } |
|---|
| 106 | 116 | } |
|---|
| 107 | 117 | else if ( !strcmp(p_frame->id, ID3_FRAME_TITLE ) ) |
|---|
| 108 | 118 | { |
|---|
| 109 | | input_Control( p_input, INPUT_SET_NAME, psz_temp ); |
|---|
| 110 | | input_Control( p_input, INPUT_ADD_INFO, "ID3", |
|---|
| 111 | | (char *)p_frame->description, psz_temp ); |
|---|
| | 119 | vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, |
|---|
| | 120 | VLC_META_TITLE, psz_temp ); |
|---|
| | 121 | // input_Control( p_demux, INPUT_SET_NAME, psz_temp ); |
|---|
| 112 | 122 | } |
|---|
| 113 | 123 | else if ( !strcmp(p_frame->id, ID3_FRAME_ARTIST ) ) |
|---|
| 114 | 124 | { |
|---|
| 115 | | input_Control( p_input, INPUT_ADD_INFO, |
|---|
| 116 | | _("General"), _("Author"), psz_temp ); |
|---|
| 117 | | input_Control( p_input, INPUT_ADD_INFO, "ID3", |
|---|
| 118 | | (char *)p_frame->description, psz_temp ); |
|---|
| | 125 | vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, |
|---|
| | 126 | VLC_META_ARTIST, psz_temp ); |
|---|
| 119 | 127 | } |
|---|
| 120 | 128 | else |
|---|
| 121 | 129 | { |
|---|
| 122 | | input_Control( p_input, INPUT_ADD_INFO, "ID3", |
|---|
| | 130 | /* Unknown meta info */ |
|---|
| | 131 | vlc_meta_Add( (vlc_meta_t *)p_demux->p_private, |
|---|
| 123 | 132 | (char *)p_frame->description, psz_temp ); |
|---|
| 124 | 133 | } |
|---|
| … | … | |
| 130 | 139 | |
|---|
| 131 | 140 | val.b_bool = VLC_TRUE; |
|---|
| 132 | | var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL ); |
|---|
| | 141 | var_Change( p_demux, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL ); |
|---|
| | 142 | |
|---|
| | 143 | vlc_object_release( p_input ); |
|---|
| 133 | 144 | } |
|---|
| 134 | 145 | |
|---|
| … | … | |
| 139 | 150 | static int ParseID3Tags( vlc_object_t *p_this ) |
|---|
| 140 | 151 | { |
|---|
| 141 | | input_thread_t *p_input = NULL; |
|---|
| | 152 | demux_t *p_demux = (demux_t *)p_this; |
|---|
| 142 | 153 | uint8_t *p_peek; |
|---|
| 143 | 154 | int i_size; |
|---|
| 144 | 155 | int i_size2; |
|---|
| 145 | | |
|---|
| 146 | | if ( p_this->i_object_type == VLC_OBJECT_INPUT ) |
|---|
| 147 | | { |
|---|
| 148 | | p_input = (input_thread_t *)p_this; |
|---|
| 149 | | } |
|---|
| 150 | | if( p_input == NULL ) |
|---|
| 151 | | { |
|---|
| 152 | | p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE ); |
|---|
| 153 | | if( p_input == NULL ) |
|---|
| 154 | | { |
|---|
| 155 | | return VLC_EGENERIC; |
|---|
| 156 | | } |
|---|
| 157 | | } |
|---|
| 158 | | |
|---|
| 159 | | msg_Dbg( p_input, "checking for ID3 tag" ); |
|---|
| 160 | | |
|---|
| 161 | | if ( p_input->stream.b_seekable && |
|---|
| 162 | | p_input->stream.i_method != INPUT_METHOD_NETWORK ) |
|---|
| 163 | | { |
|---|
| | 156 | vlc_bool_t b_seekable; |
|---|
| | 157 | |
|---|
| | 158 | p_demux->p_private = (void *)vlc_meta_New(); |
|---|
| | 159 | |
|---|
| | 160 | msg_Dbg( p_demux, "checking for ID3 tag" ); |
|---|
| | 161 | |
|---|
| | 162 | stream_Control( p_demux->s, STREAM_CAN_FASTSEEK, &b_seekable ); |
|---|
| | 163 | if( b_seekable ) |
|---|
| | 164 | { |
|---|
| | 165 | int64_t i_init; |
|---|
| 164 | 166 | int64_t i_pos; |
|---|
| 165 | 167 | |
|---|
| 166 | 168 | /*look for a ID3v1 tag at the end of the file*/ |
|---|
| 167 | | i_pos = stream_Size( p_input->s ); |
|---|
| | 169 | i_init = stream_Tell( p_demux->s ); |
|---|
| | 170 | i_pos = stream_Size( p_demux->s ); |
|---|
| 168 | 171 | |
|---|
| 169 | 172 | if ( i_pos >128 ) |
|---|
| 170 | 173 | { |
|---|
| 171 | | input_AccessReinit( p_input ); |
|---|
| 172 | | p_input->pf_seek( p_input, i_pos - 128 ); |
|---|
| | 174 | stream_Seek( p_demux->s, i_pos - 128 ); |
|---|
| 173 | 175 | |
|---|
| 174 | 176 | /* get 10 byte id3 header */ |
|---|
| 175 | | if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 ) |
|---|
| 176 | | { |
|---|
| 177 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| 178 | | vlc_object_release( p_input ); |
|---|
| | 177 | if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) |
|---|
| | 178 | { |
|---|
| | 179 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 179 | 180 | return( VLC_EGENERIC ); |
|---|
| 180 | 181 | } |
|---|
| … | … | |
| 184 | 185 | { |
|---|
| 185 | 186 | /* peek the entire tag */ |
|---|
| 186 | | if ( stream_Peek( p_input->s, &p_peek, i_size2 ) < i_size2 ) |
|---|
| 187 | | { |
|---|
| 188 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| 189 | | vlc_object_release( p_input ); |
|---|
| | 187 | if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 ) |
|---|
| | 188 | { |
|---|
| | 189 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 190 | 190 | return( VLC_EGENERIC ); |
|---|
| 191 | 191 | } |
|---|
| 192 | | msg_Dbg( p_input, "found ID3v1 tag" ); |
|---|
| 193 | | ParseID3Tag( p_input, p_peek, i_size2 ); |
|---|
| | 192 | msg_Dbg( p_demux, "found ID3v1 tag" ); |
|---|
| | 193 | ParseID3Tag( p_demux, p_peek, i_size2 ); |
|---|
| 194 | 194 | } |
|---|
| 195 | 195 | |
|---|
| 196 | 196 | /* look for ID3v2.4 tag at end of file */ |
|---|
| 197 | 197 | /* get 10 byte ID3 footer */ |
|---|
| 198 | | if( stream_Peek( p_input->s, &p_peek, 128 ) < 128 ) |
|---|
| 199 | | { |
|---|
| 200 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| 201 | | vlc_object_release( p_input ); |
|---|
| | 198 | if( stream_Peek( p_demux->s, &p_peek, 128 ) < 128 ) |
|---|
| | 199 | { |
|---|
| | 200 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 202 | 201 | return( VLC_EGENERIC ); |
|---|
| 203 | 202 | } |
|---|
| … | … | |
| 205 | 204 | if ( i_size2 < 0 && i_pos > -i_size2 ) |
|---|
| 206 | 205 | { /* id3v2.4 footer found */ |
|---|
| 207 | | input_AccessReinit( p_input ); |
|---|
| 208 | | p_input->pf_seek( p_input, i_pos + i_size2 ); |
|---|
| | 206 | stream_Seek( p_demux->s , i_pos + i_size2 ); |
|---|
| 209 | 207 | /* peek the entire tag */ |
|---|
| 210 | | if ( stream_Peek( p_input->s, &p_peek, i_size2 ) < i_size2 ) |
|---|
| 211 | | { |
|---|
| 212 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| 213 | | vlc_object_release( p_input ); |
|---|
| | 208 | if ( stream_Peek( p_demux->s, &p_peek, i_size2 ) < i_size2 ) |
|---|
| | 209 | { |
|---|
| | 210 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 214 | 211 | return( VLC_EGENERIC ); |
|---|
| 215 | 212 | } |
|---|
| 216 | | msg_Dbg( p_input, "found ID3v2 tag at end of file" ); |
|---|
| 217 | | ParseID3Tag( p_input, p_peek, i_size2 ); |
|---|
| | 213 | msg_Dbg( p_demux, "found ID3v2 tag at end of file" ); |
|---|
| | 214 | ParseID3Tag( p_demux, p_peek, i_size2 ); |
|---|
| 218 | 215 | } |
|---|
| 219 | 216 | } |
|---|
| 220 | | input_AccessReinit( p_input ); |
|---|
| 221 | | p_input->pf_seek( p_input, 0 ); |
|---|
| | 217 | stream_Seek( p_demux->s, i_init ); |
|---|
| 222 | 218 | } |
|---|
| 223 | 219 | /* get 10 byte id3 header */ |
|---|
| 224 | | if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 ) |
|---|
| 225 | | { |
|---|
| 226 | | msg_Err( p_input, "cannot peek()" ); |
|---|
| 227 | | vlc_object_release( p_input ); |
|---|
| | 220 | if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) |
|---|
| | 221 | { |
|---|
| | 222 | msg_Err( p_demux, "cannot peek()" ); |
|---|
| 228 | 223 | return( VLC_EGENERIC ); |
|---|
| 229 | 224 | } |
|---|
| … | … | |
| 232 | 227 | if ( i_size <= 0 ) |
|---|
| 233 | 228 | { |
|---|
| 234 | | vlc_object_release( p_input ); |
|---|
| 235 | 229 | return( VLC_SUCCESS ); |
|---|
| 236 | 230 | } |
|---|
| … | … | |
| 238 | 232 | /* Read the entire tag */ |
|---|
| 239 | 233 | p_peek = malloc( i_size ); |
|---|
| 240 | | if( !p_peek || stream_Read( p_input->s, p_peek, i_size ) < i_size ) |
|---|
| 241 | | { |
|---|
| 242 | | msg_Err( p_input, "cannot read ID3 tag" ); |
|---|
| | 234 | if( !p_peek || stream_Read( p_demux->s, p_peek, i_size ) < i_size ) |
|---|
| | 235 | { |
|---|
| | 236 | msg_Err( p_demux, "cannot read ID3 tag" ); |
|---|
| 243 | 237 | if( p_peek ) free( p_peek ); |
|---|
| 244 | | vlc_object_release( p_input ); |
|---|
| 245 | 238 | return( VLC_EGENERIC ); |
|---|
| 246 | 239 | } |
|---|
| 247 | 240 | |
|---|
| 248 | | ParseID3Tag( p_input, p_peek, i_size ); |
|---|
| 249 | | msg_Dbg( p_input, "found ID3v2 tag" ); |
|---|
| | 241 | ParseID3Tag( p_demux, p_peek, i_size ); |
|---|
| | 242 | msg_Dbg( p_demux, "found ID3v2 tag" ); |
|---|
| 250 | 243 | |
|---|
| 251 | 244 | free( p_peek ); |
|---|
| 252 | | vlc_object_release( p_input ); |
|---|
| 253 | 245 | return( VLC_SUCCESS ); |
|---|
| 254 | 246 | } |
|---|