]> git.vomp.tv Git - vompclient.git/blob - demuxer.h
Fix some demuxer bugs
[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     int parse_private1_frame(int len, int* full);
74     void parse_video_details(UCHAR* buf, int len);
75
76     UCHAR* local_frame;
77     static const int demuxMemory = 2097152;
78     static const int Demuxer::FrameRates[9];
79
80     enum FRAMETYPE
81     {
82       FRAMETYPE_PRIVATE_1 = 0xbd,
83
84       FRAMETYPE_AUD0 = 0xc0,
85       FRAMETYPE_AUD1,
86       FRAMETYPE_AUD2,
87       FRAMETYPE_AUD3,
88       FRAMETYPE_AUD4,
89       FRAMETYPE_AUD5,
90       FRAMETYPE_AUD6,
91       FRAMETYPE_AUD7,
92       FRAMETYPE_AUD8,
93       FRAMETYPE_AUD9,
94       FRAMETYPE_AUD10,
95       FRAMETYPE_AUD11,
96       FRAMETYPE_AUD12,
97       FRAMETYPE_AUD13,
98       FRAMETYPE_AUD14,
99       FRAMETYPE_AUD15,
100       FRAMETYPE_AUD16,
101       FRAMETYPE_AUD17,
102       FRAMETYPE_AUD18,
103       FRAMETYPE_AUD19,
104       FRAMETYPE_AUD20,
105       FRAMETYPE_AUD21,
106       FRAMETYPE_AUD22,
107       FRAMETYPE_AUD23,
108       FRAMETYPE_AUD24,
109       FRAMETYPE_AUD25,
110       FRAMETYPE_AUD26,
111       FRAMETYPE_AUD27,
112       FRAMETYPE_AUD28,
113       FRAMETYPE_AUD29,
114       FRAMETYPE_AUD30,
115       FRAMETYPE_AUD31,
116       FRAMETYPE_AUDMAX = FRAMETYPE_AUD31,
117
118       FRAMETYPE_VID0 = 0xe0,
119       FRAMETYPE_VID1,
120       FRAMETYPE_VID2,
121       FRAMETYPE_VID3,
122       FRAMETYPE_VID4,
123       FRAMETYPE_VID5,
124       FRAMETYPE_VID6,
125       FRAMETYPE_VID7,
126       FRAMETYPE_VID8,
127       FRAMETYPE_VID9,
128       FRAMETYPE_VID10,
129       FRAMETYPE_VID11,
130       FRAMETYPE_VID12,
131       FRAMETYPE_VID13,
132       FRAMETYPE_VID14,
133       FRAMETYPE_VID15,
134       FRAMETYPE_VIDMAX = FRAMETYPE_VID15
135     };
136
137     enum AspectRatio
138     {
139       ASPECT_4_3  = 2,
140       ASPECT_16_9 = 3
141     };
142
143     int horizontal_size;
144     int vertical_size;
145     enum AspectRatio aspect_ratio;
146     int frame_rate;
147     int bit_rate;
148 };
149
150 #endif