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