]> git.sesse.net Git - vlc/blob - modules/demux/util/id3.c
* modules/*: sanitization of the modules description strings.
[vlc] / modules / demux / util / id3.c
1 /*****************************************************************************
2  * id3.c: simple id3 tag skipper
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: id3.c,v 1.3 2003/02/20 01:52:46 sigmunau Exp $
6  *
7  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32
33 #include <sys/types.h>
34
35 /*****************************************************************************
36  * Local prototypes
37  *****************************************************************************/
38 static int  SkipID3Tag ( vlc_object_t * );
39
40 /* TODO: support MPEG-2.5, not difficult, but I need somes samples... */
41
42 /*****************************************************************************
43  * Module descriptor
44  *****************************************************************************/
45 vlc_module_begin();
46     set_description( _("Simple id3 tag skipper" ) );
47     set_capability( "id3", 50 );
48     set_callbacks( SkipID3Tag, NULL );
49 vlc_module_end();
50
51 /*****************************************************************************
52  * Definitions of structures  and functions used by this plugins 
53  *****************************************************************************/
54
55
56 /****************************************************************************
57  * ParseID3Tag : check if an ID3 header is present and parse and skip it
58  ****************************************************************************
59  *
60  * Author : Sigmund Augdal 
61  * 
62 ' ****************************************************************************/
63 static int SkipID3Tag( vlc_object_t *p_this )
64 {
65     input_thread_t *p_input;
66     u8  *p_peek;
67     int i_size;
68     u8  version, revision;
69     int b_footer;
70
71     if ( p_this->i_object_type != VLC_OBJECT_INPUT )
72     {
73         return( VLC_EGENERIC );
74     }
75     p_input = (input_thread_t *)p_this;
76
77     msg_Dbg( p_input, "Checking for ID3 tag" );
78     /* get 10 byte id3 header */    
79     if( input_Peek( p_input, &p_peek, 10 ) < 10 )
80     {
81         msg_Err( p_input, "cannot peek()" );
82         return( VLC_EGENERIC );
83     }
84
85     if ( !( (p_peek[0] == 0x49) && (p_peek[1] == 0x44) && (p_peek[2] == 0x33)))
86     {
87         return( VLC_SUCCESS );
88     }
89     
90     version = p_peek[3];  /* These may become usfull later, */
91     revision = p_peek[4]; /* but we ignore them for now */
92     b_footer = p_peek[5] & 0x10;
93     i_size = (p_peek[6] << 21) +
94              (p_peek[7] << 14) +
95              (p_peek[8] << 7) +
96              p_peek[9];
97     if ( b_footer )
98     {
99         i_size += 10;
100     }
101     i_size += 10;
102
103     /* peek the entire tag */
104     if ( input_Peek( p_input, &p_peek, i_size ) < i_size )
105     {
106         msg_Err( p_input, "cannot peek()" );
107         return( VLC_EGENERIC );
108     }
109
110     msg_Dbg( p_input, "ID3v2.%d revision %d tag found, skiping %d bytes",
111              version, revision, i_size );
112     p_input->p_current_data += i_size; /* seek passed end of ID3 tag */
113     return ( VLC_SUCCESS );
114 }