forked from obsproject/libdshowcapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdshow-formats.cpp
335 lines (290 loc) · 7.66 KB
/
dshow-formats.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* Copyright (C) 2014 Hugh Bailey <obs.jim@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include "dshow-formats.hpp"
#include "dshow-media-type.hpp"
#ifndef __MINGW32__
const GUID MEDIASUBTYPE_RAW_AAC1 = {0x000000FF,
0x0000,
0x0010,
{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b,
0x71}};
const GUID MEDIASUBTYPE_I420 = {0x30323449,
0x0000,
0x0010,
{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b,
0x71}};
const GUID MEDIASUBTYPE_DVM = {0x00002000,
0x0000,
0x0010,
{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b,
0x71}};
#endif
const GUID MEDIASUBTYPE_Y800 = {0x30303859,
0x0000,
0x0010,
{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b,
0x71}};
#ifdef ENABLE_HEVC
const GUID MEDIASUBTYPE_HEVC = {0x43564548,
0x0000,
0x0010,
{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b,
0x71}};
#endif
namespace DShow {
DWORD VFormatToFourCC(VideoFormat format)
{
switch (format) {
/* raw formats */
case VideoFormat::ARGB:
return MAKEFOURCC('A', 'R', 'G', 'B');
case VideoFormat::XRGB:
return MAKEFOURCC('R', 'G', 'B', '4');
/* planar YUV formats */
case VideoFormat::I420:
return MAKEFOURCC('I', '4', '2', '0');
case VideoFormat::NV12:
return MAKEFOURCC('N', 'V', '1', '2');
case VideoFormat::YV12:
return MAKEFOURCC('Y', 'V', '1', '2');
case VideoFormat::Y800:
return MAKEFOURCC('Y', '8', '0', '0');
case VideoFormat::P010:
return MAKEFOURCC('P', '0', '1', '0');
/* packed YUV formats */
case VideoFormat::YVYU:
return MAKEFOURCC('Y', 'V', 'Y', 'U');
case VideoFormat::YUY2:
return MAKEFOURCC('Y', 'U', 'Y', '2');
case VideoFormat::UYVY:
return MAKEFOURCC('U', 'Y', 'V', 'Y');
case VideoFormat::HDYC:
return MAKEFOURCC('H', 'D', 'Y', 'C');
/* encoded formats */
case VideoFormat::MJPEG:
return MAKEFOURCC('M', 'J', 'P', 'G');
case VideoFormat::H264:
return MAKEFOURCC('H', '2', '6', '4');
#ifdef ENABLE_HEVC
case VideoFormat::HEVC:
return MAKEFOURCC('H', 'E', 'V', 'C');
#endif
default:
return 0;
}
}
GUID VFormatToSubType(VideoFormat format)
{
switch (format) {
/* raw formats */
case VideoFormat::ARGB:
return MEDIASUBTYPE_ARGB32;
case VideoFormat::XRGB:
return MEDIASUBTYPE_RGB32;
/* planar YUV formats */
case VideoFormat::I420:
return MEDIASUBTYPE_I420;
case VideoFormat::NV12:
return MEDIASUBTYPE_NV12;
case VideoFormat::YV12:
return MEDIASUBTYPE_YV12;
case VideoFormat::Y800:
return MEDIASUBTYPE_Y800;
case VideoFormat::P010:
return MEDIASUBTYPE_P010;
/* packed YUV formats */
case VideoFormat::YVYU:
return MEDIASUBTYPE_YVYU;
case VideoFormat::YUY2:
return MEDIASUBTYPE_YUY2;
case VideoFormat::UYVY:
return MEDIASUBTYPE_UYVY;
/* encoded formats */
case VideoFormat::MJPEG:
return MEDIASUBTYPE_MJPG;
case VideoFormat::H264:
return MEDIASUBTYPE_H264;
#ifdef ENABLE_HEVC
case VideoFormat::HEVC:
return MEDIASUBTYPE_HEVC;
#endif
default:
return GUID();
}
}
WORD VFormatBits(VideoFormat format)
{
switch (format) {
/* raw formats */
case VideoFormat::ARGB:
case VideoFormat::XRGB:
return 32;
/* planar YUV formats */
case VideoFormat::I420:
case VideoFormat::NV12:
case VideoFormat::YV12:
return 12;
case VideoFormat::Y800:
return 8;
/* packed YUV formats */
case VideoFormat::YVYU:
case VideoFormat::YUY2:
case VideoFormat::UYVY:
return 16;
default:
return 0;
}
}
WORD VFormatPlanes(VideoFormat format)
{
switch (format) {
/* raw formats */
case VideoFormat::ARGB:
case VideoFormat::XRGB:
return 1;
/* planar YUV formats */
case VideoFormat::I420:
return 3;
case VideoFormat::NV12:
case VideoFormat::YV12:
return 2;
case VideoFormat::Y800:
return 1;
/* packed YUV formats */
case VideoFormat::YVYU:
case VideoFormat::YUY2:
case VideoFormat::UYVY:
return 1;
default:
return 0;
}
}
static bool GetFourCCVFormat(DWORD fourCC, VideoFormat &format)
{
switch (fourCC) {
/* raw formats */
case MAKEFOURCC('R', 'G', 'B', '2'):
format = VideoFormat::XRGB;
break;
case MAKEFOURCC('R', 'G', 'B', '4'):
format = VideoFormat::XRGB;
break;
case MAKEFOURCC('A', 'R', 'G', 'B'):
format = VideoFormat::ARGB;
break;
/* planar YUV formats */
case MAKEFOURCC('I', '4', '2', '0'):
case MAKEFOURCC('I', 'Y', 'U', 'V'):
format = VideoFormat::I420;
break;
case MAKEFOURCC('Y', 'V', '1', '2'):
format = VideoFormat::YV12;
break;
case MAKEFOURCC('N', 'V', '1', '2'):
format = VideoFormat::NV12;
break;
case MAKEFOURCC('Y', '8', '0', '0'):
format = VideoFormat::Y800;
break;
case MAKEFOURCC('P', '0', '1', '0'):
format = VideoFormat::P010;
break;
/* packed YUV formats */
case MAKEFOURCC('Y', 'V', 'Y', 'U'):
format = VideoFormat::YVYU;
break;
case MAKEFOURCC('Y', 'U', 'Y', '2'):
format = VideoFormat::YUY2;
break;
case MAKEFOURCC('U', 'Y', 'V', 'Y'):
format = VideoFormat::UYVY;
break;
case MAKEFOURCC('H', 'D', 'Y', 'C'):
format = VideoFormat::HDYC;
break;
/* compressed formats */
case MAKEFOURCC('H', '2', '6', '4'):
format = VideoFormat::H264;
break;
#ifdef ENABLE_HEVC
case MAKEFOURCC('H', 'E', 'V', 'C'):
format = VideoFormat::HEVC;
break;
#endif
/* compressed formats that can automatically create intermediary
* filters for decompression */
case MAKEFOURCC('M', 'J', 'P', 'G'):
format = VideoFormat::MJPEG;
break;
default:
return false;
}
return true;
}
bool GetMediaTypeVFormat(const AM_MEDIA_TYPE &mt, VideoFormat &format)
{
if (mt.majortype != MEDIATYPE_Video)
return false;
const BITMAPINFOHEADER *bmih = GetBitmapInfoHeader(mt);
format = VideoFormat::Unknown;
/* raw formats */
if (mt.subtype == MEDIASUBTYPE_RGB24)
format = VideoFormat::XRGB;
else if (mt.subtype == MEDIASUBTYPE_RGB32)
format = VideoFormat::XRGB;
else if (mt.subtype == MEDIASUBTYPE_ARGB32)
format = VideoFormat::ARGB;
/* planar YUV formats */
else if (mt.subtype == MEDIASUBTYPE_I420)
format = VideoFormat::I420;
else if (mt.subtype == MEDIASUBTYPE_IYUV)
format = VideoFormat::I420;
else if (mt.subtype == MEDIASUBTYPE_YV12)
format = VideoFormat::YV12;
else if (mt.subtype == MEDIASUBTYPE_NV12)
format = VideoFormat::NV12;
else if (mt.subtype == MEDIASUBTYPE_Y800)
format = VideoFormat::Y800;
else if (mt.subtype == MEDIASUBTYPE_P010)
format = VideoFormat::P010;
/* packed YUV formats */
else if (mt.subtype == MEDIASUBTYPE_YVYU)
format = VideoFormat::YVYU;
else if (mt.subtype == MEDIASUBTYPE_YUY2)
format = VideoFormat::YUY2;
else if (mt.subtype == MEDIASUBTYPE_UYVY)
format = VideoFormat::UYVY;
/* compressed formats */
else if (mt.subtype == MEDIASUBTYPE_H264)
format = VideoFormat::H264;
#ifdef ENABLE_HEVC
else if (mt.subtype == MEDIASUBTYPE_HEVC)
format = VideoFormat::HEVC;
#endif
/* compressed formats that can automatically create intermediary
* filters for decompression */
else if (mt.subtype == MEDIASUBTYPE_MJPG)
format = VideoFormat::MJPEG;
/* no valid types, check fourcc value instead */
else
return bmih ? GetFourCCVFormat(bmih->biCompression, format)
: false;
return true;
}
}; /* namespace DShow */