xine-lib  1.2.10
id3.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2008 the xine project
3  *
4  * This file is part of xine, a free video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  *
20  * ID3 tag parser
21  *
22  * Supported versions: v1, v1.1, v2.2, v2.3, v2.4
23  */
24 
25 #ifndef ID3_H
26 #define ID3_H
27 
28 #include <xine/xine_internal.h>
29 #include <xine/xineutils.h>
30 #include "bswap.h"
31 
32 /* id3v2 */
33 #define ID3V22_TAG ME_FOURCC('I', 'D', '3', 2) /* id3 v2.2 header tag */
34 #define ID3V23_TAG ME_FOURCC('I', 'D', '3', 3) /* id3 v2.3 header tag */
35 #define ID3V24_TAG ME_FOURCC('I', 'D', '3', 4) /* id3 v2.4 header tag */
36 #define ID3V24_FOOTER_TAG ME_FOURCC('3', 'D', 'I', 0) /* id3 v2.4 footer tag */
37 
38 #define ID3V2X_TAG ME_FOURCC('I', 'D', '3', 0) /* id3 v2.x header tag */
39 #define ID3V2X_MASK ~ME_FOURCC( 0 , 0 , 0 , 0xFF) /* id3 v2.x header mask */
40 
41 /*
42  * ID3 v2.2
43  */
44 /* tag header */
45 #define ID3V22_UNSYNCH_FLAG 0x80
46 #define ID3V22_COMPRESS_FLAG 0x40
47 #define ID3V22_ZERO_FLAG 0x3F
48 
49 /* frame header */
50 #define ID3V22_FRAME_HEADER_SIZE 6
51 
52 /*
53  * ID3 v2.3
54  */
55 /* tag header */
56 #define ID3V23_UNSYNCH_FLAG 0x80
57 #define ID3V23_EXT_HEADER_FLAG 0x40
58 #define ID3V23_EXPERIMENTAL_FLAG 0x20
59 #define ID3V23_ZERO_FLAG 0x1F
60 
61 /* frame header */
62 #define ID3V23_FRAME_HEADER_SIZE 10
63 #define ID3V23_FRAME_TAG_PRESERV_FLAG 0x8000
64 #define ID3V23_FRAME_FILE_PRESERV_FLAG 0x4000
65 #define ID3V23_FRAME_READ_ONLY_FLAG 0x2000
66 #define ID3V23_FRAME_COMPRESS_FLAG 0x0080
67 #define ID3V23_FRAME_ENCRYPT_FLAG 0x0040
68 #define ID3V23_FRAME_GROUP_ID_FLAG 0x0020
69 #define ID3V23_FRAME_ZERO_FLAG 0x1F1F
70 
71 /*
72  * ID3 v2.4
73  */
74 /* tag header */
75 #define ID3V24_UNSYNCH_FLAG 0x80
76 #define ID3V24_EXT_HEADER_FLAG 0x40
77 #define ID3V24_EXPERIMENTAL_FLAG 0x20
78 #define ID3V24_FOOTER_FLAG 0x10
79 #define ID3V24_ZERO_FLAG 0x0F
80 
81 /* extended header */
82 #define ID3V24_EXT_UPDATE_FLAG 0x40
83 #define ID3V24_EXT_CRC_FLAG 0x20
84 #define ID3V24_EXT_RESTRICTIONS_FLAG 0x10
85 #define ID3V24_EXT_ZERO_FLAG 0x8F
86 
87 /* frame header */
88 #define ID3V24_FRAME_HEADER_SIZE 10
89 #define ID3V24_FRAME_TAG_PRESERV_FLAG 0x4000
90 #define ID3V24_FRAME_FILE_PRESERV_FLAG 0x2000
91 #define ID3V24_FRAME_READ_ONLY_FLAG 0x1000
92 #define ID3V24_FRAME_GROUP_ID_FLAG 0x0040
93 #define ID3V24_FRAME_COMPRESS_FLAG 0x0008
94 #define ID3V24_FRAME_ENCRYPT_FLAG 0x0004
95 #define ID3V24_FRAME_UNSYNCH_FLAG 0x0002
96 #define ID3V24_FRAME_DATA_LEN_FLAG 0x0001
97 #define ID3V24_FRAME_ZERO_FLAG 0x8FB0
98 
99 /* footer */
100 #define ID3V24_FOOTER_SIZE 10
101 
102 
103 typedef struct {
104  uint32_t id;
105  uint8_t revision;
106  uint8_t flags;
107  size_t size;
109 
110 typedef struct {
111  uint32_t id;
112  size_t size;
114 
115 typedef struct {
116  uint32_t id;
117  size_t size;
118  uint16_t flags;
120 
121 typedef struct {
122  size_t size;
123  uint16_t flags;
124  uint32_t padding_size;
125  uint32_t crc;
127 
129 
130 typedef struct {
131  uint32_t id;
132  size_t size;
133  uint16_t flags;
135 
136 typedef struct {
137  size_t size;
138  uint8_t flags;
139  uint32_t crc;
140  uint8_t restrictions;
142 
143 typedef struct {
144  char tag[3];
145  char title[30];
146  char artist[30];
147  char album[30];
148  char year[4];
149  char comment[30];
150  uint8_t genre;
151 } id3v1_tag_t;
152 
154 
166  xine_stream_t *stream,
167  uint32_t id3_signature);
168 
173 static inline int id3v2_istag(uint32_t id3_signature) {
174  return (id3_signature & ID3V2X_MASK) == ID3V2X_TAG;
175 }
176 
177 #if 0
178 /* parse an unsynchronized 16bits integer */
179 static inline uint16_t _X_BE_16_synchsafe(uint8_t buf[2]) {
180  return ((uint16_t)(buf[0] & 0x7F) << 7) |
181  (uint16_t)(buf[1] & 0x7F);
182 }
183 #endif
184 
185 /* parse an unsynchronized 24bits integer */
186 static inline uint32_t _X_BE_24_synchsafe(uint8_t buf[3]) {
187  return ((uint32_t)(buf[0] & 0x7F) << 14) |
188  ((uint32_t)(buf[1] & 0x7F) << 7) |
189  (uint32_t)(buf[2] & 0x7F);
190 }
191 
192 /* parse an unsynchronized 32bits integer */
193 static inline uint32_t _X_BE_32_synchsafe(uint8_t buf[4]) {
194  return ((uint32_t)(buf[0] & 0x7F) << 21) |
195  ((uint32_t)(buf[1] & 0x7F) << 14) |
196  ((uint32_t)(buf[2] & 0x7F) << 7) |
197  (uint32_t)(buf[3] & 0x7F);
198 }
199 
200 /* parse an unsynchronized 35bits integer */
201 static inline uint32_t BE_35_synchsafe(uint8_t buf[5]) {
202  return ((uint32_t)(buf[0] & 0x07) << 28) |
203  ((uint32_t)(buf[1] & 0x7F) << 21) |
204  ((uint32_t)(buf[2] & 0x7F) << 14) |
205  ((uint32_t)(buf[3] & 0x7F) << 7) |
206  (uint32_t)(buf[4] & 0x7F);
207 }
208 
209 #endif /* ID3_H */
ID3V23_EXT_HEADER_FLAG
#define ID3V23_EXT_HEADER_FLAG
Definition: id3.h:57
xine_stream_s::xine
xine_t * xine
Definition: xine_internal.h:126
ID3V22_FRAME_HEADER_SIZE
#define ID3V22_FRAME_HEADER_SIZE
Definition: id3.h:50
id3v24_interp_frame
static int id3v24_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v24_frame_header_t *frame_header)
Definition: id3.c:733
_X_BE_24_synchsafe
static uint32_t _X_BE_24_synchsafe(uint8_t buf[3])
Definition: id3.h:186
xine_stream_s
Definition: xine_internal.h:123
id3v2_parse_tag
int id3v2_parse_tag(input_plugin_t *input, xine_stream_t *stream, uint32_t id3_signature)
Generic function for ID3v2 tags parsing.
Definition: id3.c:885
id3v23_parse_tag
static int id3v23_parse_tag(input_plugin_t *input, xine_stream_t *stream, uint32_t id3_signature)
Definition: id3.c:541
xineutils.h
id3v24_frame_ext_header_t::restrictions
uint8_t restrictions
Definition: id3.h:140
ID3V24_FRAME_HEADER_SIZE
#define ID3V24_FRAME_HEADER_SIZE
Definition: id3.h:88
id3v24_footer_t
id3v2_header_t id3v24_footer_t
Definition: id3.h:128
id3v23_frame_ext_header_t::size
size_t size
Definition: id3.h:122
ID3V24_ZERO_FLAG
#define ID3V24_ZERO_FLAG
Definition: id3.h:79
id3v2_parse_header
static int id3v2_parse_header(input_plugin_t *input, uint32_t id3_signature, id3v2_header_t *tag_header)
Definition: id3.c:230
_x_meta_info_set_generic
void _x_meta_info_set_generic(xine_stream_t *s, int info, const char *str, const char *enc)
Definition: info_helper.c:331
id3v24_parse_tag
static int id3v24_parse_tag(input_plugin_t *input, xine_stream_t *stream, uint32_t id3_signature)
Definition: id3.c:810
id3v23_frame_ext_header_t::flags
uint16_t flags
Definition: id3.h:123
id3v24_parse_ext_header
static int id3v24_parse_ext_header(input_plugin_t *input, id3v24_frame_ext_header_t *frame_ext_header)
Definition: id3.c:649
_x_meta_info_set
void _x_meta_info_set(xine_stream_t *s, int info, const char *str)
Definition: info_helper.c:321
id3_encoding
static const char id3_encoding[][12]
Definition: id3.c:84
id3v1_tag_t
Definition: id3.h:143
ID3V24_EXT_UPDATE_FLAG
#define ID3V24_EXT_UPDATE_FLAG
Definition: id3.h:82
be2me_32
#define be2me_32(x)
Definition: ffmpeg_bswap.h:168
id3v2_header_t
Definition: id3.h:103
ID3V2X_MASK
#define ID3V2X_MASK
Definition: id3.h:39
ID3V24_EXT_CRC_FLAG
#define ID3V24_EXT_CRC_FLAG
Definition: id3.h:83
ID3_GENRE_COUNT
#define ID3_GENRE_COUNT
Definition: id3.c:50
id3v2_header_t::flags
uint8_t flags
Definition: id3.h:106
id3v23_interp_frame
static int id3v23_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v23_frame_header_t *frame_header)
Definition: id3.c:468
lprintf
#define lprintf(...)
Definition: xineutils.h:620
id3v22_interp_frame
static int id3v22_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v22_frame_header_t *frame_header)
Definition: id3.c:271
ID3V24_EXT_RESTRICTIONS_FLAG
#define ID3V24_EXT_RESTRICTIONS_FLAG
Definition: id3.h:84
id3v1_tag_t::genre
uint8_t genre
Definition: id3.h:150
ID3V23_ZERO_FLAG
#define ID3V23_ZERO_FLAG
Definition: id3.h:59
id3v22_frame_header_t
Definition: id3.h:110
id3v2_header_t::id
uint32_t id
Definition: id3.h:104
ID3V24_TAG
#define ID3V24_TAG
Definition: id3.h:35
_X_BE_16
#define _X_BE_16(x)
Definition: bswap.h:40
ID3V23_UNSYNCH_FLAG
#define ID3V23_UNSYNCH_FLAG
Definition: id3.h:56
ID3V24_EXPERIMENTAL_FLAG
#define ID3V24_EXPERIMENTAL_FLAG
Definition: id3.h:77
ID3V23_FRAME_HEADER_SIZE
#define ID3V23_FRAME_HEADER_SIZE
Definition: id3.h:62
ID3V23_TAG
#define ID3V23_TAG
Definition: id3.h:34
XINE_META_INFO_TRACK_NUMBER
#define XINE_META_INFO_TRACK_NUMBER
Definition: xine.h:1073
ID3V24_FOOTER_SIZE
#define ID3V24_FOOTER_SIZE
Definition: id3.h:100
id3v23_frame_header_t
Definition: id3.h:115
ID3V24_FOOTER_FLAG
#define ID3V24_FOOTER_FLAG
Definition: id3.h:78
id3v2_header_t::size
size_t size
Definition: id3.h:107
id3_genre
static const char id3_genre[][24]
Definition: id3.c:51
XINE_VERBOSITY_LOG
#define XINE_VERBOSITY_LOG
Definition: xine.h:425
id3v22_frame_header_t::id
uint32_t id
Definition: id3.h:111
_x_assert
#define _x_assert(exp)
Definition: xineutils.h:550
ID3V22_UNSYNCH_FLAG
#define ID3V22_UNSYNCH_FLAG
Definition: id3.h:45
XINE_META_INFO_ALBUM
#define XINE_META_INFO_ALBUM
Definition: xine.h:1066
id3v23_frame_ext_header_t
Definition: id3.h:121
id3v22_parse_frame_header
static int id3v22_parse_frame_header(input_plugin_t *input, id3v22_frame_header_t *frame_header)
Definition: id3.c:251
ID3V22_COMPRESS_FLAG
#define ID3V22_COMPRESS_FLAG
Definition: id3.h:46
id3v24_frame_header_t
Definition: id3.h:130
id3v23_frame_ext_header_t::crc
uint32_t crc
Definition: id3.h:125
input_plugin_s
Definition: input_plugin.h:90
id3v24_frame_header_t::flags
uint16_t flags
Definition: id3.h:133
XINE_META_INFO_ARTIST
#define XINE_META_INFO_ARTIST
Definition: xine.h:1064
id3v2_parse_tag
int id3v2_parse_tag(input_plugin_t *input, xine_stream_t *stream, uint32_t id3_signature)
Generic function for ID3v2 tags parsing.
Definition: id3.c:885
ID3_ENCODING_COUNT
#define ID3_ENCODING_COUNT
Definition: id3.c:83
XINE_META_INFO_YEAR
#define XINE_META_INFO_YEAR
Definition: xine.h:1067
id3v2_header_t::revision
uint8_t revision
Definition: id3.h:105
id3v24_frame_header_t::id
uint32_t id
Definition: id3.h:131
XINE_VERBOSITY_DEBUG
#define XINE_VERBOSITY_DEBUG
Definition: xine.h:426
id3v2_istag
static int id3v2_istag(uint32_t id3_signature)
Checks if the given buffer is an ID3 tag preamble.
Definition: id3.h:173
id3v24_parse_genre
static int id3v24_parse_genre(char *dest, const char *src, size_t len)
Definition: id3.c:615
id3v23_frame_header_t::id
uint32_t id
Definition: id3.h:116
XINE_META_INFO_COMMENT
#define XINE_META_INFO_COMMENT
Definition: xine.h:1063
XINE_META_INFO_DISCNUMBER
#define XINE_META_INFO_DISCNUMBER
Definition: xine.h:1090
id3v22_parse_tag
static int id3v22_parse_tag(input_plugin_t *input, xine_stream_t *stream, uint32_t id3_signature)
Definition: id3.c:341
LOG_MODULE
#define LOG_MODULE
Definition: id3.c:39
id3v22_frame_header_t::size
size_t size
Definition: id3.h:112
id3v23_frame_header_t::flags
uint16_t flags
Definition: id3.h:118
ID3V22_ZERO_FLAG
#define ID3V22_ZERO_FLAG
Definition: id3.h:47
XINE_META_INFO_GENRE
#define XINE_META_INFO_GENRE
Definition: xine.h:1065
id3v24_frame_ext_header_t
Definition: id3.h:136
id3v23_frame_header_t::size
size_t size
Definition: id3.h:117
id3v24_frame_header_t::size
size_t size
Definition: id3.h:132
id3v23_frame_ext_header_t::padding_size
uint32_t padding_size
Definition: id3.h:124
ID3V2X_TAG
#define ID3V2X_TAG
Definition: id3.h:38
bswap.h
_X_BE_32
#define _X_BE_32(x)
Definition: bswap.h:45
xine_internal.h
_x_meta_info_n_set
void _x_meta_info_n_set(xine_stream_t *s, int info, const char *buf, int len)
Definition: info_helper.c:351
_X_BE_24
#define _X_BE_24(x)
Definition: bswap.h:42
ID3V24_EXT_ZERO_FLAG
#define ID3V24_EXT_ZERO_FLAG
Definition: id3.h:85
config.h
ID3V24_EXT_HEADER_FLAG
#define ID3V24_EXT_HEADER_FLAG
Definition: id3.h:76
ID3V24_UNSYNCH_FLAG
#define ID3V24_UNSYNCH_FLAG
Definition: id3.h:75
id3v1_parse_tag
int id3v1_parse_tag(input_plugin_t *input, xine_stream_t *stream)
Definition: id3.c:90
id3v24_frame_ext_header_t::size
size_t size
Definition: id3.h:137
id3v24_frame_ext_header_t::flags
uint8_t flags
Definition: id3.h:138
ID3V22_TAG
#define ID3V22_TAG
Definition: id3.h:33
id3.h
input
static int input(void)
Definition: goomsl_lex.c:1495
id3v2_parse_genre
static int id3v2_parse_genre(char *dest, const char *src, size_t len)
Definition: id3.c:123
_X_BE_32_synchsafe
static uint32_t _X_BE_32_synchsafe(uint8_t buf[4])
Definition: id3.h:193
id3v24_parse_frame_header
static int id3v24_parse_frame_header(input_plugin_t *input, id3v24_frame_header_t *frame_header)
Definition: id3.c:629
id3v23_parse_frame_ext_header
static int id3v23_parse_frame_ext_header(input_plugin_t *input, id3v23_frame_ext_header_t *frame_ext_header)
Definition: id3.c:432
id3v24_frame_ext_header_t::crc
uint32_t crc
Definition: id3.h:139
xprintf
#define xprintf(xine, verbose,...)
Definition: xineutils.h:664
id3v23_parse_frame_header
static int id3v23_parse_frame_header(input_plugin_t *input, id3v23_frame_header_t *frame_header)
Definition: id3.c:412
XINE_META_INFO_TITLE
#define XINE_META_INFO_TITLE
Definition: xine.h:1062
BE_FOURCC
#define BE_FOURCC(ch0, ch1, ch2, ch3)
Definition: bswap.h:133
id3v1_parse_tag
int id3v1_parse_tag(input_plugin_t *input, xine_stream_t *stream)
Definition: id3.c:90
BE_35_synchsafe
static uint32_t BE_35_synchsafe(uint8_t buf[5])
Definition: id3.h:201