2 Copyright 2006 Mark Calderbank, Andreas Vogel
4 This file is part of VOMP.
6 VOMP 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.
11 VOMP 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.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef DEMUXERAUDIO_H
22 #define DEMUXERAUDIO_H
29 class DemuxerAudio : public Demuxer
33 char mpegVersion[8]; //MPEG1/2/2,5
34 int mpegLayer; //1,2,3
38 char info[20]; //channel mode,...
47 DemuxerAudio(int p_vID = 0, int p_aID = 0);
48 virtual ~DemuxerAudio();
51 virtual int scan(UCHAR* buf, int len);
52 virtual int findPTS(UCHAR* buf, int len, ULLONG* dest);
53 virtual void setVID(int p_vID);
54 virtual void setAID(int p_aID);
55 virtual int put(UCHAR* buf, int len);
57 //special functions for the audioplayer
62 void setSkipFactor(int faktor);
64 //how many bytes do we need at the file start
65 //ID3V2, VBR + some spare to detect a first header
66 static UINT headerBytes() {
69 //how many bytes do we need at the end
70 static UINT footerBytes() {
73 //return a reference to an ID3 tag
74 //if not found (from checkStart or checkID3)
75 //NULL will be returned
76 const id3_tag * getId3Tag();
77 const mpegInfo * getMpegInfo();
78 const vbrInfo * getVBRINfo();
80 //check for a valid header at the beginning (and parse all we find)
81 //will return the offset in buffer where the first valid
82 //header was found (with potentially skipping ID3 and VBR)
83 //return -1 if nothing found
84 int checkStart(UCHAR * buffer, int len);
85 //check for ID3V1 (at the end)
87 int checkID3(UCHAR * buffer, int len);
89 //return length if we can do this
91 ULONG getSecondsFromLen(ULONG len);
93 //position within a file
94 //return 0 if we cannot
95 ULONG positionFromSeconds(ULONG seconds);
97 //try to read the iD3 tag value (V2xx) and
98 //fill it into the ID3 store
99 bool fillId3Tag(id3_tag * tag,UCHAR * frameData, int frameLen, int dataOffset, bool v23);
101 const static UINT PACKET_SIZE=4096;
103 /*max size of a packet
104 see http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
105 assumptions: max br 448kb/s, min sample 16k
106 L2/L3 FrameLengthInBytes = 144 * BitRate / SampleRate + Padding
107 L2/3 28*144+8 -> 4040
108 L1 FrameLengthInBytes = (12 * BitRate / SampleRate + Padding) * 4
113 int readHeader(UCHAR* buf, int len, bool writeInfo=false);
115 //info flags for the player
116 bool inSync; //set if we read a valid header
117 UINT outOfSync; //counts each invalid read headers
118 bool hasHdrInfo; //if we have been able to successfully
119 //parse the first header
120 bool hasVBRInfo; //we have VBR and the necessary info
125 //a little bit guessing for VBR
131 ULONG globalBytesWritten;
134 //search for the start of a header
135 //return NULL if none found
136 UCHAR * findHeader(UCHAR * buf, int len, bool writeInfo=false);
137 //we need a buffer to be able to read at least a complete header
138 const static int HDRLEN=4;
139 UCHAR tmpBuffer[PACKET_SIZE+HDRLEN];
142 //compute the bytes/second from the BR info
143 //return 0 if not there;
144 ULONG getBytesPerSecond();
146 //parse ID3V2 at the beginning
148 //return length of header, -1 if not found
149 int parseID3V2(UCHAR *data, int len);
150 int id3_2_3_FrameParse(unsigned char buf[], id3_frame *frame);
151 int id3_2_2_FrameParse(unsigned char buf[], id3_frame *frame);
153 //parse ID3V1 at the end
154 //set info if there, return -1 otherwise
155 int parseID3V1(UCHAR *data, int len) ;
157 //parse a VBR header and set VBR info
158 //input has to point to firts MPEG header in file
159 //potentially after ID3V2
160 int parseVBR(UCHAR *data, int len);
163 class PacketBuffer* buffer;