]> git.sesse.net Git - vlc/blob - modules/demux/util/id3.c
* when you use object_find you need to do a object_release as well
[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.8 2004/03/03 11:38:14 fenrir 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 "ninput.h"
34
35 #include <sys/types.h>
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40 static int  SkipID3Tag ( vlc_object_t * );
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  * SkipID3Tag : check if an ID3 tag is present, and skip it if it is
53  ****************************************************************************/
54 static int SkipID3Tag( vlc_object_t *p_this )
55 {
56     input_thread_t *p_input = NULL;
57     uint8_t *p_peek;
58     int i_size;
59     uint8_t version, revision;
60     int b_footer;
61
62     if ( p_this->i_object_type == VLC_OBJECT_INPUT )
63     {
64         p_input = (input_thread_t *)p_this;
65     }
66     if( p_input == NULL )
67     {
68         p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
69         if( p_input == NULL )
70         {
71             return VLC_EGENERIC;
72         }
73     }
74
75     msg_Dbg( p_input, "checking for ID3 tag" );
76
77     /* get 10 byte id3 header */
78     if( stream_Peek( p_input->s, &p_peek, 10 ) < 10 )
79     {
80         msg_Err( p_input, "cannot peek()" );
81         vlc_object_release( p_input );
82         return VLC_EGENERIC;
83     }
84
85     if( p_peek[0] != 'I' || p_peek[1] != 'D' || p_peek[2] != '3' )
86     {
87         vlc_object_release( p_input );
88         return VLC_SUCCESS;
89     }
90
91     version = p_peek[3];  /* These may become usfull later, */
92     revision = p_peek[4]; /* but we ignore them for now */
93     b_footer = p_peek[5] & 0x10;
94     i_size = (p_peek[6] << 21) +
95              (p_peek[7] << 14) +
96              (p_peek[8] << 7) +
97              p_peek[9];
98     if ( b_footer )
99     {
100         i_size += 10;
101     }
102     i_size += 10;
103
104     /* Skip the entire tag */
105     stream_Read( p_input->s, NULL, i_size );
106
107     msg_Dbg( p_input, "ID3v2.%d revision %d tag found, skiping %d bytes",
108              version, revision, i_size );
109
110     vlc_object_release( p_input );
111     return VLC_SUCCESS;
112 }