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