]> git.vomp.tv Git - vompclient.git/blob - demuxer.h
Connection failure detection
[vompclient.git] / demuxer.h
1 /*
2     Copyright 2005 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
40 class Demuxer
41 {
42   public:
43     Demuxer();
44     ~Demuxer();
45     static Demuxer* getInstance();
46     int init(Callback* callback);
47     void reset();
48     void flush();
49     void flushAudio();
50     void seek();
51     void setVideoStream(int id);
52     void setAudioStream(int id);
53     int writeAudio(int fd);
54     int writeVideo(int fd);
55     int scan(UCHAR* buf, int len);
56     int findVideoPTS(UCHAR* buf, int len, ULLONG* dest);
57     int put(UCHAR* buf, int len);
58
59     int getHorizontalSize() { return horizontal_size; }
60     int getVerticalSize() { return vertical_size; }
61     int getAspectRatio() { return aspect_ratio; }
62     int getFrameRate() { return frame_rate; }
63     int getBitRate() { return bit_rate; }
64     ULLONG getVideoPTS() { return video_pts; }
65
66     enum AspectRatio
67     {
68       ASPECT_4_3  = 2,
69       ASPECT_16_9 = 3
70     };
71
72   private:
73     static Demuxer* instance;
74     Stream videostream;
75     Stream audiostream;
76     int shutdown();
77     int initted;
78     int seeking;
79     UCHAR* inbuf;
80
81     void setAspectRatio(enum AspectRatio);
82     Callback* callback;
83
84     int video_current, audio_current;
85     int state_frametype, state_framepos;
86     int state_stream_fill, state_vid_parsed;
87     int frame_length;
88     int parse_find_frame(int len);
89     int parse_video_frame(int len, int* full);
90     int parse_audio_frame(int len, int* full);
91     int parse_private1_frame(int len, int* full);
92     void parse_video_details(UCHAR* buf, int len);
93
94     UCHAR* local_frame;
95     static const int demuxMemoryV = 2097152;
96     static const int demuxMemoryA = 524288;
97     static const int Demuxer::FrameRates[9];
98
99     enum FRAMETYPE
100     {
101       FRAMETYPE_PRIVATE_1 = 0xbd,
102
103       FRAMETYPE_AUD0 = 0xc0,
104       FRAMETYPE_AUD1,
105       FRAMETYPE_AUD2,
106       FRAMETYPE_AUD3,
107       FRAMETYPE_AUD4,
108       FRAMETYPE_AUD5,
109       FRAMETYPE_AUD6,
110       FRAMETYPE_AUD7,
111       FRAMETYPE_AUD8,
112       FRAMETYPE_AUD9,
113       FRAMETYPE_AUD10,
114       FRAMETYPE_AUD11,
115       FRAMETYPE_AUD12,
116       FRAMETYPE_AUD13,
117       FRAMETYPE_AUD14,
118       FRAMETYPE_AUD15,
119       FRAMETYPE_AUD16,
120       FRAMETYPE_AUD17,
121       FRAMETYPE_AUD18,
122       FRAMETYPE_AUD19,
123       FRAMETYPE_AUD20,
124       FRAMETYPE_AUD21,
125       FRAMETYPE_AUD22,
126       FRAMETYPE_AUD23,
127       FRAMETYPE_AUD24,
128       FRAMETYPE_AUD25,
129       FRAMETYPE_AUD26,
130       FRAMETYPE_AUD27,
131       FRAMETYPE_AUD28,
132       FRAMETYPE_AUD29,
133       FRAMETYPE_AUD30,
134       FRAMETYPE_AUD31,
135       FRAMETYPE_AUDMAX = FRAMETYPE_AUD31,
136
137       FRAMETYPE_VID0 = 0xe0,
138       FRAMETYPE_VID1,
139       FRAMETYPE_VID2,
140       FRAMETYPE_VID3,
141       FRAMETYPE_VID4,
142       FRAMETYPE_VID5,
143       FRAMETYPE_VID6,
144       FRAMETYPE_VID7,
145       FRAMETYPE_VID8,
146       FRAMETYPE_VID9,
147       FRAMETYPE_VID10,
148       FRAMETYPE_VID11,
149       FRAMETYPE_VID12,
150       FRAMETYPE_VID13,
151       FRAMETYPE_VID14,
152       FRAMETYPE_VID15,
153       FRAMETYPE_VIDMAX = FRAMETYPE_VID15
154     };
155
156     int horizontal_size;
157     int vertical_size;
158     enum AspectRatio aspect_ratio;
159     int frame_rate;
160     int bit_rate;
161     ULLONG video_pts;
162 };
163
164 #endif