2 Copyright 2005-2008 Mark Calderbank
3 Copyright 2007 Marten Richter (AC3 support)
5 This file is part of VOMP.
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.
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.
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.
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.
44 PESPacket(const PESPacket& packet);
45 PESPacket& operator=(const PESPacket& packet);
47 void init(UCHAR type, UCHAR sub=0);
49 int write(const UCHAR* buf, int len);
51 UCHAR operator[] (UINT index) const;
52 // return data[index] if in bounds, else 0
53 // so no proper error condition but never mind for now
54 const UCHAR* getData() const { return data; }
55 UINT getLength() const { return length; }
56 UINT getSize() const { return size; }
57 UCHAR getPacketType() const { return packetType; }
58 void setSubstream(UCHAR s) { substream = s; }
59 UCHAR getSubstream() const { return substream; }
60 ULLONG getPTS() const;
61 bool hasPTS() const { return (getPTS() != PTS_INVALID); }
63 UINT findPictureHeader() const;
64 UINT findSeqHeader() const;
65 static const ULLONG PTS_INVALID = (1LL << 33);
67 void copyFrom(const PESPacket& packet);
73 UINT mutable seq_header; // 0 = no, 1 = unknown, else = header offset
81 static Demuxer* getInstance();
82 int init(Callback* tcallback, DrainTarget* audio, DrainTarget* video,
83 DrainTarget* teletext,
84 ULONG demuxMemoryV, ULONG demuxMemoryA, ULONG demuxMemoryT,
85 DVBSubtitles* tsubtitles=NULL);
90 void setVideoStream(int id);
91 void setAudioStream(int id);
92 void setTeletextStream(int id);
93 void setDVBSubtitleStream(int id);
98 virtual int scan(UCHAR* buf, int len) = 0;
99 virtual int findPTS(UCHAR* buf, int len, ULLONG* dest) = 0;
100 virtual int put(UCHAR* buf, int len) = 0;
101 virtual void setFrameNum(ULONG frame) {}
102 virtual void setPacketNum(ULONG packet) {}
103 virtual ULONG getFrameNumFromPTS(ULLONG pts) {return 0;}
104 virtual ULONG getPacketNum() {return 0;}
106 bool* getmpAudioChannels(); //Maybe virtual ?
107 bool* getac3AudioChannels(); //Maybe virtual ?
108 bool* getSubtitleChannels();
109 int getselAudioChannel();
110 int getselSubtitleChannel();
112 int getHorizontalSize() { return horizontal_size; }
113 int getVerticalSize() { return vertical_size; }
114 int getAspectRatio() { return aspect_ratio; }
115 int getFrameRate() { return frame_rate; }
116 int getBitRate() { return bit_rate; }
117 ULLONG getVideoPTS() { return video_pts; }
118 ULLONG getAudioPTS() { return audio_pts; }
126 // Remove all data from a buffer apart from video PES packets.
127 // Returns the length of the reduced data.
129 static UINT stripAudio(UCHAR* buf, UINT len);
131 // Scan a buffer to see if video packets are present.
132 // Returns true if video exists; false if not.
134 static bool scanForVideo(UCHAR* buf, UINT len);
138 PESTYPE_PRIVATE_1 = 0xBD,
141 PESTYPE_AUD1, PESTYPE_AUD2, PESTYPE_AUD3, PESTYPE_AUD4,
142 PESTYPE_AUD5, PESTYPE_AUD6, PESTYPE_AUD7, PESTYPE_AUD8,
143 PESTYPE_AUD9, PESTYPE_AUD10, PESTYPE_AUD11, PESTYPE_AUD12,
144 PESTYPE_AUD13, PESTYPE_AUD14, PESTYPE_AUD15, PESTYPE_AUD16,
145 PESTYPE_AUD17, PESTYPE_AUD18, PESTYPE_AUD19, PESTYPE_AUD20,
146 PESTYPE_AUD21, PESTYPE_AUD22, PESTYPE_AUD23, PESTYPE_AUD24,
147 PESTYPE_AUD25, PESTYPE_AUD26, PESTYPE_AUD27, PESTYPE_AUD28,
148 PESTYPE_AUD29, PESTYPE_AUD30, PESTYPE_AUD31,
149 PESTYPE_AUDMAX = PESTYPE_AUD31,
152 PESTYPE_VID1, PESTYPE_VID2, PESTYPE_VID3, PESTYPE_VID4,
153 PESTYPE_VID5, PESTYPE_VID6, PESTYPE_VID7, PESTYPE_VID8,
154 PESTYPE_VID9, PESTYPE_VID10, PESTYPE_VID11, PESTYPE_VID12,
155 PESTYPE_VID13, PESTYPE_VID14, PESTYPE_VID15,
156 PESTYPE_VIDMAX = PESTYPE_VID15
158 enum PESTYPE_SUBSTREAM
160 PESTYPE_SUBSTREAM_TELETEXT0 = 0x10,
161 PESTYPE_SUBSTREAM_TELETEXT1,PESTYPE_SUBSTREAM_TELETEXT2, PESTYPE_SUBSTREAM_TELETEXT3,
162 PESTYPE_SUBSTREAM_TELETEXT4,PESTYPE_SUBSTREAM_TELETEXT5,PESTYPE_SUBSTREAM_TELETEXT6,
163 PESTYPE_SUBSTREAM_TELETEXT7, PESTYPE_SUBSTREAM_TELETEXT8, PESTYPE_SUBSTREAM_TELETEXT9,
164 PESTYPE_SUBSTREAM_TELETEXT10,PESTYPE_SUBSTREAM_TELETEXT11,PESTYPE_SUBSTREAM_TELETEXT12,
165 PESTYPE_SUBSTREAM_TELETEXT13,PESTYPE_SUBSTREAM_TELETEXT14,PESTYPE_SUBSTREAM_TELETEXT15,
166 PESTYPE_SUBSTREAM_TELETEXTMAX=PESTYPE_SUBSTREAM_TELETEXT15,
167 PESTYPE_SUBSTREAM_DVBSUBTITLE0=0x20,
168 PESTYPE_SUBSTREAM_DVBSUBTITLE1,PESTYPE_SUBSTREAM_DVBSUBTITLE2,PESTYPE_SUBSTREAM_DVBSUBTITLE3,
169 PESTYPE_SUBSTREAM_DVBSUBTITLE4,PESTYPE_SUBSTREAM_DVBSUBTITLE5,PESTYPE_SUBSTREAM_DVBSUBTITLE6,
170 PESTYPE_SUBSTREAM_DVBSUBTITLE7,
171 PESTYPE_SUBSTREAM_DVBSUBTITLEMAX=PESTYPE_SUBSTREAM_DVBSUBTITLE7,
172 PESTYPE_SUBSTREAM_AC30 = 0x80,
173 PESTYPE_SUBSTREAM_AC31,PESTYPE_SUBSTREAM_AC32, PESTYPE_SUBSTREAM_AC33,
174 PESTYPE_SUBSTREAM_AC34,PESTYPE_SUBSTREAM_AC35,PESTYPE_SUBSTREAM_AC36,
175 PESTYPE_SUBSTREAM_AC37,
176 PESTYPE_SUBSTREAM_AC3MAX = PESTYPE_SUBSTREAM_AC37
180 // Operations on PES packets
181 bool submitPacket(PESPacket&);
182 void parsePacketDetails(PESPacket&);
184 // General demuxer objects and status indicators
185 static Demuxer* instance;
188 DVBSubtitles* subtitles;
189 Stream teletextstream;
194 int video_current, audio_current, teletext_current, subtitle_current;
196 // Video stream information
197 void setAspectRatio(enum AspectRatio);
202 enum AspectRatio aspect_ratio;
207 ULLONG video_pts_seek;
210 bool isteletextdecoded;
213 static const int FrameRates[9];
216 bool avail_mpaudchan[PESTYPE_AUDMAX-PESTYPE_AUD0+1];
217 bool avail_ac3audchan[PESTYPE_SUBSTREAM_AC3MAX-PESTYPE_SUBSTREAM_AC30+1];
218 bool avail_dvbsubtitlechan[PESTYPE_SUBSTREAM_DVBSUBTITLEMAX-PESTYPE_SUBSTREAM_DVBSUBTITLE0+1];