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