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
31 class DemuxerAudio : public Demuxer
35 char mpegVersion[8]; //MPEG1/2/2,5
36 int mpegLayer; //1,2,3
40 char info[20]; //channel mode,...
49 DemuxerAudio(int p_vID = 0, int p_aID = 0);
50 virtual ~DemuxerAudio();
53 virtual int scan(UCHAR* buf, int len);
54 virtual int findPTS(UCHAR* buf, int len, ULLONG* dest);
55 virtual void setVID(int p_vID);
56 virtual void setAID(int p_aID);
57 virtual int put(UCHAR* buf, int len);
59 //special functions for the audioplayer
64 void setSkipFactor(int faktor);
66 //how many bytes do we need at the file start
67 //ID3V2, VBR + some spare to detect a first header
68 static UINT headerBytes() {
71 //how many bytes do we need at the end
72 static UINT footerBytes() {
75 //return a reference to an ID3 tag
76 //if not found (from checkStart or checkID3)
77 //NULL will be returned
78 const id3_tag * getId3Tag();
79 const mpegInfo * getMpegInfo();
80 const vbrInfo * getVBRINfo();
82 //check for a valid header at the beginning (and parse all we find)
83 //will return the offset in buffer where the first valid
84 //header was found (with potentially skipping ID3 and VBR)
85 //return -1 if nothing found
86 int checkStart(UCHAR * buffer, int len);
87 //check for ID3V1 (at the end)
89 int checkID3(UCHAR * buffer, int len);
91 //return length if we can do this
93 ULONG getSecondsFromLen(ULONG len);
95 //position within a file
96 //return 0 if we cannot
97 ULONG positionFromSeconds(ULONG seconds);
99 //try to read the iD3 tag value (V2xx) and
100 //fill it into the ID3 store
101 bool fillId3Tag(id3_tag * tag,UCHAR * frameData, int frameLen, int dataOffset, bool v23);
103 const static UINT PACKET_SIZE=4096;
105 /*max size of a packet
106 see http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
107 assumptions: max br 448kb/s, min sample 16k
108 L2/L3 FrameLengthInBytes = 144 * BitRate / SampleRate + Padding
109 L2/3 28*144+8 -> 4040
110 L1 FrameLengthInBytes = (12 * BitRate / SampleRate + Padding) * 4
115 int readHeader(UCHAR* buf, int len, bool writeInfo=false);
117 //info flags for the player
118 bool inSync; //set if we read a valid header
119 UINT outOfSync; //counts each invalid read headers
120 bool hasHdrInfo; //if we have been able to successfully
121 //parse the first header
122 bool hasVBRInfo; //we have VBR and the necessary info
127 //a little bit guessing for VBR
133 ULONG globalBytesWritten;
136 //search for the start of a header
137 //return NULL if none found
138 UCHAR * findHeader(UCHAR * buf, int len, bool writeInfo=false);
139 //we need a buffer to be able to read at least a complete header
140 const static int HDRLEN=4;
141 UCHAR tmpBuffer[PACKET_SIZE+HDRLEN];
144 //compute the bytes/second from the BR info
145 //return 0 if not there;
146 ULONG getBytesPerSecond();
148 //parse ID3V2 at the beginning
150 //return length of header, -1 if not found
151 int parseID3V2(UCHAR *data, int len);
152 int id3_2_3_FrameParse(unsigned char buf[], id3_frame *frame);
153 int id3_2_2_FrameParse(unsigned char buf[], id3_frame *frame);
155 //parse ID3V1 at the end
156 //set info if there, return -1 otherwise
157 int parseID3V1(UCHAR *data, int len) ;
159 //parse a VBR header and set VBR info
160 //input has to point to firts MPEG header in file
161 //potentially after ID3V2
162 int parseVBR(UCHAR *data, int len);
165 class PacketBuffer* buffer;