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