]> git.vomp.tv Git - vompclient.git/blob - demuxer.h
New player, ffwd/fbwd, iframe navigation stuff
[vompclient.git] / demuxer.h
1 /*
2     Copyright 2005-2006 Mark Calderbank
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 /*
22
23 Thanks goes to Jon Gettler of the MVPMC project and Stephen Rice for
24 the demuxer in mvpmc. It was used in the creation of this Demuxer,
25 however, no code was copied verbatim.
26
27 */
28
29 #ifndef DEMUXER_H
30 #define DEMUXER_H
31
32 #include <stdio.h>
33 #include <memory.h>
34 #include "stream.h"
35 #include "log.h"
36 #include "defines.h"
37 #include "callback.h"
38 #include "draintarget.h"
39
40 class Demuxer
41 {
42 protected:
43   class PESPacket
44   {
45     public:
46       PESPacket();
47       void init(UCHAR type);
48       int  write(UCHAR* buf, int len);
49       int  submit();
50     protected:
51       UCHAR data[0x10000];
52       UINT length, size;
53       bool closed;
54       UCHAR packetType;
55       ULLONG pts;
56       bool seq_header;
57       UINT submitted;
58       virtual void parseDetails();
59       UINT findPictureHeader();
60
61       static const ULLONG PTS_INVALID;
62   };
63   friend class PESPacket;
64
65   public:
66     Demuxer();
67     virtual ~Demuxer();
68     static Demuxer* getInstance();
69     int init(Callback* callback, DrainTarget* audio, DrainTarget* video);
70     virtual void reset();
71     virtual void flush();
72     void flushAudio();
73     void seek();
74     void setVideoStream(int id);
75     void setAudioStream(int id);
76     bool writeAudio();
77     bool writeVideo();
78
79     virtual int scan(UCHAR* buf, int len) = 0;
80     virtual int findVideoPTS(UCHAR* buf, int len, ULLONG* dest) = 0;
81     virtual int put(UCHAR* buf, int len) = 0;
82     virtual void setFrameNum(ULONG frame) {}
83     virtual ULONG getFrameNumFromPTS(ULLONG pts) {return 0;}
84
85     int getHorizontalSize() { return horizontal_size; }
86     int getVerticalSize() { return vertical_size; }
87     int getAspectRatio() { return aspect_ratio; }
88     int getFrameRate() { return frame_rate; }
89     int getBitRate() { return bit_rate; }
90     ULLONG getVideoPTS() { return video_pts; }
91
92     enum AspectRatio
93     {
94       ASPECT_4_3  = 2,
95       ASPECT_16_9 = 3
96     };
97
98     // Strip audio packets from buffer, leaving video only *static function*
99     static UINT stripAudio(UCHAR* buf, UINT len);
100
101   protected:
102     // General demuxer objects and status indicators
103     static Demuxer* instance;
104     Stream videostream;
105     Stream audiostream;
106     int shutdown();
107     bool initted;
108     bool vid_seeking;
109     bool aud_seeking;
110     int video_current, audio_current;
111
112     // Video stream information
113     void setAspectRatio(enum AspectRatio);
114     Callback* callback;
115
116     int horizontal_size;
117     int vertical_size;
118     enum AspectRatio aspect_ratio;
119     int arcnt;
120     int frame_rate;
121     int bit_rate;
122     ULLONG video_pts;
123     ULLONG video_pts_seek;
124     ULLONG audio_pts;
125
126     // Constants
127     static const int demuxMemoryV = 2097152;
128     static const int demuxMemoryA = 524288;
129     static const int FrameRates[9];
130
131     enum PESTYPE
132     {
133       PESTYPE_PRIVATE_1 = 0xBD,
134
135       PESTYPE_AUD0 = 0xC0,
136       PESTYPE_AUD1,  PESTYPE_AUD2,  PESTYPE_AUD3,  PESTYPE_AUD4,
137       PESTYPE_AUD5,  PESTYPE_AUD6,  PESTYPE_AUD7,  PESTYPE_AUD8,
138       PESTYPE_AUD9,  PESTYPE_AUD10, PESTYPE_AUD11, PESTYPE_AUD12,
139       PESTYPE_AUD13, PESTYPE_AUD14, PESTYPE_AUD15, PESTYPE_AUD16,
140       PESTYPE_AUD17, PESTYPE_AUD18, PESTYPE_AUD19, PESTYPE_AUD20,
141       PESTYPE_AUD21, PESTYPE_AUD22, PESTYPE_AUD23, PESTYPE_AUD24,
142       PESTYPE_AUD25, PESTYPE_AUD26, PESTYPE_AUD27, PESTYPE_AUD28,
143       PESTYPE_AUD29, PESTYPE_AUD30, PESTYPE_AUD31,
144       PESTYPE_AUDMAX = PESTYPE_AUD31,
145
146       PESTYPE_VID0 = 0xE0,
147       PESTYPE_VID1,  PESTYPE_VID2,  PESTYPE_VID3,  PESTYPE_VID4,
148       PESTYPE_VID5,  PESTYPE_VID6,  PESTYPE_VID7,  PESTYPE_VID8,
149       PESTYPE_VID9,  PESTYPE_VID10, PESTYPE_VID11, PESTYPE_VID12,
150       PESTYPE_VID13, PESTYPE_VID14, PESTYPE_VID15,
151       PESTYPE_VIDMAX = PESTYPE_VID15
152     };
153
154 };
155
156 #endif