1 /*
2  *   tags is a support module which provides access to metadata tags (and xing/vbri/lame tags as well)
3  *   Copyright (C) 2013-2020 Elio Blanca <eblanca76@users.sourceforge.net>
4  *
5  *   This library is free software; you can redistribute it and/or
6  *   modify it under the terms of the GNU Lesser General Public
7  *   License as published by the Free Software Foundation; either
8  *   version 2.1 of the License, or (at your option) any later version.
9  *
10  *   This library is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *   Lesser General Public License for more details.
14  *
15  *   You should have received a copy of the GNU Lesser General Public
16  *   License along with this library; if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef TAGS_H
21 #define TAGS_H
22 
23 #define LAMETAGSIZE        36
24 #define LAME_STRING_LENGTH 48
25 
26 #define TAG_NOTAG           0
27 #define TAG_VBRITAG         1
28 #define TAG_XINGTAG         2
29 #define TAG_LAMECBRTAG      3
30 
31 /*
32  * this value MUST be carefully choosen!
33  * (or some calculation will be needed, so boring)
34  * Current identification routines work for id3v2, apetag and wave riff,
35  * (the metadata tags we can usually find at the very beginning)
36  * and they require 10 bytes, 32 bytes and 12 bytes (just look at the code)
37  * at least.
38  * Should a new tag appear, this value will have to be evaluated again.
39  */
40 #define HEAD_METADATA_MIN_IDENTIFICATION_LENGTH             32
41 
42 typedef struct id3tag {
43     unsigned char tag[3];
44     unsigned char title[30];
45     unsigned char artist[30];
46     unsigned char album[30];
47     unsigned char year[4];
48     unsigned char comment[30];
49     unsigned char genre;
50 } id3tag;
51 
52 /* structure for MusicMatch tag */
53 typedef struct mmtag_t {
54     unsigned int  tag_size;
55     unsigned int  image_size;
56     unsigned int  metadata_size;
57     off_t         image_offset;
58     char          mm_ver[5];   /* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
59     char          tag_ver[5];  /* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
60     char          enc_ver[5];  /* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
61     char          image_ext[5];/* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
62     char          header_present;
63 } mmtag_t;
64 
65 /* structure to receive extracted info tag */
66 typedef struct vbrtagdata_t
67 {
68     char    *tagId;
69     off_t   tagStartsAt;
70     unsigned int     header;           /* mpeg header of the frame containing the tag */
71     int     frameSize;                 /* I want to keep the size of the frame containing the tag */
72     char    infoTag;
73     short   version;
74     /* The following two fields come from lame vbr tag - they differ from similar info
75        written by fhg encoders (stored into streamInfo structure) */
76     short   encDelay;                  /* encoder delay (start) */
77     short   encPadding;                /* encoder padding (samples added at the end of the wave) */
78     short   tocEntries;
79     short   sizePerTocEntry;
80     short   framesPerTocEntry;
81     int     tocSize;
82     unsigned int reported_frames;      /* total bit stream frames from Vbr header data */
83     unsigned int bytes;                /* total bit stream bytes from Vbr header data*/
84     int     vbr_scale;                 /* encoded vbr scale from Vbr header data*/
85     char    lame_buggy_vbrheader;
86     unsigned char lametag[LAMETAGSIZE];
87     char    lametagVerified;
88     int     lameMusicCRC;                  /* this is actually 16 bit long
89                                               but I need to set -1 for signaling an empty value */
90 } vbrtagdata_t;
91 
92 
93 int  extract_enc_string(char *, unsigned char *, int);
94 char checkvbrinfotag(vbrtagdata_t *, unsigned char *, off_t, char *);
95 void show_info_tag (vbrtagdata_t *);
96 void show_id3v1(id3tag *);
97 int  checkid3v1(FILE *, off_t, id3tag *);
98 int  checkid3v2_footer(FILE *, off_t, unsigned char *, unsigned char *);
99 int  checkapetagx_tail(FILE *, off_t, int *, int *, char *);
100 int  checklyrics3v1(FILE *, off_t);
101 int  checklyrics3v2(FILE *, off_t);
102 void checkmmtag(FILE *, off_t, mmtag_t *);
103 char checkmm_partial_tag(FILE *, off_t, mmtag_t *);
104 int  checkid3v2(unsigned char *, int, int *, unsigned char *, unsigned char *);
105 int  checkapetagx_head(unsigned char *, int, int *, int *, int *, char *);
106 int  checkwaveriff(unsigned char *, int, int *);
107 int  checkwaveriff_datachunk(unsigned char *, int *, int *);
108 
109 #endif
110