Increase ParseScript cache from 30 to 90 seconds
[xy_vsfilter.git] / src / dsutil / MediaTypes.cpp
blob9c64e9eabade5937aca168e129eaffc2024e5b62
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "stdafx.h"
23 #include <initguid.h>
24 #include "..\..\include\moreuuids.h"
25 #include "MediaTypes.h"
26 #include "DSUtil.h"
28 #define VIH_NORMAL (sizeof(VIDEOINFOHEADER))
29 #define VIH_BITFIELDS (sizeof(VIDEOINFOHEADER)+3*sizeof(RGBQUAD))
30 #define VIH2_NORMAL (sizeof(VIDEOINFOHEADER2))
31 #define VIH2_BITFIELDS (sizeof(VIDEOINFOHEADER2)+3*sizeof(RGBQUAD))
32 #define BIH_SIZE (sizeof(BITMAPINFOHEADER))
34 VIH vihs[] =
36 // P010
39 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
40 {BIH_SIZE, 0, 0, 1, 24, mmioFOURCC('P','0','1','0'), 0, 0, 0, 0, 0} // bmiHeader
41 },
42 {0, 0, 0}, // mask[3]
43 VIH_NORMAL, // size
44 &MEDIASUBTYPE_P010 // subtype
46 // P016
49 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
50 {BIH_SIZE, 0, 0, 1, 24, mmioFOURCC('P','0','1','6'), 0, 0, 0, 0, 0} // bmiHeader
51 },
52 {0, 0, 0}, // mask[3]
53 VIH_NORMAL, // size
54 &MEDIASUBTYPE_P016 // subtype
56 // NV12
59 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
60 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('N','V','1','2'), 0, 0, 0, 0, 0} // bmiHeader
62 {0, 0, 0}, // mask[3]
63 VIH_NORMAL, // size
64 &MEDIASUBTYPE_NV12 // subtype
66 // NV21
69 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
70 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('N','V','2','1'), 0, 0, 0, 0, 0} // bmiHeader
72 {0, 0, 0}, // mask[3]
73 VIH_NORMAL, // size
74 &MEDIASUBTYPE_NV21 // subtype
76 // YUY2
79 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
80 {BIH_SIZE, 0, 0, 1, 16, mmioFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0} // bmiHeader
81 },
82 {0, 0, 0}, // mask[3]
83 VIH_NORMAL, // size
84 &MEDIASUBTYPE_YUY2 // subtype
86 // YV12
89 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
90 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('Y','V','1','2'), 0, 0, 0, 0, 0} // bmiHeader
91 },
92 {0, 0, 0}, // mask[3]
93 VIH_NORMAL, // size
94 &MEDIASUBTYPE_YV12 // subtype
96 // I420
99 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
100 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','4','2','0'), 0, 0, 0, 0, 0} // bmiHeader
102 {0, 0, 0}, // mask[3]
103 VIH_NORMAL, // size
104 &MEDIASUBTYPE_I420 // subtype
106 // IYUV
109 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
110 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','Y','U','V'), 0, 0, 0, 0, 0} // bmiHeader
112 {0, 0, 0}, // mask[3]
113 VIH_NORMAL, // size
114 &MEDIASUBTYPE_IYUV // subtype
116 // AYUV
119 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
120 {BIH_SIZE, 0, 0, 1, 32, mmioFOURCC('A','Y','U','V'), 0, 0, 0, 0, 0} // bmiHeader
122 {0, 0, 0}, // mask[3]
123 VIH_NORMAL, // size
124 &MEDIASUBTYPE_AYUV // subtype
126 // 8888 normal
129 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
130 {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
132 {0, 0, 0}, // mask[3]
133 VIH_NORMAL, // size
134 &MEDIASUBTYPE_RGB32 // subtype
136 // 8888 bitf
139 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
140 {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
142 {0xFF0000, 0x00FF00, 0x0000FF}, // mask[3]
143 VIH_BITFIELDS, // size
144 &MEDIASUBTYPE_RGB32 // subtype
146 // A888 normal
149 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
150 {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
152 {0, 0, 0}, // mask[3]
153 VIH_NORMAL, // size
154 &MEDIASUBTYPE_ARGB32 // subtype
156 // A888 bitf (I'm not sure if this exist...)
159 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
160 {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
162 {0xFF0000, 0x00FF00, 0x0000FF}, // mask[3]
163 VIH_BITFIELDS, // size
164 &MEDIASUBTYPE_ARGB32 // subtype
166 // 888 normal
169 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
170 {BIH_SIZE, 0, 0, 1, 24, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
172 {0, 0, 0}, // mask[3]
173 VIH_NORMAL, // size
174 &MEDIASUBTYPE_RGB24 // subtype
176 // 888 bitf
179 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
180 {BIH_SIZE, 0, 0, 1, 24, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
182 {0xFF0000, 0x00FF00, 0x0000FF}, // mask[3]
183 VIH_BITFIELDS, // size
184 &MEDIASUBTYPE_RGB24 // subtype
186 // 565 normal
189 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
190 {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
192 {0, 0, 0}, // mask[3]
193 VIH_NORMAL, // size
194 &MEDIASUBTYPE_RGB565 // subtype
196 // 565 bitf
199 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
200 {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
202 {0xF800, 0x07E0, 0x001F}, // mask[3]
203 VIH_BITFIELDS, // size
204 &MEDIASUBTYPE_RGB565 // subtype
206 // 555 normal
209 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
210 {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
212 {0, 0, 0}, // mask[3]
213 VIH_NORMAL, // size
214 &MEDIASUBTYPE_RGB555 // subtype
216 // 555 bitf
219 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0,
220 {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
222 {0x7C00, 0x03E0, 0x001F}, // mask[3]
223 VIH_BITFIELDS, // size
224 &MEDIASUBTYPE_RGB555 // subtype
228 VIH2 vih2s[] =
230 // P010
233 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
234 {BIH_SIZE, 0, 0, 1, 24, mmioFOURCC('P','0','1','0'), 0, 0, 0, 0, 0} // bmiHeader
236 {0, 0, 0}, // mask[3]
237 VIH2_NORMAL, // size
238 &MEDIASUBTYPE_P010 // subtype
240 // P016
243 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 {BIH_SIZE, 0, 0, 1, 24, mmioFOURCC('P','0','1','6'), 0, 0, 0, 0, 0} // bmiHeader
246 {0, 0, 0}, // mask[3]
247 VIH2_NORMAL, // size
248 &MEDIASUBTYPE_P016 // subtype
250 // NV12
253 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
254 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('N','V','1','2'), 0, 0, 0, 0, 0} // bmiHeader
256 {0, 0, 0}, // mask[3]
257 VIH2_NORMAL, // size
258 &MEDIASUBTYPE_NV12 // subtype
260 // NV21
263 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
264 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('N','V','2','1'), 0, 0, 0, 0, 0} // bmiHeader
266 {0, 0, 0}, // mask[3]
267 VIH2_NORMAL, // size
268 &MEDIASUBTYPE_NV21 // subtype
270 // YUY2
273 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
274 {BIH_SIZE, 0, 0, 1, 16, mmioFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0} // bmiHeader
276 {0, 0, 0}, // mask[3]
277 VIH2_NORMAL, // size
278 &MEDIASUBTYPE_YUY2 // subtype
280 // YV12
283 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
284 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('Y','V','1','2'), 0, 0, 0, 0, 0} // bmiHeader
286 {0, 0, 0}, // mask[3]
287 VIH2_NORMAL, // size
288 &MEDIASUBTYPE_YV12 // subtype
290 // I420
293 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
294 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','4','2','0'), 0, 0, 0, 0, 0} // bmiHeader
296 {0, 0, 0}, // mask[3]
297 VIH2_NORMAL, // size
298 &MEDIASUBTYPE_I420 // subtype
300 // IYUV
303 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
304 {BIH_SIZE, 0, 0, 1, 12, mmioFOURCC('I','Y','U','V'), 0, 0, 0, 0, 0} // bmiHeader
306 {0, 0, 0}, // mask[3]
307 VIH2_NORMAL, // size
308 &MEDIASUBTYPE_IYUV // subtype
310 // AYUV
313 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
314 {BIH_SIZE, 0, 0, 1, 32, mmioFOURCC('A','Y','U','V'), 0, 0, 0, 0, 0} // bmiHeader
316 {0, 0, 0}, // mask[3]
317 VIH2_NORMAL, // size
318 &MEDIASUBTYPE_AYUV // subtype
320 // 8888 normal
323 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
324 {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
326 {0, 0, 0}, // mask[3]
327 VIH2_NORMAL, // size
328 &MEDIASUBTYPE_RGB32 // subtype
330 // 8888 bitf
333 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
334 {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
336 {0xFF0000, 0x00FF00, 0x0000FF}, // mask[3]
337 VIH2_BITFIELDS, // size
338 &MEDIASUBTYPE_RGB32 // subtype
340 // A888 normal
343 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
344 {BIH_SIZE, 0, 0, 1, 32, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
346 {0, 0, 0}, // mask[3]
347 VIH2_NORMAL, // size
348 &MEDIASUBTYPE_ARGB32 // subtype
350 // A888 bitf (I'm not sure if this exist...)
353 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
354 {BIH_SIZE, 0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
356 {0xFF0000, 0x00FF00, 0x0000FF}, // mask[3]
357 VIH2_BITFIELDS, // size
358 &MEDIASUBTYPE_ARGB32 // subtype
360 // 888 normal
363 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
364 {BIH_SIZE, 0, 0, 1, 24, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
366 {0, 0, 0}, // mask[3]
367 VIH2_NORMAL, // size
368 &MEDIASUBTYPE_RGB24 // subtype
370 // 888 bitf
373 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
374 {BIH_SIZE, 0, 0, 1, 24, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
376 {0xFF0000, 0x00FF00, 0x0000FF}, // mask[3]
377 VIH2_BITFIELDS, // size
378 &MEDIASUBTYPE_RGB24 // subtype
380 // 565 normal
383 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
384 {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
386 {0, 0, 0}, // mask[3]
387 VIH2_NORMAL, // size
388 &MEDIASUBTYPE_RGB565 // subtype
390 // 565 bitf
393 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
394 {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
396 {0xF800, 0x07E0, 0x001F}, // mask[3]
397 VIH2_BITFIELDS, // size
398 &MEDIASUBTYPE_RGB565 // subtype
400 // 555 normal
403 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
404 {BIH_SIZE, 0, 0, 1, 16, BI_RGB, 0, 0, 0, 0, 0} // bmiHeader
406 {0, 0, 0}, // mask[3]
407 VIH2_NORMAL, // size
408 &MEDIASUBTYPE_RGB555 // subtype
410 // 555 bitf
413 {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0,
414 {BIH_SIZE, 0, 0, 1, 16, BI_BITFIELDS, 0, 0, 0, 0, 0} // bmiHeader
416 {0x7C00, 0x03E0, 0x001F}, // mask[3]
417 VIH2_BITFIELDS, // size
418 &MEDIASUBTYPE_RGB555 // subtype
422 int VIHSIZE = countof(vihs);
424 CString VIH2String(int i)
426 CString ret = CString(GuidNames[*vihs[i].subtype]);
427 if(!ret.Left(13).CompareNoCase(_T("MEDIASUBTYPE_"))) ret = ret.Mid(13);
428 if(vihs[i].vih.bmiHeader.biCompression == 3) ret += _T(" BITF");
429 if(*vihs[i].subtype == MEDIASUBTYPE_I420) ret = _T("I420"); // FIXME
430 else if(*vihs[i].subtype == MEDIASUBTYPE_NV21) ret = _T("NV21"); // FIXME
431 return(ret);
434 CString Subtype2String(const GUID& subtype)
436 CString ret = CString(GuidNames[subtype]);
437 if(!ret.Left(13).CompareNoCase(_T("MEDIASUBTYPE_"))) ret = ret.Mid(13);
438 if(subtype == MEDIASUBTYPE_I420) ret = _T("I420"); // FIXME
439 else if(subtype == MEDIASUBTYPE_NV21) ret = _T("NV21"); // FIXME
440 return(ret);
443 void CorrectMediaType(AM_MEDIA_TYPE* pmt)
445 if(!pmt) return;
447 CMediaType mt(*pmt);
449 if(mt.formattype == FORMAT_VideoInfo)
451 VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)mt.pbFormat;
453 for(int i = 0; i < VIHSIZE; i++)
455 if(mt.subtype == *vihs[i].subtype
456 && vih->bmiHeader.biCompression == vihs[i].vih.bmiHeader.biCompression)
458 mt.AllocFormatBuffer(vihs[i].size);
459 memcpy(mt.pbFormat, &vihs[i], vihs[i].size);
460 memcpy(mt.pbFormat, pmt->pbFormat, sizeof(VIDEOINFOHEADER));
461 break;
465 else if(mt.formattype == FORMAT_VideoInfo2)
467 VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)mt.pbFormat;
469 for(int i = 0; i < VIHSIZE; i++)
471 if(mt.subtype == *vih2s[i].subtype
472 && vih2->bmiHeader.biCompression == vih2s[i].vih.bmiHeader.biCompression)
474 mt.AllocFormatBuffer(vih2s[i].size);
475 memcpy(mt.pbFormat, &vih2s[i], vih2s[i].size);
476 memcpy(mt.pbFormat, pmt->pbFormat, sizeof(VIDEOINFOHEADER2));
477 break;
482 CopyMediaType(pmt, &mt);