]> git.vomp.tv Git - vompclient.git/blob - demuxer.h
Windows port changes
[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
30 #ifndef DEMUXER_H
31 #define DEMUXER_H
32
33 #include <stdio.h>
34 #include <memory.h>
35 #include "stream.h"
36 #include "log.h"
37 #include "defines.h"
38 #include "callback.h"
39 #include "draintarget.h"
40
41 #include "audio.h"
42 #include "video.h"
43
44 class Demuxer
45 {
46 public: //MS Visual C++ need this, private does not work for DemuxerVDR, Marten
47   class PESPacket
48   {
49     public:
50       PESPacket();
51       void init(UCHAR type);
52       int  write(UCHAR* buf, int len);
53 #ifndef NEW_DEMUXER
54       int  submit();
55 #else
56     int  submit(ULLONG cur_pos);
57 #endif
58     private:
59       UCHAR data[0x10000];
60       UINT length, size;
61       bool closed;
62       UCHAR packetType;
63       UINT submitted;
64       void parseDetails();
65   };
66   friend class PESPacket;
67
68   public:
69     Demuxer();
70     virtual ~Demuxer();
71     static Demuxer* getInstance();
72     int init(Callback* callback);
73     void reset();
74     virtual void flush();
75     void flushAudio();
76     void seek();
77     void setVideoStream(int id);
78     void setAudioStream(int id);
79 #ifndef NEW_DEMUXER
80     int writeAudio(int fd);
81     int writeVideo(int fd);
82 #else
83     int writeAudio(DrainTarget* dt);
84     int writeVideo(DrainTarget* dt);
85 #endif
86
87     virtual int scan(UCHAR* buf, int len) = 0;
88     virtual int findVideoPTS(UCHAR* buf, int len, ULLONG* dest) = 0;
89 #ifndef NEW_DEMUXER
90     virtual int put(UCHAR* buf, int len) = 0;
91 #else
92   virtual int put(UCHAR* buf, int len,ULLONG cur_pos) = 0;
93 #endif
94
95     int getHorizontalSize() { return horizontal_size; }
96     int getVerticalSize() { return vertical_size; }
97     int getAspectRatio() { return aspect_ratio; }
98     int getFrameRate() { return frame_rate; }
99     int getBitRate() { return bit_rate; }
100     ULLONG getVideoPTS() { return video_pts; }
101
102     enum AspectRatio
103     {
104       ASPECT_4_3  = 2,
105       ASPECT_16_9 = 3
106     };
107
108   protected:
109     // General demuxer objects and status indicators
110     static Demuxer* instance;
111     Stream videostream;
112     Stream audiostream;
113     int shutdown();
114     bool initted;
115     bool vid_seeking;
116     bool aud_seeking;
117     int video_current, audio_current;
118
119     // Video stream information
120     void setAspectRatio(enum AspectRatio);
121     Callback* callback;
122
123     int horizontal_size;
124     int vertical_size;
125     enum AspectRatio aspect_ratio;
126     int arcnt;
127     int frame_rate;
128     int bit_rate;
129     ULLONG video_pts;
130     ULLONG video_pts_seek;
131     ULLONG audio_pts;
132
133     // Constants
134     static const int demuxMemoryV = 2097152;
135     static const int demuxMemoryA = 524288;
136     static const int FrameRates[9];
137
138     enum PESTYPE
139     {
140       PESTYPE_PRIVATE_1 = 0xBD,
141
142       PESTYPE_AUD0 = 0xC0,
143       PESTYPE_AUD1,  PESTYPE_AUD2,  PESTYPE_AUD3,  PESTYPE_AUD4,
144       PESTYPE_AUD5,  PESTYPE_AUD6,  PESTYPE_AUD7,  PESTYPE_AUD8,
145       PESTYPE_AUD9,  PESTYPE_AUD10, PESTYPE_AUD11, PESTYPE_AUD12,
146       PESTYPE_AUD13, PESTYPE_AUD14, PESTYPE_AUD15, PESTYPE_AUD16,
147       PESTYPE_AUD17, PESTYPE_AUD18, PESTYPE_AUD19, PESTYPE_AUD20,
148       PESTYPE_AUD21, PESTYPE_AUD22, PESTYPE_AUD23, PESTYPE_AUD24,
149       PESTYPE_AUD25, PESTYPE_AUD26, PESTYPE_AUD27, PESTYPE_AUD28,
150       PESTYPE_AUD29, PESTYPE_AUD30, PESTYPE_AUD31,
151       PESTYPE_AUDMAX = PESTYPE_AUD31,
152
153       PESTYPE_VID0 = 0xE0,
154       PESTYPE_VID1,  PESTYPE_VID2,  PESTYPE_VID3,  PESTYPE_VID4,
155       PESTYPE_VID5,  PESTYPE_VID6,  PESTYPE_VID7,  PESTYPE_VID8,
156       PESTYPE_VID9,  PESTYPE_VID10, PESTYPE_VID11, PESTYPE_VID12,
157       PESTYPE_VID13, PESTYPE_VID14, PESTYPE_VID15,
158       PESTYPE_VIDMAX = PESTYPE_VID15
159     };
160
161 };
162
163 #endif