spAudio
Loading...
Searching...
No Matches
spID3.h
1/*
2 * spID3.h
3 *
4 * **** UNOFFICIAL VERSION, DON'T USE THIS API ****
5 */
6
7#ifndef __SPID3_H
8#define __SPID3_H
9
10#include <sp/spChunk.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#define spID3FrameSize spChunkSize
17
18#define SP_ID3_CHUNK_INFO_OPTION_TEXT_MASK (1<<(SP_CHUNK_INFO_OPTION_USER_MASK_OFFSET))
19#define SP_ID3_CHUNK_INFO_OPTION_DESC_MASK (1<<(SP_CHUNK_INFO_OPTION_USER_MASK_OFFSET+1))
20#define SP_ID3_CHUNK_INFO_OPTION_LANG_MASK (1<<(SP_CHUNK_INFO_OPTION_USER_MASK_OFFSET+2))
21#define SP_ID3_CHUNK_INFO_OPTION_DESC_TEXT_MASK (SP_ID3_CHUNK_INFO_OPTION_DESC_MASK|SP_ID3_CHUNK_INFO_OPTION_TEXT_MASK)
22#define SP_ID3_CHUNK_INFO_OPTION_LANG_TEXT_MASK (SP_ID3_CHUNK_INFO_OPTION_LANG_MASK|SP_ID3_CHUNK_INFO_OPTION_DESC_TEXT_MASK)
23
24#define SP_ID3_FRAME_TYPE_ALBUM_V2_2 "TAL"
25#define SP_ID3_FRAME_TYPE_ALBUM_V2_3 "TALB"
26#define SP_ID3_FRAME_TYPE_ALBUM SP_ID3_FRAME_TYPE_ALBUM_V2_3
27#define SP_ID3_FRAME_TYPE_COMPOSER_V2_2 "TCM"
28#define SP_ID3_FRAME_TYPE_COMPOSER_V2_3 "TCOM"
29#define SP_ID3_FRAME_TYPE_COMPOSER SP_ID3_FRAME_TYPE_COMPOSER_V2_3
30#define SP_ID3_FRAME_TYPE_LYRICIST_V2_2 "TXT"
31#define SP_ID3_FRAME_TYPE_LYRICIST_V2_3 "TEXT"
32#define SP_ID3_FRAME_TYPE_LYRICIST SP_ID3_FRAME_TYPE_LYRICIST_V2_3
33#define SP_ID3_FRAME_TYPE_COPYRIGHT_V2_2 "TCR"
34#define SP_ID3_FRAME_TYPE_COPYRIGHT_V2_3 "TCOP"
35#define SP_ID3_FRAME_TYPE_COPYRIGHT SP_ID3_FRAME_TYPE_COPYRIGHT_V2_3
36#define SP_ID3_FRAME_TYPE_TRACK_V2_2 "TRK"
37#define SP_ID3_FRAME_TYPE_TRACK_V2_3 "TRCK"
38#define SP_ID3_FRAME_TYPE_TRACK SP_ID3_FRAME_TYPE_TRACK_V2_3
39#define SP_ID3_FRAME_TYPE_DISC_V2_2 "TPA"
40#define SP_ID3_FRAME_TYPE_DISC_V2_3 "TPOS"
41#define SP_ID3_FRAME_TYPE_DISC SP_ID3_FRAME_TYPE_DISC_V2_3
42#define SP_ID3_FRAME_TYPE_TITLE_V2_2 "TT2"
43#define SP_ID3_FRAME_TYPE_TITLE_V2_3 "TIT2"
44#define SP_ID3_FRAME_TYPE_TITLE SP_ID3_FRAME_TYPE_TITLE_V2_3
45#define SP_ID3_FRAME_TYPE_ARTIST_V2_2 "TP1"
46#define SP_ID3_FRAME_TYPE_ARTIST_V2_3 "TPE1"
47#define SP_ID3_FRAME_TYPE_ARTIST SP_ID3_FRAME_TYPE_ARTIST_V2_3
48#define SP_ID3_FRAME_TYPE_ALBUM_ARTIST_V2_2 "TP2"
49#define SP_ID3_FRAME_TYPE_ALBUM_ARTIST_V2_3 "TPE2"
50#define SP_ID3_FRAME_TYPE_ALBUM_ARTIST SP_ID3_FRAME_TYPE_ALBUM_ARTIST_V2_3
51#define SP_ID3_FRAME_TYPE_GENRE_V2_2 "TCO"
52#define SP_ID3_FRAME_TYPE_GENRE_V2_3 "TCON"
53#define SP_ID3_FRAME_TYPE_GENRE SP_ID3_FRAME_TYPE_GENRE_V2_3
54#define SP_ID3_FRAME_TYPE_SOFTWARE_V2_2 "TEN"
55#define SP_ID3_FRAME_TYPE_SOFTWARE_V2_3 "TENC"
56#define SP_ID3_FRAME_TYPE_SOFTWARE SP_ID3_FRAME_TYPE_SOFTWARE_V2_3
57#define SP_ID3_FRAME_TYPE_TEMPO_V2_2 "TBP"
58#define SP_ID3_FRAME_TYPE_TEMPO_V2_3 "TBPM"
59#define SP_ID3_FRAME_TYPE_TEMPO SP_ID3_FRAME_TYPE_TEMPO_V2_3
60#define SP_ID3_FRAME_TYPE_COMMENT_V2_2 "COM"
61#define SP_ID3_FRAME_TYPE_COMMENT_V2_3 "COMM"
62#define SP_ID3_FRAME_TYPE_COMMENT SP_ID3_FRAME_TYPE_COMMENT_V2_3
63#define SP_ID3_FRAME_TYPE_PUBLISHER_V2_2 "TPB"
64#define SP_ID3_FRAME_TYPE_PUBLISHER_V2_3 "TPUB"
65#define SP_ID3_FRAME_TYPE_PUBLISHER SP_ID3_FRAME_TYPE_PUBLISHER_V2_3
66
67#define SP_ID3_FRAME_TYPE_RELEASE_V2_2 "TYE"
68#define SP_ID3_FRAME_TYPE_RELEASE_V2_3 "TYER"
69#define SP_ID3_FRAME_TYPE_RELEASE_V2_4 "TDRC"
70#define SP_ID3_FRAME_TYPE_RELEASE SP_ID3_FRAME_TYPE_RELEASE_V2_4
71
72#define SP_ID3_FRAME_TYPE_ISRC_V2_3 "TSRC"
73#define SP_ID3_FRAME_TYPE_ISRC SP_ID3_FRAME_TYPE_ISRC_V2_3
74
75#define SP_ID3_HEADER_FLAG_UNSYNCHRONISATION_MASK 0x80
76#define SP_ID3_HEADER_FLAG_V2_2_COMPRESSION_MASK 0x40
77#define SP_ID3_HEADER_FLAG_EXTENDED_MASK 0x40
78#define SP_ID3_HEADER_FLAG_EXPERIMENTAL_MASK 0x20
79#define SP_ID3_HEADER_FLAG_V2_4_FOOTERL_MASK 0x10
80
81#define SP_ID3_HEADER_EXTRA_FLAG_V2_3_CRC_MASK 0x8000
82
83#define SP_ID3_HEADER_EXTRA_FLAG_V2_4_TAG_UPDATE_MASK 0x40
84#define SP_ID3_HEADER_EXTRA_FLAG_V2_4_CRC_MASK 0x20
85#define SP_ID3_HEADER_EXTRA_FLAG_V2_4_TAG_RESTRICTIONS_MASK 0x10
86
87#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_SIZE_1MB 0x0
88#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_SIZE_128KB 0x40
89#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_SIZE_40KB 0x80
90#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_SIZE_4KB 0xc0
91
92#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_TEXT_ENCODING_NONE 0x0
93#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_TEXT_ENCODING_ISO8859_1_OR_UTF8 0x20
94
95#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_TEXT_SIZE_NONE 0x0
96#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_TEXT_SIZE_1024 0x8
97#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_TEXT_SIZE_128 0x10
98#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_TEXT_SIZE_30 0x18
99
100#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_IMAGE_ENCODING_NONE 0x0
101#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_IMAGE_ENCODING_PNG_OR_JPEG 0x4
102
103#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_IMAGE_SIZE_NONE 0x0
104#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_IMAGE_SIZE_UP_TO_256x256 0x1
105#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_IMAGE_SIZE_UP_TO_64x64 0x2
106#define SP_ID3_HEADER_EXTRA_TAG_RESTRICTIONS_IMAGE_SIZE_EXACTLY_64x64 0x3
107
108#define SP_ID3_FRAME_HEADER_FLAG1_V2_3_TAG_ALTER_MASK 0x80
109#define SP_ID3_FRAME_HEADER_FLAG1_V2_3_FILE_ALTER_MASK 0x40
110#define SP_ID3_FRAME_HEADER_FLAG1_V2_3_READ_ONLY_MASK 0x20
111
112#define SP_ID3_FRAME_HEADER_FLAG2_V2_3_COMPRESSION_MASK 0x80
113#define SP_ID3_FRAME_HEADER_FLAG2_V2_3_ENCRIPTION_MASK 0x40
114#define SP_ID3_FRAME_HEADER_FLAG2_V2_3_GROUPING_MASK 0x20
115
116#define SP_ID3_FRAME_HEADER_FLAG1_V2_4_TAG_ALTER_MASK 0x40
117#define SP_ID3_FRAME_HEADER_FLAG1_V2_4_FILE_ALTER_MASK 0x20
118#define SP_ID3_FRAME_HEADER_FLAG1_V2_4_READ_ONLY_MASK 0x10
119
120#define SP_ID3_FRAME_HEADER_FLAG2_V2_4_GROUPING_MASK 0x40
121#define SP_ID3_FRAME_HEADER_FLAG2_V2_4_COMPRESSION_MASK 0x8
122#define SP_ID3_FRAME_HEADER_FLAG2_V2_4_ENCRIPTION_MASK 0x4
123#define SP_ID3_FRAME_HEADER_FLAG2_V2_4_UNSYNCHRONISATION_MASK 0x2
124#define SP_ID3_FRAME_HEADER_FLAG2_V2_4_DATA_LENGTH_MASK 0x1
125
126typedef struct _spID3HeaderExtra_V2_3 {
127 unsigned long size;
128 short flag;
129 unsigned long padding_size;
130 unsigned long crc;
131} spID3HeaderExtra_V2_3;
132
133typedef struct _spID3HeaderExtra_V2_4 {
134 unsigned long size;
135 unsigned char flag_length;
136 unsigned char flag;
137 unsigned long crc;
138 unsigned char restrictions;
139} spID3HeaderExtra_V2_4;
140
141typedef struct _spID3FrameHeaderExtra_V2_3 {
142 unsigned long decompressed_size;
143 unsigned char encryption_method;
144 unsigned char group_id;
145} spID3FrameHeaderExtra_V2_3;
146
147typedef struct _spID3FrameHeaderExtra_V2_4 {
148 unsigned char group_id;
149 unsigned char encryption_method;
150 unsigned long data_length_indicator;
151} spID3FrameHeaderExtra_V2_4;
152
153typedef struct _spID3FrameHeader {
154 char type[4];
155
156 unsigned long size;
157 unsigned char flag1;
158 unsigned char flag2;
159
160 union {
161 spID3FrameHeaderExtra_V2_3 v2_3;
162 spID3FrameHeaderExtra_V2_4 v2_4;
163 } extra;
164} spID3FrameHeader;
165
166typedef struct _spID3Frame {
167 struct _spID3Frame *parent;
168 struct _spID3Frame *child;
169
170 struct _spID3Frame *prev;
171 struct _spID3Frame *next;
172
173 spFileOffset offset;
174
175 spID3FrameHeader header;
176
177 long unsync_count;
178} spID3Frame;
179
180typedef struct _spID3Header {
181 struct _spID3Frame *parent; /* NULL */
182 struct _spID3Frame *child;
183
184 struct _spID3Frame *prev; /* NULL */
185 struct _spID3Frame *next; /* NULL */
186
187 spFileOffset offset;
188
189 spID3FrameHeader header; /* 'ID3' */
190
191 long unsync_count;
192
193 unsigned char version;
194 unsigned char revision;
195
196 union {
197 spID3HeaderExtra_V2_3 v2_3;
198 spID3HeaderExtra_V2_4 v2_4;
199 } extra;
200} spID3Header;
201
202typedef struct _spID3DataFrame {
203 struct _spID3Frame *parent;
204 struct _spID3Frame *child;
205
206 struct _spID3Frame *prev;
207 struct _spID3Frame *next;
208
209 spFileOffset offset;
210
211 spID3FrameHeader header;
212
213 long unsync_count;
214
215 unsigned char *data;
216} spID3DataFrame;
217
218typedef struct _spID3TextFrame {
219 struct _spID3Frame *parent;
220 struct _spID3Frame *child;
221
222 struct _spID3Frame *prev;
223 struct _spID3Frame *next;
224
225 spFileOffset offset;
226
227 spID3FrameHeader header;
228
229 long unsync_count;
230
231 unsigned char encoding;
232 spBool bom_flag; /* internal */
233 spBool swap_flag; /* internal */
234
235 unsigned char *string;
236} spID3TextFrame;
237
238typedef struct _spID3DescTextFrame {
239 struct _spID3Frame *parent;
240 struct _spID3Frame *child;
241
242 struct _spID3Frame *prev;
243 struct _spID3Frame *next;
244
245 spFileOffset offset;
246
247 spID3FrameHeader header;
248
249 long unsync_count;
250
251 unsigned char encoding;
252 spBool bom_flag; /* internal */
253 spBool swap_flag; /* internal */
254
255 unsigned char *string;
256 unsigned char *actual_string;
257} spID3DescTextFrame;
258
259typedef struct _spID3LangTextFrame {
260 struct _spID3Frame *parent;
261 struct _spID3Frame *child;
262
263 struct _spID3Frame *prev;
264 struct _spID3Frame *next;
265
266 spFileOffset offset;
267
268 spID3FrameHeader header;
269
270 long unsync_count;
271
272 unsigned char encoding;
273 spBool bom_flag; /* internal */
274 spBool swap_flag; /* internal */
275
276 unsigned char *string;
277 unsigned char *actual_string;
278
279 unsigned char lang[3];
280} spID3LangTextFrame;
281
282typedef struct _spID3MimeDataFrame {
283 struct _spID3Frame *parent;
284 struct _spID3Frame *child;
285
286 struct _spID3Frame *prev;
287 struct _spID3Frame *next;
288
289 spFileOffset offset;
290
291 spID3FrameHeader header;
292
293 long unsync_count;
294
295 unsigned char encoding;
296 unsigned char format[3];
297 long mime_type_len;
298 unsigned char *mime_type;
299 long filename_len;
300 unsigned char *filename;
301 unsigned char data_type;
302 long description_len;
303 unsigned char *description;
304
305 long data_size;
306 unsigned char *data;
307} spID3MimeDataFrame;
308
309typedef enum {
310 SP_ID3V1_GENRE_EXTENSION_UNKNOWN = -1,
311 SP_ID3V1_GENRE_NONEXTENSION = 0,
312 SP_ID3V1_GENRE_EXTENSION_WINAMP_CORE = 88,
313 SP_ID3V1_GENRE_EXTENSION_WINAMP_1998 = 142,
314 SP_ID3V1_GENRE_EXTENSION_WINAMP_2010 = 148,
315 SP_ID3V1_GENRE_EXTENSION_END = 191,
316} spID3v1GenreExtension;
317
318typedef spID3FrameSize (*spID3FrameUpdateFunc)(spID3Frame *frame, void *data);
319
320extern spBool spInitID3Header(spID3Header *header, unsigned char version, unsigned char revision);
321extern void spPropagateID3FrameContentSize(spID3Frame *parent, spChunkSize size_diff);
322extern spBool spSetID3FrameContentSize(spID3Frame *frame, spID3FrameSize size, spBool propagate_size);
323extern spID3Frame *spCreateID3FrameWithCB(spID3Header *header, const char *type, spID3FrameUpdateFunc update_func, void *data);
324extern spID3Frame *spCreateID3Frame(spID3Header *header, const char *type);
325
326extern spID3FrameSize spGetID3FrameContentSize(spID3Frame *frame);
327extern spID3FrameSize spGetID3FrameSize(spID3Frame *frame, char *string /* char string[5] */);
328extern spID3FrameSize spGetID3HeaderSize(spID3Header *header);
329extern spID3FrameSize spReadID3Header(spID3Header *header, FILE *fp);
330extern spID3FrameSize spWriteID3Header(spID3Header *header, FILE *fp);
331extern spBool spFreeID3Header(spID3Header *header);
332extern spID3FrameSize spCopyID3Header(spID3Header *dest_header, spID3Header *src_header);
333
334extern spID3Frame *spFindID3FrameFromHeader(spID3Header *header, const char *type);
335extern spID3Frame *spFindID3Frame(spID3Frame *frame, const char *type);
336
337extern const unsigned char *spGetID3TextFrameString(spID3TextFrame *tframe, unsigned char *encoding);
338extern spBool spGetID3TextFrameStringToLocaleCode(spID3TextFrame *tframe, unsigned char *str_in_locale, long size);
339extern spBool spGetID3TextFrameTrackNumber(spID3TextFrame *tframe, spLong32 *track, spLong32 *total);
340extern spBool spGetID3TextFrameNumber(spID3TextFrame *tframe, spLong32 *number);
341
342extern const unsigned char *spFindID3TextFrameString(spID3Header *header, const char *type, unsigned char *encoding);
343extern spBool spFindID3TextFrameStringToLocaleCode(spID3Header *header, const char *type, unsigned char *str_in_locale, long size);
344extern spBool spFindID3TextFrameTrackNumber(spID3Header *header, spLong32 *track, spLong32 *total);
345extern spBool spFindID3TextFrameDiscNumber(spID3Header *header, spLong32 *disc, spLong32 *total);
346extern spBool spFindID3TextFrameTempo(spID3Header *header, spLong32 *tempo);
347
348extern spBool spSetID3TextFrameString(spID3TextFrame *tframe, unsigned char encoding, const unsigned char *str, long len);
349extern spBool spSetID3TextFrameStringFromLocaleCode(spID3TextFrame *tframe, unsigned char encoding, const unsigned char *str_in_locale);
350extern spID3TextFrame *spAppendID3TextFrameStringFromLocaleCode(spID3Header *header, const char *type, spBool find_existing_frame, unsigned char encoding, const unsigned char *str_in_locale);
351extern spID3TextFrame *spAppendID3TextFrameString(spID3Header *header, const char *type, spBool find_existing_frame,
352 unsigned char encoding, const unsigned char *str, long len);
353extern spID3TextFrame *spAppendID3TextFrameTrackNumber(spID3Header *header, spLong32 number, spLong32 total);
354extern spID3TextFrame *spAppendID3TextFrameDiscNumber(spID3Header *header, spLong32 number, spLong32 total);
355extern spID3TextFrame *spAppendID3TextFrameTempo(spID3Header *header, spLong32 tempo);
356
357extern spBool spParseID3SongInfo(spID3Header *header, spSongInfoV2 *song_info);
358extern spBool spAppendID3SongInfo(spID3Header *header, spSongInfoV2 *song_info);
359
360extern spBool spIsStringInsideID3AsciiRange(const unsigned char *str);
361extern spBool spIsStringInsideID3Laten1Range(const unsigned char *str);
362
363extern void spShowID3HeaderInfo(spID3Header *header);
364
365extern const char *spGetID3v1GenreString(int index, spID3v1GenreExtension *extension_type);
366extern int spFindID3v1GenreIndex(const char *string, spID3v1GenreExtension extension_limit);
367
368
369typedef struct spID3Converter *spID3Converter;
370
371#define SP_ID3_CONVERTER_OPTION_NONE 0L
372#define SP_ID3_CONVERTER_OPTION_NO_CODESET_CONVERTER 1L
373
374extern spID3Converter spID3ConverterOpen(const char *system_codeset, unsigned long options);
375extern void spID3ConverterClose(spID3Converter id3conv);
376extern spBool spID3ConverterFindTextFrameString(spID3Converter id3conv, spID3Header *header, const char *type,
377 unsigned char *str_in_codeset, long size);
378extern spID3TextFrame *spID3ConverterAppendTextFrameString(spID3Converter id3conv, spID3Header *header, const char *type,
379 spBool find_existing_frame, unsigned char encoding, const unsigned char *str_in_lang);
380extern spBool spID3ConverterParseSongInfo(spID3Converter id3conv, spID3Header *header, spSongInfoV2 *song_info);
381extern spBool spID3ConverterAppendSongInfo(spID3Converter id3conv, spID3Header *header, spSongInfoV2 *song_info);
382extern void spID3ConverterShowID3HeaderInfo(spID3Converter id3conv, spID3Header *header);
383extern spBool spID3ConverterConvertUTF8StringTo(spID3Converter id3conv, unsigned char *iobuf, long buf_size);
384extern spBool spID3ConverterConvertToUTF8String(spID3Converter id3conv, unsigned char *iobuf, long buf_size);
385
386
387#ifdef __cplusplus
388} /* Close scope of 'extern "C"' declaration */
389#endif
390
391#endif /* __SPID3_H */
int spBool
Definition spWave.h:138