1545
|
1 #ifndef __LIBWIN32_H
|
|
2 #define __LIBWIN32_H
|
|
3
|
|
4 #define VFW_E_INVALIDMEDIATYPE 0x80040200
|
|
5 #define VFW_E_INVALIDSUBTYPE 0x80040201
|
|
6 #define VFW_E_ALREADY_CONNECTED 0x80040204
|
|
7 #define VFW_E_FILTER_ACTIVE 0x80040205
|
|
8 #define VFW_E_NO_ACCEPTABLE_TYPES 0x80040207
|
|
9 #define VFW_E_NOT_CONNECTED 0x80040209
|
|
10 #define VFW_E_NO_ALLOCATOR 0x8004020A
|
|
11 #define VFW_E_NOT_RUNNING 0x80040226
|
|
12 #define VFW_E_TYPE_NOT_ACCEPTED 0x8004022A
|
|
13 #define VFW_E_SAMPLE_REJECTED 0x8004022B
|
|
14
|
|
15 #include <sys/types.h>
|
|
16 #include <inttypes.h>
|
|
17
|
|
18 #ifndef NOAVIFILE_HEADERS
|
|
19 #include <audiodecoder.h>
|
|
20 #include <audioencoder.h>
|
|
21 #include <videodecoder.h>
|
|
22 #include <videoencoder.h>
|
|
23 #include <except.h>
|
|
24 #include <fourcc.h>
|
|
25
|
|
26 #else
|
|
27 // code for mplayer team
|
|
28
|
1558
|
29 //#define FATAL(a) // you don't need exception - if you want - just fill more code
|
|
30 #define FATAL(X...) FatalError(__MODULE__,__FILE__,__LINE__,X)
|
1545
|
31 #include <wine/mmreg.h>
|
|
32 #include <wine/winreg.h>
|
|
33 #include <wine/vfw.h>
|
|
34 #include <com.h>
|
1558
|
35 #include <stdarg.h>
|
1545
|
36 #include <string>
|
1558
|
37 #include <stdio.h>
|
1545
|
38
|
|
39 typedef unsigned int fourcc_t;
|
1558
|
40
|
1545
|
41 struct FatalError
|
|
42 {
|
1558
|
43 FatalError(const char* mod, const char* f, int l, const char* desc,...)
|
|
44 {
|
|
45 printf("FATAL: module: %s source: %s line %d ", mod, f, l);
|
|
46 va_list va;
|
|
47 va_start(va, desc);
|
|
48 vprintf(desc, va);
|
|
49 va_end(va);
|
|
50 }
|
1545
|
51 void PrintAll() {}
|
|
52 };
|
|
53
|
|
54 struct CodecInfo
|
|
55 {
|
|
56 std::string dll;
|
|
57 GUID guid;
|
|
58 };
|
|
59
|
|
60 struct CImage { // public your_libvo_mem
|
|
61 char* ptr;
|
|
62 char* Data() { return ptr; } // pointer to memory block
|
|
63 /* if you support such surface: */
|
|
64 static bool Supported(fourcc_t csp, int bits) { return true; }
|
|
65 };
|
|
66
|
|
67 // might be minimalized to contain just those which are needed by DS_VideoDecoder
|
|
68
|
|
69 #ifndef mmioFOURCC
|
|
70 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
|
|
71 ( (long)(unsigned char)(ch0) | ( (long)(unsigned char)(ch1) << 8 ) | \
|
|
72 ( (long)(unsigned char)(ch2) << 16 ) | ( (long)(unsigned char)(ch3) << 24 ) )
|
|
73 #endif /* mmioFOURCC */
|
|
74
|
|
75 /* OpenDivX */
|
|
76 #define fccMP4S mmioFOURCC('M', 'P', '4', 'S')
|
|
77 #define fccmp4s mmioFOURCC('m', 'p', '4', 's')
|
|
78 #define fccDIVX mmioFOURCC('D', 'I', 'V', 'X')
|
|
79 #define fccdivx mmioFOURCC('d', 'i', 'v', 'x')
|
|
80 #define fccDIV1 mmioFOURCC('D', 'I', 'V', '1')
|
|
81 #define fccdiv1 mmioFOURCC('d', 'i', 'v', '1')
|
|
82
|
|
83 /* DivX codecs */
|
|
84 #define fccDIV2 mmioFOURCC('D', 'I', 'V', '2')
|
|
85 #define fccdiv2 mmioFOURCC('d', 'i', 'v', '2')
|
|
86 #define fccDIV3 mmioFOURCC('D', 'I', 'V', '3')
|
|
87 #define fccdiv3 mmioFOURCC('d', 'i', 'v', '3')
|
|
88 #define fccDIV4 mmioFOURCC('D', 'I', 'V', '4')
|
|
89 #define fccdiv4 mmioFOURCC('d', 'i', 'v', '4')
|
|
90 #define fccDIV5 mmioFOURCC('D', 'I', 'V', '5')
|
|
91 #define fccdiv5 mmioFOURCC('d', 'i', 'v', '5')
|
|
92 #define fccDIV6 mmioFOURCC('D', 'I', 'V', '6')
|
|
93 #define fccdiv6 mmioFOURCC('d', 'i', 'v', '6')
|
|
94 #define fccMP41 mmioFOURCC('M', 'P', '4', '1')
|
|
95 #define fccmp41 mmioFOURCC('m', 'p', '4', '1')
|
|
96 #define fccMP43 mmioFOURCC('M', 'P', '4', '3')
|
|
97 #define fccmp43 mmioFOURCC('m', 'p', '4', '3')
|
|
98 /* old ms mpeg-4 codecs */
|
|
99 #define fccMP42 mmioFOURCC('M', 'P', '4', '2')
|
|
100 #define fccmp42 mmioFOURCC('m', 'p', '4', '2')
|
|
101 #define fccMPG4 mmioFOURCC('M', 'P', 'G', '4')
|
|
102 #define fccmpg4 mmioFOURCC('m', 'p', 'g', '4')
|
|
103 /* Windows media codecs */
|
|
104 #define fccWMV1 mmioFOURCC('W', 'M', 'V', '1')
|
|
105 #define fccwmv1 mmioFOURCC('w', 'm', 'v', '1')
|
|
106 #define fccWMV2 mmioFOURCC('W', 'M', 'V', '2')
|
|
107 #define fccwmv2 mmioFOURCC('w', 'm', 'v', '2')
|
|
108 #define fccMWV1 mmioFOURCC('M', 'W', 'V', '1')
|
|
109
|
|
110 /* Angel codecs */
|
|
111 #define fccAP41 mmioFOURCC('A', 'P', '4', '1')
|
|
112 #define fccap41 mmioFOURCC('a', 'p', '4', '1')
|
|
113 #define fccAP42 mmioFOURCC('A', 'P', '4', '2')
|
|
114 #define fccap42 mmioFOURCC('a', 'p', '4', '2')
|
|
115
|
|
116 /* other codecs */
|
|
117 #define fccIV31 mmioFOURCC('I', 'V', '3', '1')
|
|
118 #define fcciv31 mmioFOURCC('i', 'v', '3', '1')
|
|
119 #define fccIV32 mmioFOURCC('I', 'V', '3', '2')
|
|
120 #define fcciv32 mmioFOURCC('i', 'v', '3', '2')
|
|
121 #define fccIV41 mmioFOURCC('I', 'V', '4', '1')
|
|
122 #define fcciv41 mmioFOURCC('i', 'v', '4', '1')
|
|
123 #define fccIV50 mmioFOURCC('I', 'V', '5', '0')
|
|
124 #define fcciv50 mmioFOURCC('i', 'v', '5', '0')
|
|
125 #define fccI263 mmioFOURCC('I', '2', '6', '3')
|
|
126 #define fcci263 mmioFOURCC('i', '2', '6', '3')
|
|
127
|
|
128 #define fccMJPG mmioFOURCC('M', 'J', 'P', 'G')
|
|
129 #define fccmjpg mmioFOURCC('m', 'j', 'p', 'g')
|
|
130
|
|
131 #define fccHFYU mmioFOURCC('H', 'F', 'Y', 'U')
|
|
132
|
|
133 #define fcccvid mmioFOURCC('c', 'v', 'i', 'd')
|
|
134 #define fccdvsd mmioFOURCC('d', 'v', 's', 'd')
|
|
135
|
|
136 /* Ati codecs */
|
|
137 #define fccVCR2 mmioFOURCC('V', 'C', 'R', '2')
|
|
138 #define fccVCR1 mmioFOURCC('V', 'C', 'R', '1')
|
|
139 #define fccVYUY mmioFOURCC('V', 'Y', 'U', 'Y')
|
|
140 #define fccYVU9 mmioFOURCC('I', 'Y', 'U', '9')
|
|
141
|
|
142 /* Asus codecs */
|
|
143 #define fccASV1 mmioFOURCC('A', 'S', 'V', '1')
|
|
144 #define fccASV2 mmioFOURCC('A', 'S', 'V', '2')
|
|
145
|
|
146 /* Microsoft video */
|
|
147 #define fcccram mmioFOURCC('c', 'r', 'a', 'm')
|
|
148 #define fccCRAM mmioFOURCC('C', 'R', 'A', 'M')
|
|
149 #define fccMSVC mmioFOURCC('M', 'S', 'V', 'C')
|
|
150
|
|
151
|
|
152 #define fccMSZH mmioFOURCC('M', 'S', 'Z', 'H')
|
|
153
|
|
154 #define fccZLIB mmioFOURCC('Z', 'L', 'I', 'B')
|
|
155
|
|
156 #define fccTM20 mmioFOURCC('T', 'M', '2', '0')
|
|
157
|
|
158 #define fccYUV mmioFOURCC('Y', 'U', 'V', ' ')
|
|
159 #define fccYUY2 mmioFOURCC('Y', 'U', 'Y', '2')
|
|
160 #define fccYV12 mmioFOURCC('Y', 'V', '1', '2')/* Planar mode: Y + V + U (3 planes) */
|
|
161 #define fccI420 mmioFOURCC('I', '4', '2', '0')
|
|
162 #define fccIYUV mmioFOURCC('I', 'Y', 'U', 'V')/* Planar mode: Y + U + V (3 planes) */
|
|
163 #define fccUYVY mmioFOURCC('U', 'Y', 'V', 'Y')/* Packed mode: U0+Y0+V0+Y1 (1 plane) */
|
|
164 #define fccYVYU mmioFOURCC('Y', 'V', 'Y', 'U')/* Packed mode: Y0+V0+Y1+U0 (1 plane) */
|
|
165
|
|
166
|
|
167 struct BitmapInfo : public BITMAPINFOHEADER
|
|
168 {
|
|
169 int colors[3];
|
|
170
|
|
171 void SetBitFields16(){
|
|
172 biSize=sizeof(BITMAPINFOHEADER)+12;
|
|
173 biCompression=3;//BI_BITFIELDS
|
|
174 biBitCount=16;
|
|
175 biSizeImage=abs((int)(2*biWidth*biHeight));
|
|
176 colors[0]=0xF800;
|
|
177 colors[1]=0x07E0;
|
|
178 colors[2]=0x001F;
|
|
179 }
|
|
180 void SetBitFields15(){
|
|
181 biSize=sizeof(BITMAPINFOHEADER)+12;
|
|
182 biCompression=3;//BI_BITFIELDS
|
|
183 biBitCount=16;
|
|
184 biSizeImage=abs((int)(2*biWidth*biHeight));
|
|
185 colors[0]=0x7C00;
|
|
186 colors[1]=0x03E0;
|
|
187 colors[2]=0x001F;
|
|
188 }
|
|
189 void SetRGB(){
|
|
190 biSize = sizeof(BITMAPINFOHEADER);
|
|
191 biCompression = 0; //BI_RGB
|
|
192 //biHeight = labs(biHeight);
|
|
193 biSizeImage = labs(biWidth * biHeight) * ((biBitCount + 7) / 8);
|
|
194 }
|
|
195 void SetBits(int bits) {
|
|
196 switch (bits){
|
|
197 case 15: SetBitFields15();break;
|
|
198 case 16: SetBitFields16();break;
|
|
199 default: biBitCount = bits; SetRGB();break;
|
|
200 }
|
|
201 }
|
|
202 void SetSpace(int csp,int bits) {
|
|
203 biSize = sizeof(BITMAPINFOHEADER);
|
|
204 biCompression=csp;
|
|
205 biBitCount=bits;
|
|
206 biSizeImage=labs(biBitCount*biWidth*biHeight)>>3;
|
|
207 }
|
|
208 void SetSpace(int csp) {
|
|
209 int bits=0;
|
|
210 switch(csp){
|
|
211 case fccYUV:
|
|
212 bits=24;break;
|
|
213 case fccYUY2:
|
|
214 case fccUYVY:
|
|
215 case fccYVYU:
|
|
216 bits=16;break;
|
|
217 case fccYV12:
|
|
218 case fccIYUV:
|
|
219 case fccI420:
|
|
220 bits=12;break;
|
|
221 }
|
|
222 if (csp != 0 && csp != 3 && biHeight > 0)
|
|
223 biHeight *= -1; // YUV formats uses should have height < 0
|
|
224 SetSpace(csp,bits);
|
|
225 }
|
|
226
|
|
227 };
|
|
228
|
|
229 struct IAudioDecoder
|
|
230 {
|
|
231 WAVEFORMATEX in_fmt;
|
|
232 const CodecInfo& record;
|
|
233 IAudioDecoder(const CodecInfo& r, const WAVEFORMATEX* w) : record(r)
|
|
234 {
|
|
235 in_fmt = *w;
|
|
236 }
|
|
237 };
|
|
238
|
|
239 struct IAudioEncoder
|
|
240 {
|
|
241 IAudioEncoder(const CodecInfo&, WAVEFORMATEX*) {}
|
|
242 // you do not need this one...
|
|
243 };
|
|
244
|
|
245 struct IVideoDecoder
|
|
246 {
|
|
247 int VBUFSIZE;
|
|
248 int QMARKHI;
|
|
249 int QMARKLO;
|
|
250 int DMARKHI;
|
|
251 int DMARKLO;
|
|
252
|
|
253 enum CAPS
|
|
254 {
|
|
255 CAP_NONE = 0,
|
|
256 CAP_YUY2 = 1,
|
|
257 CAP_YV12 = 2,
|
|
258 CAP_IYUV = 4,
|
|
259 CAP_UYVY = 8,
|
|
260 CAP_YVYU = 16,
|
|
261 CAP_I420 = 32,
|
|
262 };
|
|
263 enum DecodingMode
|
|
264 {
|
|
265 DIRECT = 0,
|
|
266 REALTIME,
|
|
267 REALTIME_QUALITY_AUTO,
|
|
268 };
|
|
269 enum DecodingState
|
|
270 {
|
|
271 STOP = 0,
|
|
272 START,
|
|
273 };
|
|
274 IVideoDecoder(const CodecInfo& info, const BITMAPINFOHEADER& format) : record(info)
|
|
275 {
|
|
276 // implement init part
|
|
277 unsigned bihs = (format.biSize < (int) sizeof(BITMAPINFOHEADER)) ?
|
|
278 sizeof(BITMAPINFOHEADER) : format.biSize;
|
|
279 m_bh = (BITMAPINFOHEADER*) new char[bihs];
|
|
280 memcpy(m_bh, &format, bihs);
|
|
281 m_State = STOP;
|
|
282 //m_pFrame = 0;
|
|
283 m_Mode = DIRECT;
|
|
284 m_iDecpos = 0;
|
|
285 m_iPlaypos = -1;
|
|
286 m_fQuality = 0.0f;
|
|
287 m_bCapable16b = true;
|
|
288
|
|
289 }
|
|
290 virtual ~IVideoDecoder(){};
|
1558
|
291 // use this one
|
|
292 int Decode(void* src, size_t size, int is_keyframe, CImage* pImage)
|
|
293 { return DecodeInternal(src, size, is_keyframe, pImage); }
|
|
294 void Stop(){ StopInternal(); m_State = STOP;}
|
|
295 void Start(){StartInternal(); m_State = START;}
|
|
296 protected:
|
|
297 virtual int DecodeInternal(void* src, size_t size, int is_keyframe, CImage* pImage) = 0;
|
1545
|
298 virtual void StartInternal()=0;
|
|
299 virtual void StopInternal()=0;
|
|
300
|
|
301 const CodecInfo& record;
|
|
302 DecodingMode m_Mode; // should we do precaching (or even change Quality on the fly)
|
|
303 DecodingState m_State;
|
|
304 int m_iDecpos;
|
|
305 int m_iPlaypos;
|
|
306 float m_fQuality; // quality for the progress bar 0..1(best)
|
|
307 bool m_bCapable16b;
|
|
308
|
|
309 BITMAPINFOHEADER* m_bh; // format of input data (might be larger - e.g. huffyuv)
|
|
310 BitmapInfo m_decoder; // format of decoder output
|
|
311 BitmapInfo m_obh; // format of returned frames
|
|
312 };
|
|
313
|
|
314 struct IRtConfig
|
|
315 {
|
|
316 };
|
|
317
|
|
318
|
|
319
|
|
320 #endif
|
|
321
|
|
322 #endif
|