]> git.vomp.tv Git - vompclient.git/blob - demuxeraudio.h
Fix text corruption in channel number display on live tv
[vompclient.git] / demuxeraudio.h
1 /*
2     Copyright 2006 Mark Calderbank, Andreas Vogel
3
4     This file is part of VOMP.
5
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.
10
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.
15
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef DEMUXERAUDIO_H
22 #define DEMUXERAUDIO_H
23
24 #include "demuxer.h"
25 #include "defines.h"
26 #include "id3.h"
27
28 class Log;
29 class PacketBuffer;
30
31 class DemuxerAudio : public Demuxer
32 {
33   public:
34                 typedef struct {
35                         char mpegVersion[8]; //MPEG1/2/2,5
36                         int  mpegLayer;      //1,2,3
37                         int  bitRate; 
38                         int  avrBitrate;
39                         int  sampleRate;
40                         char info[20];       //channel mode,...
41                 } mpegInfo;
42
43                 typedef struct {
44                         ULONG numFrames;
45                         ULONG numBytes;
46                         ULONG fileSeconds;
47                         UCHAR table[100];
48                 } vbrInfo;
49     DemuxerAudio(int p_vID = 0, int p_aID = 0);
50                 virtual ~DemuxerAudio();
51     virtual void flush();
52                 virtual void reset();
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,int type);
57     virtual int put(UCHAR* buf, int len);
58
59                 //special functions for the audioplayer
60                 bool isSync() ;
61                 UINT getSyncErrors();
62
63                 //set the skip factor
64                 void setSkipFactor(int faktor);
65
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() {
69                         return 4096;
70                 }
71                 //how many bytes do we need at the end
72                 static UINT footerBytes() {
73                         return 128;
74                 }
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();
81
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)
88                 //return 0 if found
89                 int checkID3(UCHAR * buffer, int len);
90
91                 //return length if we can do this
92                 //otherwise return 0
93                 ULONG getSecondsFromLen(ULONG len);
94
95                 //position within a file
96                 //return 0 if we cannot
97                 ULONG positionFromSeconds(ULONG seconds);
98
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);
102
103     const static UINT PACKET_SIZE=4096;
104   private:
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
111                 L1 (336+32)*4 = 1472
112                 */
113                 Log * log;
114                 
115                 int readHeader(UCHAR* buf, int len, bool writeInfo=false);
116
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
123                 //infos from header
124                 int hdrFramelen;
125                 int hdrBitrate;
126                 int hdrSamplingRate;
127                 //a little bit guessing for VBR
128                 int avrBitrate;
129
130                 int streamtype;
131                 bool isStarting;
132                 ULONG readHeaders;
133                 ULONG globalBytesWritten;
134
135
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];
142                 UINT tmpFill;
143
144                 //compute the bytes/second from the BR info
145                 //return 0 if not there;
146                 ULONG getBytesPerSecond();
147
148                 //parse ID3V2 at the beginning
149                 //set info if there
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);
154
155                 //parse ID3V1 at the end
156                 //set info if there, return -1 otherwise
157     int parseID3V1(UCHAR *data, int len) ;
158
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);
163
164
165                 class PacketBuffer* buffer;
166
167                 id3_tag *id3;
168                 mpegInfo *info;
169                 vbrInfo *vbr;
170
171                 unsigned int packetnum;
172
173
174 };
175
176 #endif