1 /*
2  * MP3val - a program for MPEG audio file validation
3  * Copyright (C) 2005-2009 Alexey Kuznetsov (ring0) and Eugen Tikhonov (jetsys)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 
20 #ifndef __MPEGPARSE_H__
21 #define __MPEGPARSE_H__
22 
23 #include <iostream>
24 
25 /*
26  * MPEGINFO structure is used to contain both information about the last analyzed
27  * frame (filled by ValidateMPEGFrame) and for the entire stream.
28  */
29 
30 
31 struct MPEGINFO {
32 //MPEG frames counts
33 	int mpeg1layer1;
34 	int mpeg1layer2;
35 	int mpeg1layer3;
36 	int mpeg2layer1;
37 	int mpeg2layer2;
38 	int mpeg2layer3;
39 	int mpeg25layer1;
40 	int mpeg25layer2;
41 	int mpeg25layer3;
42 //Tag counts
43 	int id3v1;
44 	int id3v2;
45 	int apev2;
46 
47 //VBR header info
48 	bool VBRHeaderPresent;
49 	bool IsXingHeader; //otherwise it's Fraunhofer VBRI header
50 	bool BytesPresent;
51 	int iBytes;
52 	bool FramesPresent;
53 	int iFrames;
54 	int iFirstMPEGFrameSize; //because Foobar2000 doesn't count the first frame (with Xing header) as MPEG data
55 
56 //Error flags
57 	int riff;
58 	int unknown_format;
59 	int truncated;
60 	int mpeg_stream_error;
61 	int garbage_at_the_begin;
62 	int garbage_at_the_end;
63 
64 //MPEG-related data
65 	bool LastFrameStereo;
66 	bool bLastFrameCRC;
67 	bool bCRC;
68 	bool bCRCError;
69 	int iLastBitrate;
70 	int iLastMPEGLayer;
71 	int iLastMPEGVersion;
72 //Miscellaneous data
73 	bool bVariableBitrate;
74 	int iTotalMPEGBytes;
75 	int iErrors;
76 	int iDeletedFrames;
77 	int iCRCErrors;
78 
MPEGINFOMPEGINFO79 	MPEGINFO() {
80 		clear();
81 	}
82 
clearMPEGINFO83 	void clear() {
84 		mpeg1layer1=0;
85 		mpeg1layer2=0;
86 		mpeg1layer3=0;
87 		mpeg2layer1=0;
88 		mpeg2layer2=0;
89 		mpeg2layer3=0;
90 		mpeg25layer1=0;
91 		mpeg25layer2=0;
92 		mpeg25layer3=0;
93 		id3v1=0;
94 		id3v2=0;
95 		apev2=0;
96 
97 		VBRHeaderPresent=false;
98 		IsXingHeader=true;
99 		BytesPresent=false;
100 		iBytes=-1;
101 		FramesPresent=false;
102 		iFrames=-1;
103 
104 		riff=-1;
105 		unknown_format=-1;
106 		mpeg_stream_error=-1;
107 		truncated=-1;
108 		garbage_at_the_begin=-1;
109 		garbage_at_the_end=-1;
110 
111 		LastFrameStereo=false;
112 		bLastFrameCRC=false;
113 		bCRC=false;
114 		bCRCError=false;
115 		bVariableBitrate=false;
116 		iLastBitrate=-2;
117 		iLastMPEGLayer=0;
118 		iLastMPEGVersion=0;
119 		iCRCErrors=0;
120 
121 		iTotalMPEGBytes=0;
122 		iErrors=0;
123 		iDeletedFrames=0;
124 	}
125 };
126 
127 int ValidateFile(unsigned char *baseptr,int iFileSize, MPEGINFO *mpginfo,std::ostream *out,char *filename,bool fix,int hFile);
128 
129 #endif
130