]> git.vomp.tv Git - vompclient.git/blob - demuxer.h
Display channel name, duration, resume point and size on recording info screen
[vompclient.git] / demuxer.h
1 /*
2     Copyright 2005-2008 Mark Calderbank
3     Copyright 2007 Marten Richter (AC3 support)
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21
22 /*
23
24 Thanks go to Jon Gettler of the MVPMC project and Stephen Rice for
25 the demuxer in mvpmc. It was used in the creation of this demuxer;
26 however, no code was copied verbatim.
27
28 */
29
30 #ifndef DEMUXER_H
31 #define DEMUXER_H
32
33 #include "stream.h"
34 #include "defines.h"
35
36 class DVBSubtitles;
37 class Callback;
38 class DrainTarget;
39
40 struct PictCountInfo
41 {
42         bool hassps;
43         bool hasaccessunit;
44         int log2_max_frame_num;
45         int frame_mbs_only_flag;
46         int separate_color_plane_flag;
47 };
48
49 class PESPacket
50 {
51   public:
52     PESPacket();
53     PESPacket(const PESPacket& packet);
54     PESPacket& operator=(const PESPacket& packet);
55     ~PESPacket();
56     void init(UCHAR type, UCHAR sub=0);
57     void truncate();
58     int  write(const UCHAR* buf, int len);
59
60     UCHAR operator[] (UINT index) const;
61                        // return data[index] if in bounds, else 0
62                        // so no proper error condition but never mind for now
63     const UCHAR* getData() const { return data; }
64     UINT getLength() const { return length; }
65     UINT getSize() const { return size; }
66     UCHAR getPacketType() const { return packetType; }
67     void setSubstream(UCHAR s) { substream = s; }
68     UCHAR getSubstream() const { return substream; }
69     ULLONG getPTS() const;
70     bool hasPTS() const { return (getPTS() != PTS_INVALID); }
71
72     UINT findPictureHeader(bool h264) const;
73     UINT findSeqHeader(bool h264) const;
74     UINT findSeqExtHeader(bool h264) const;
75     UINT countPictureHeaders(bool h264, struct PictCountInfo& pinfo) const;
76     static const ULLONG PTS_INVALID = (1LL << 33);
77
78
79
80   protected:
81     void copyFrom(const PESPacket& packet);
82     UCHAR * data;
83     UINT length, size;
84     UINT data_size;
85     UCHAR packetType;
86     UCHAR substream;
87     UINT mutable seq_header; // 0 = no, 1 = unknown, else = header offset
88 };
89
90 class Demuxer
91 {
92   public:
93     Demuxer();
94     virtual ~Demuxer();
95     static Demuxer* getInstance();
96      int init(Callback* tcallback, DrainTarget* audio, DrainTarget* video,
97          DrainTarget* teletext,
98          ULONG demuxMemoryV, ULONG demuxMemoryA, ULONG demuxMemoryT, double fps=25.,
99          DVBSubtitles* tsubtitles=NULL);
100     virtual void reset();
101     virtual void flush();
102     void flushAudio();
103     void seek();
104     void setVideoStream(int id);
105     //TODO HANS next virtual necessary?
106     //virtual void setAudioStream(int id);
107     void setAudioStream(int id);
108     void setTeletextStream(int id);
109     void setDVBSubtitleStream(int id);
110     bool writeAudio(bool * dataavail=NULL);
111     bool writeVideo(bool * dataavail=NULL);
112     bool writeTeletext(bool * dataavail=NULL);
113
114     virtual int scan(UCHAR* buf, int len) = 0;
115     virtual int findPTS(UCHAR* buf, int len, ULLONG* dest) = 0;
116     virtual int put(UCHAR* buf, int len) = 0;
117     virtual void setFrameNum(ULONG frame) {}
118     virtual void setPacketNum(ULONG packet) {}
119     virtual ULONG getFrameNumFromPTS(ULLONG pts) {return 0;}
120     virtual ULONG getPacketNum() {return 0;}
121
122     bool* getmpAudioChannels(); //Maybe virtual ?
123     bool* getac3AudioChannels(); //Maybe virtual ?
124     bool* getSubtitleChannels();
125     int getselAudioChannel();
126     int getselSubtitleChannel();
127         bool ish264() {return h264;}
128     void seth264(bool newh264){h264=newh264;}
129
130     int getHorizontalSize() { return horizontal_size; }
131     int getVerticalSize() { return vertical_size; }
132     int getAspectRatio(int *tparx,int *tpary) {
133         *tparx=parx; *tpary=pary;return aspect_ratio; }
134     int getFrameRate() { return frame_rate; }
135     int getBitRate() { return bit_rate; }
136     bool getInterlaced() { return interlaced;}
137     ULLONG getVideoPTS() { return video_pts; }
138     ULLONG getAudioPTS() { return audio_pts; }
139
140     enum AspectRatio
141     {
142       ASPECT_1_1  = 1,
143       ASPECT_4_3  = 2,
144       ASPECT_16_9 = 3,
145       ASPECT_221  = 4,
146     };
147
148     // Remove all data from a buffer apart from video PES packets.
149     // Returns the length of the reduced data.
150     // removed *static function*, due to DemuxerTS
151     virtual UINT stripAudio(UCHAR* buf, UINT len);
152     void changeTimes(UCHAR* buf, UINT len,UINT playtime);
153
154     // Scan a buffer to see if video packets are present.
155     // Returns true if video exists; false if not.
156     // removed *static function* for h264 detection
157     static bool scanForVideo(UCHAR* buf, UINT len, bool &ish264);
158
159     enum PESTYPE
160     {
161       PESTYPE_PRIVATE_1 = 0xBD,
162
163       PESTYPE_AUD0 = 0xC0,
164       PESTYPE_AUD1,  PESTYPE_AUD2,  PESTYPE_AUD3,  PESTYPE_AUD4,
165       PESTYPE_AUD5,  PESTYPE_AUD6,  PESTYPE_AUD7,  PESTYPE_AUD8,
166       PESTYPE_AUD9,  PESTYPE_AUD10, PESTYPE_AUD11, PESTYPE_AUD12,
167       PESTYPE_AUD13, PESTYPE_AUD14, PESTYPE_AUD15, PESTYPE_AUD16,
168       PESTYPE_AUD17, PESTYPE_AUD18, PESTYPE_AUD19, PESTYPE_AUD20,
169       PESTYPE_AUD21, PESTYPE_AUD22, PESTYPE_AUD23, PESTYPE_AUD24,
170       PESTYPE_AUD25, PESTYPE_AUD26, PESTYPE_AUD27, PESTYPE_AUD28,
171       PESTYPE_AUD29, PESTYPE_AUD30, PESTYPE_AUD31,
172       PESTYPE_AUDMAX = PESTYPE_AUD31,
173
174       PESTYPE_VID0 = 0xE0,
175       PESTYPE_VID1,  PESTYPE_VID2,  PESTYPE_VID3,  PESTYPE_VID4,
176       PESTYPE_VID5,  PESTYPE_VID6,  PESTYPE_VID7,  PESTYPE_VID8,
177       PESTYPE_VID9,  PESTYPE_VID10, PESTYPE_VID11, PESTYPE_VID12,
178       PESTYPE_VID13, PESTYPE_VID14, PESTYPE_VID15,
179       PESTYPE_VIDMAX = PESTYPE_VID15
180     };
181     enum PESTYPE_SUBSTREAM
182     {
183       PESTYPE_SUBSTREAM_TELETEXT0 = 0x10,
184       PESTYPE_SUBSTREAM_TELETEXT1,PESTYPE_SUBSTREAM_TELETEXT2, PESTYPE_SUBSTREAM_TELETEXT3,
185       PESTYPE_SUBSTREAM_TELETEXT4,PESTYPE_SUBSTREAM_TELETEXT5,PESTYPE_SUBSTREAM_TELETEXT6,
186       PESTYPE_SUBSTREAM_TELETEXT7, PESTYPE_SUBSTREAM_TELETEXT8, PESTYPE_SUBSTREAM_TELETEXT9,
187       PESTYPE_SUBSTREAM_TELETEXT10,PESTYPE_SUBSTREAM_TELETEXT11,PESTYPE_SUBSTREAM_TELETEXT12,
188       PESTYPE_SUBSTREAM_TELETEXT13,PESTYPE_SUBSTREAM_TELETEXT14,PESTYPE_SUBSTREAM_TELETEXT15,
189       PESTYPE_SUBSTREAM_TELETEXTMAX=PESTYPE_SUBSTREAM_TELETEXT15,
190       PESTYPE_SUBSTREAM_DVBSUBTITLE0=0x20,
191       PESTYPE_SUBSTREAM_DVBSUBTITLE1,PESTYPE_SUBSTREAM_DVBSUBTITLE2,PESTYPE_SUBSTREAM_DVBSUBTITLE3,
192       PESTYPE_SUBSTREAM_DVBSUBTITLE4,PESTYPE_SUBSTREAM_DVBSUBTITLE5,PESTYPE_SUBSTREAM_DVBSUBTITLE6,
193       PESTYPE_SUBSTREAM_DVBSUBTITLE7,
194       PESTYPE_SUBSTREAM_DVBSUBTITLEMAX=PESTYPE_SUBSTREAM_DVBSUBTITLE7,
195       PESTYPE_SUBSTREAM_AC30 = 0x80,
196       PESTYPE_SUBSTREAM_AC31,PESTYPE_SUBSTREAM_AC32, PESTYPE_SUBSTREAM_AC33,
197       PESTYPE_SUBSTREAM_AC34,PESTYPE_SUBSTREAM_AC35,PESTYPE_SUBSTREAM_AC36,
198       PESTYPE_SUBSTREAM_AC37,
199       PESTYPE_SUBSTREAM_AC3MAX = PESTYPE_SUBSTREAM_AC37
200     };
201
202   protected:
203     // Operations on PES packets
204     bool submitPacket(PESPacket&);
205     void parsePacketDetails(PESPacket&);
206
207     // General demuxer objects and status indicators
208     static Demuxer* instance;
209     Stream videostream;
210     Stream audiostream;
211     DVBSubtitles* subtitles;
212     Stream teletextstream;
213     int shutdown();
214     bool initted;
215     bool vid_seeking;
216     bool aud_seeking;
217         bool h264;
218     int video_current, audio_current, teletext_current, subtitle_current;
219     int astreamtype;
220     bool livetv;
221
222     // Video stream information
223     void setAspectRatio(enum AspectRatio, int taspectx, int taspecty);
224     int parx;
225     int pary;
226     Callback* callback;
227
228     int horizontal_size;
229     int vertical_size;
230     bool interlaced;
231     int profile;
232     enum AspectRatio aspect_ratio;
233     int arcnt;
234     int frame_rate;
235     int bit_rate;
236     ULLONG video_pts;
237     ULLONG video_pts_seek;
238     ULLONG audio_pts;
239     ULLONG teletext_pts;
240     bool isteletextdecoded;
241
242
243         unsigned int packetnum;
244
245     // Constants
246     static const int FrameRates[9];
247
248         double fps;
249
250     bool ispre_1_3_19;
251     bool avail_mpaudchan[PESTYPE_AUDMAX-PESTYPE_AUD0+1];
252     bool avail_ac3audchan[PESTYPE_SUBSTREAM_AC3MAX-PESTYPE_SUBSTREAM_AC30+1];
253     bool avail_dvbsubtitlechan[PESTYPE_SUBSTREAM_DVBSUBTITLEMAX-PESTYPE_SUBSTREAM_DVBSUBTITLE0+1];
254 };
255
256 #endif