1 /*
2  *   tags is a support module which provides access to metadata tags (and xing/vbri/lame tags as well)
3  *   Copyright (C) 2013-2018 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 /* Modifed by Evan Dekker 2019-09-26 */
20 
21 #ifndef TAGS_H
22 #define TAGS_H
23 
24 #if defined(__WINDOWS__)
25 #include <sys/types.h>
26 #endif
27 
28 #define LAMETAGSIZE        36
29 #define LAME_STRING_LENGTH 48
30 
31 #define TAG_NOTAG           0
32 #define TAG_VBRITAG         1
33 #define TAG_XINGTAG         2
34 #define TAG_LAMECBRTAG      3
35 
36 /*
37  * this value MUST be carefully choosen!
38  * (or some calculation will be needed, so boring)
39  * Current identification routines work for id3v2, apetag and wave riff,
40  * (the metadata tags we can usually find at the very beginning)
41  * and they require 10 bytes, 32 bytes and 12 bytes (just look at the code)
42  * at least.
43  * Should a new tag appear, this value will have to be evaluated again.
44  */
45 #define HEAD_METADATA_MIN_IDENTIFICATION_LENGTH             32
46 
47 typedef struct id3tag {
48     unsigned char tag[3];
49     unsigned char title[30];
50     unsigned char artist[30];
51     unsigned char album[30];
52     unsigned char year[4];
53     unsigned char comment[30];
54     unsigned char genre;
55 } id3tag;
56 
57 /* structure for MusicMatch tag */
58 typedef struct mmtag_t {
59     unsigned int  tag_size;
60     unsigned int  image_size;
61     unsigned int  metadata_size;
62     off_t         image_offset;
63     char          mm_ver[5];   /* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
64     char          tag_ver[5];  /* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
65     char          enc_ver[5];  /* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
66     char          image_ext[5];/* this field is actually four bytes long, this trick ensures there will always be a null string terminator */
67     char          header_present;
68 } mmtag_t;
69 
70 /* structure to receive extracted header */
71 typedef struct vbrtagdata_t
72 {
73     char    *tagId;
74     off_t   tagStartsAt;
75     unsigned int     header;           /* mpeg header of the frame containing the tag */
76     int     frameSize;                 /* I want to keep the size of the frame containing the tag */
77     char    infoTag;
78     short   version;
79     /* The following two fields come from lame vbr tag - they differ from similar info
80        written by fhg encoders (stored into streamInfo structure) */
81     short   encDelay;                  /* encoder delay (start) */
82     short   encPadding;                /* encoder padding (samples added at the end of the wave) */
83     short   tocEntries;
84     short   sizePerTocEntry;
85     short   framesPerTocEntry;
86     int     tocSize;
87     unsigned int reported_frames;      /* total bit stream frames from Vbr header data */
88     unsigned int bytes;                /* total bit stream bytes from Vbr header data*/
89     int     vbr_scale;                 /* encoded vbr scale from Vbr header data*/
90     char    lame_buggy_vbrheader;
91     unsigned char lametag[LAMETAGSIZE];
92     char    lametagVerified;
93     int     lameMusicCRC;                  /* this is actually a ushort
94                                               but I need setting -1 for signaling empty value */
95 } vbrtagdata_t;
96 
97 
98 int  extract_enc_string(char *, unsigned char *, int);
99 char checkvbrinfotag(vbrtagdata_t *, unsigned char *, off_t, char *);
100 void show_info_tag (vbrtagdata_t *);
101 void show_id3v1(id3tag *);
102 int  checkid3v1(FILE *, off_t, id3tag *);
103 int  checkid3v2_footer(FILE *, off_t, unsigned char *, unsigned char *);
104 int  checkapetagx_tail(FILE *, off_t, int *, int *, char *);
105 int  checklyrics3v1(FILE *, off_t);
106 int  checklyrics3v2(FILE *, off_t);
107 void checkmmtag(FILE *, off_t, mmtag_t *);
108 char checkmm_partial_tag(FILE *, off_t, mmtag_t *);
109 int  checkid3v2(unsigned char *, int, int *, unsigned char *, unsigned char *);
110 int  checkapetagx_head(unsigned char *, int, int *, int *, int *, char *);
111 int  checkwaveriff(unsigned char *, int, int *);
112 int  checkwaveriff_datachunk(unsigned char *, int *, int *);
113 
114 int check_timing_shift_case(vbrtagdata_t *);
115 
116 #endif
117