xine-lib 1.2.13-20230125hg15249
id3.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2000-2022 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
103typedef struct {
104 uint32_t id;
105 uint8_t revision;
106 uint8_t flags;
107 size_t size;
109
110typedef struct {
111 uint32_t id;
112 size_t size;
114
115typedef struct {
116 uint32_t id;
117 size_t size;
118 uint16_t flags;
120
121typedef struct {
122 size_t size;
123 uint16_t flags;
124 uint32_t padding_size;
125 uint32_t crc;
127
129
130typedef struct {
131 uint32_t id;
132 size_t size;
133 uint16_t flags;
135
136typedef struct {
137 size_t size;
138 uint8_t flags;
139 uint32_t crc;
142
143typedef 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;
152
154
162
174 xine_stream_t *stream,
175 uint32_t id3_signature) XINE_PROTECTED;
176
181static inline int id3v2_istag(uint32_t id3_signature) {
182 return (id3_signature & ID3V2X_MASK) == ID3V2X_TAG;
183}
184
185#if 0
186/* parse an unsynchronized 16bits integer */
187static inline uint16_t _X_BE_16_synchsafe(uint8_t buf[2]) {
188 return ((uint16_t)(buf[0] & 0x7F) << 7) |
189 (uint16_t)(buf[1] & 0x7F);
190}
191#endif
192
193/* parse an unsynchronized 24bits integer */
194static inline uint32_t _X_BE_24_synchsafe(uint8_t buf[3]) {
195 return ((uint32_t)(buf[0] & 0x7F) << 14) |
196 ((uint32_t)(buf[1] & 0x7F) << 7) |
197 (uint32_t)(buf[2] & 0x7F);
198}
199
200/* parse an unsynchronized 32bits integer */
201static inline uint32_t _X_BE_32_synchsafe(uint8_t buf[4]) {
202 return ((uint32_t)(buf[0] & 0x7F) << 21) |
203 ((uint32_t)(buf[1] & 0x7F) << 14) |
204 ((uint32_t)(buf[2] & 0x7F) << 7) |
205 (uint32_t)(buf[3] & 0x7F);
206}
207
208/* parse an unsynchronized 35bits integer */
209static inline uint32_t BE_35_synchsafe(uint8_t buf[5]) {
210 return ((uint32_t)(buf[0] & 0x07) << 28) |
211 ((uint32_t)(buf[1] & 0x7F) << 21) |
212 ((uint32_t)(buf[2] & 0x7F) << 14) |
213 ((uint32_t)(buf[3] & 0x7F) << 7) |
214 (uint32_t)(buf[4] & 0x7F);
215}
216
217#endif /* ID3_H */
static int input(void)
Definition goomsl_lex.c:1495
int id3v1_parse_tag(input_plugin_t *input, xine_stream_t *stream)
Definition id3.c:91
#define ID3V2X_TAG
Definition id3.h:38
static int id3v2_istag(uint32_t id3_signature)
Checks if the given buffer is an ID3 tag preamble.
Definition id3.h:181
static uint32_t _X_BE_32_synchsafe(uint8_t buf[4])
Definition id3.h:201
int xine_parse_id3v2_tag(xine_stream_t *stream, input_plugin_t *input)
Check/parse/skip a possible initial ID3 v2 tag from the (side) stream.
Definition id3.c:915
static uint32_t _X_BE_24_synchsafe(uint8_t buf[3])
Definition id3.h:194
static uint32_t BE_35_synchsafe(uint8_t buf[5])
Definition id3.h:209
id3v2_header_t id3v24_footer_t
Definition id3.h:128
#define ID3V2X_MASK
Definition id3.h:39
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:886
#define XINE_PROTECTED
Definition attributes.h:75
Definition id3.h:143
uint8_t genre
Definition id3.h:150
Definition id3.h:110
uint32_t id
Definition id3.h:111
size_t size
Definition id3.h:112
Definition id3.h:121
uint32_t crc
Definition id3.h:125
uint32_t padding_size
Definition id3.h:124
size_t size
Definition id3.h:122
uint16_t flags
Definition id3.h:123
Definition id3.h:115
uint32_t id
Definition id3.h:116
size_t size
Definition id3.h:117
uint16_t flags
Definition id3.h:118
Definition id3.h:136
uint8_t restrictions
Definition id3.h:140
uint32_t crc
Definition id3.h:139
uint8_t flags
Definition id3.h:138
size_t size
Definition id3.h:137
Definition id3.h:130
uint16_t flags
Definition id3.h:133
size_t size
Definition id3.h:132
uint32_t id
Definition id3.h:131
Definition id3.h:103
uint8_t revision
Definition id3.h:105
uint32_t id
Definition id3.h:104
uint8_t flags
Definition id3.h:106
size_t size
Definition id3.h:107
Definition input_plugin.h:90
Definition xine_internal.h:123