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)
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
24 #include "..\..\include\moreuuids.h"
25 #include "MediaTypes.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))
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
44 &MEDIASUBTYPE_P010
// subtype
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
54 &MEDIASUBTYPE_P016
// subtype
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
64 &MEDIASUBTYPE_NV12
// subtype
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
74 &MEDIASUBTYPE_NV21
// subtype
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
84 &MEDIASUBTYPE_YUY2
// subtype
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
94 &MEDIASUBTYPE_YV12
// subtype
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]
104 &MEDIASUBTYPE_I420
// subtype
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]
114 &MEDIASUBTYPE_IYUV
// subtype
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]
124 &MEDIASUBTYPE_AYUV
// subtype
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]
134 &MEDIASUBTYPE_RGB32
// subtype
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
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]
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
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]
174 &MEDIASUBTYPE_RGB24
// subtype
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
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]
194 &MEDIASUBTYPE_RGB565
// subtype
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
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]
214 &MEDIASUBTYPE_RGB555
// subtype
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
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]
238 &MEDIASUBTYPE_P010
// subtype
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]
248 &MEDIASUBTYPE_P016
// subtype
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]
258 &MEDIASUBTYPE_NV12
// subtype
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]
268 &MEDIASUBTYPE_NV21
// subtype
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]
278 &MEDIASUBTYPE_YUY2
// subtype
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]
288 &MEDIASUBTYPE_YV12
// subtype
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]
298 &MEDIASUBTYPE_I420
// subtype
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]
308 &MEDIASUBTYPE_IYUV
// subtype
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]
318 &MEDIASUBTYPE_AYUV
// subtype
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]
328 &MEDIASUBTYPE_RGB32
// subtype
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
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]
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
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]
368 &MEDIASUBTYPE_RGB24
// subtype
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
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]
388 &MEDIASUBTYPE_RGB565
// subtype
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
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]
408 &MEDIASUBTYPE_RGB555
// subtype
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
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
443 void CorrectMediaType(AM_MEDIA_TYPE
* 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
));
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
));
482 CopyMediaType(pmt
, &mt
);