xine-lib  1.2.9
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 */
uint32_t padding_size
Definition: id3.h:124
size_t size
Definition: id3.h:137
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:853
static uint32_t BE_35_synchsafe(uint8_t buf[5])
Definition: id3.h:201
Definition: id3.h:130
uint16_t flags
Definition: id3.h:118
#define ID3V2X_MASK
Definition: id3.h:39
size_t size
Definition: id3.h:132
Definition: id3.h:103
uint8_t restrictions
Definition: id3.h:140
uint32_t crc
Definition: id3.h:125
uint8_t flags
Definition: id3.h:106
uint16_t flags
Definition: id3.h:123
static int id3v2_istag(uint32_t id3_signature)
Checks if the given buffer is an ID3 tag preamble.
Definition: id3.h:173
size_t size
Definition: id3.h:107
static uint32_t _X_BE_24_synchsafe(uint8_t buf[3])
Definition: id3.h:186
uint32_t id
Definition: id3.h:104
uint8_t genre
Definition: id3.h:150
uint32_t id
Definition: id3.h:116
Definition: id3.h:115
size_t size
Definition: id3.h:112
Definition: id3.h:110
uint8_t revision
Definition: id3.h:105
Definition: id3.h:143
Definition: xine_internal.h:210
uint32_t id
Definition: id3.h:131
static int input(void)
Definition: goomsl_lex.c:1495
size_t size
Definition: id3.h:122
#define ID3V2X_TAG
Definition: id3.h:38
Definition: input_plugin.h:92
Definition: id3.h:136
Definition: id3.h:121
static uint32_t _X_BE_32_synchsafe(uint8_t buf[4])
Definition: id3.h:193
uint16_t flags
Definition: id3.h:133
uint8_t flags
Definition: id3.h:138
uint32_t id
Definition: id3.h:111
id3v2_header_t id3v24_footer_t
Definition: id3.h:128
int id3v1_parse_tag(input_plugin_t *input, xine_stream_t *stream)
Definition: id3.c:88
uint32_t crc
Definition: id3.h:139
size_t size
Definition: id3.h:117