1 // The following code enables you to view the contents of a media type while
2 // debugging.
3
4 #include <strsafe.h>
5
6 LPCWSTR GetGUIDNameConst(const GUID& guid);
7 HRESULT GetGUIDName(const GUID& guid, WCHAR **ppwsz);
8
9 HRESULT LogAttributeValueByIndex(IMFAttributes *pAttr, DWORD index);
10 HRESULT SpecialCaseAttributeValue(GUID guid, const PROPVARIANT& var);
11
12 void DBGMSG(PCWSTR format, ...);
13
14 HRESULT LogMediaType(IMFMediaType *pType)
15 {
16 UINT32 count = 0;
17
18 HRESULT hr = pType->GetCount(&count);
19 if (FAILED(hr))
20 {
21 return hr;
22 }
23
24 if (count == 0)
25 {
26 DBGMSG(L"Empty media type.\n");
27 }
28
29 for (UINT32 i = 0; i < count; i++)
30 {
31 hr = LogAttributeValueByIndex(pType, i);
32 if (FAILED(hr))
33 {
34 break;
35 }
36 }
37 return hr;
38 }
39
40 HRESULT LogAttributeValueByIndex(IMFAttributes *pAttr, DWORD index)
41 {
42 WCHAR *pGuidName = NULL;
43 WCHAR *pGuidValName = NULL;
44
45 GUID guid = { 0 };
46
47 PROPVARIANT var;
48 PropVariantInit(&var);
49
50 HRESULT hr = pAttr->GetItemByIndex(index, &guid, &var);
51 if (FAILED(hr))
52 {
53 goto done;
54 }
55
56 hr = GetGUIDName(guid, &pGuidName);
57 if (FAILED(hr))
58 {
59 goto done;
60 }
61
62 DBGMSG(L"\t%s\t", pGuidName);
63
64 hr = SpecialCaseAttributeValue(guid, var);
65 if (FAILED(hr))
66 {
67 goto done;
68 }
69 if (hr == S_FALSE)
70 {
71 switch (var.vt)
72 {
73 case VT_UI4:
74 DBGMSG(L"%d", var.ulVal);
75 break;
76
77 case VT_UI8:
78 DBGMSG(L"%I64d", var.uhVal);
79 break;
80
81 case VT_R8:
82 DBGMSG(L"%f", var.dblVal);
83 break;
84
85 case VT_CLSID:
86 hr = GetGUIDName(*var.puuid, &pGuidValName);
87 if (SUCCEEDED(hr))
88 {
89 DBGMSG(pGuidValName);
90 }
91 break;
92
93 case VT_LPWSTR:
94 DBGMSG(var.pwszVal);
95 break;
96
97 case VT_VECTOR | VT_UI1:
98 DBGMSG(L"<<byte array>>");
99 break;
100
101 case VT_UNKNOWN:
102 DBGMSG(L"IUnknown");
103 break;
104
105 default:
106 DBGMSG(L"Unexpected attribute type (vt = %d)", var.vt);
107 break;
108 }
109 }
110
111 done:
112 DBGMSG(L"\n");
113 CoTaskMemFree(pGuidName);
114 CoTaskMemFree(pGuidValName);
115 PropVariantClear(&var);
116 return hr;
117 }
118
119 HRESULT GetGUIDName(const GUID& guid, WCHAR **ppwsz)
120 {
121 HRESULT hr = S_OK;
122 WCHAR *pName = NULL;
123
124 LPCWSTR pcwsz = GetGUIDNameConst(guid);
125 if (pcwsz)
126 {
127 size_t cchLength = 0;
128
129 hr = StringCchLength(pcwsz, STRSAFE_MAX_CCH, &cchLength);
130 if (FAILED(hr))
131 {
132 goto done;
133 }
134
135 pName = (WCHAR*)CoTaskMemAlloc((cchLength + 1) * sizeof(WCHAR));
136
137 if (pName == NULL)
138 {
139 hr = E_OUTOFMEMORY;
140 goto done;
141 }
142
143 hr = StringCchCopy(pName, cchLength + 1, pcwsz);
144 if (FAILED(hr))
145 {
146 goto done;
147 }
148 }
149 else
150 {
151 hr = StringFromCLSID(guid, &pName);
152 }
153
154 done:
155 if (FAILED(hr))
156 {
157 *ppwsz = NULL;
158 CoTaskMemFree(pName);
159 }
160 else
161 {
162 *ppwsz = pName;
163 }
164 return hr;
165 }
166
167 void LogUINT32AsUINT64(const PROPVARIANT& var)
168 {
169 UINT32 uHigh = 0, uLow = 0;
170 Unpack2UINT32AsUINT64(var.uhVal.QuadPart, &uHigh, &uLow);
171 DBGMSG(L"%d x %d", uHigh, uLow);
172 }
173
174 float OffsetToFloat(const MFOffset& offset)
175 {
176 return offset.value + (static_cast<float>(offset.fract) / 65536.0f);
177 }
178
179 HRESULT LogVideoArea(const PROPVARIANT& var)
180 {
181 if (var.caub.cElems < sizeof(MFVideoArea))
182 {
183 return MF_E_BUFFERTOOSMALL;
184 }
185
186 MFVideoArea *pArea = (MFVideoArea*)var.caub.pElems;
187
188 DBGMSG(L"(%f,%f) (%d,%d)", OffsetToFloat(pArea->OffsetX), OffsetToFloat(pArea->OffsetY),
189 pArea->Area.cx, pArea->Area.cy);
190 return S_OK;
191 }
192
193 // Handle certain known special cases.
194 HRESULT SpecialCaseAttributeValue(GUID guid, const PROPVARIANT& var)
195 {
196 if ((guid == MF_MT_FRAME_RATE) || (guid == MF_MT_FRAME_RATE_RANGE_MAX) ||
197 (guid == MF_MT_FRAME_RATE_RANGE_MIN) || (guid == MF_MT_FRAME_SIZE) ||
198 (guid == MF_MT_PIXEL_ASPECT_RATIO))
199 {
200 // Attributes that contain two packed 32-bit values.
201 LogUINT32AsUINT64(var);
202 }
203 else if ((guid == MF_MT_GEOMETRIC_APERTURE) ||
204 (guid == MF_MT_MINIMUM_DISPLAY_APERTURE) ||
205 (guid == MF_MT_PAN_SCAN_APERTURE))
206 {
207 // Attributes that an MFVideoArea structure.
208 return LogVideoArea(var);
209 }
210 else
211 {
212 return S_FALSE;
213 }
214 return S_OK;
215 }
216
217 void DBGMSG(PCWSTR format, ...)
218 {
219 va_list args;
220 va_start(args, format);
221
222 WCHAR msg[MAX_PATH];
223
224 if (SUCCEEDED(StringCbVPrintf(msg, sizeof(msg), format, args)))
225 {
226 OutputDebugString(msg);
227 }
228 }
229
230 #ifndef IF_EQUAL_RETURN
231 #define IF_EQUAL_RETURN(param, val) if(val == param) return L#val
232 #endif
233
234 LPCWSTR GetGUIDNameConst(const GUID& guid)
235 {
236 IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
237 IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
238 IF_EQUAL_RETURN(guid, MF_MT_SUBTYPE);
239 IF_EQUAL_RETURN(guid, MF_MT_ALL_SAMPLES_INDEPENDENT);
240 IF_EQUAL_RETURN(guid, MF_MT_FIXED_SIZE_SAMPLES);
241 IF_EQUAL_RETURN(guid, MF_MT_COMPRESSED);
242 IF_EQUAL_RETURN(guid, MF_MT_SAMPLE_SIZE);
243 IF_EQUAL_RETURN(guid, MF_MT_WRAPPED_TYPE);
244 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_NUM_CHANNELS);
245 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_SECOND);
246 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_FLOAT_SAMPLES_PER_SECOND);
247 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_AVG_BYTES_PER_SECOND);
248 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BLOCK_ALIGNMENT);
249 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BITS_PER_SAMPLE);
250 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_VALID_BITS_PER_SAMPLE);
251 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_BLOCK);
252 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_CHANNEL_MASK);
253 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_FOLDDOWN_MATRIX);
254 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKREF);
255 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKTARGET);
256 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGREF);
257 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGTARGET);
258 IF_EQUAL_RETURN(guid, MF_MT_AUDIO_PREFER_WAVEFORMATEX);
259 IF_EQUAL_RETURN(guid, MF_MT_AAC_PAYLOAD_TYPE);
260 IF_EQUAL_RETURN(guid, MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION);
261 IF_EQUAL_RETURN(guid, MF_MT_FRAME_SIZE);
262 IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE);
263 IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MAX);
264 IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MIN);
265 IF_EQUAL_RETURN(guid, MF_MT_PIXEL_ASPECT_RATIO);
266 IF_EQUAL_RETURN(guid, MF_MT_DRM_FLAGS);
267 IF_EQUAL_RETURN(guid, MF_MT_PAD_CONTROL_FLAGS);
268 IF_EQUAL_RETURN(guid, MF_MT_SOURCE_CONTENT_HINT);
269 IF_EQUAL_RETURN(guid, MF_MT_VIDEO_CHROMA_SITING);
270 IF_EQUAL_RETURN(guid, MF_MT_INTERLACE_MODE);
271 IF_EQUAL_RETURN(guid, MF_MT_TRANSFER_FUNCTION);
272 IF_EQUAL_RETURN(guid, MF_MT_VIDEO_PRIMARIES);
273 IF_EQUAL_RETURN(guid, MF_MT_CUSTOM_VIDEO_PRIMARIES);
274 IF_EQUAL_RETURN(guid, MF_MT_YUV_MATRIX);
275 IF_EQUAL_RETURN(guid, MF_MT_VIDEO_LIGHTING);
276 IF_EQUAL_RETURN(guid, MF_MT_VIDEO_NOMINAL_RANGE);
277 IF_EQUAL_RETURN(guid, MF_MT_GEOMETRIC_APERTURE);
278 IF_EQUAL_RETURN(guid, MF_MT_MINIMUM_DISPLAY_APERTURE);
279 IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_APERTURE);
280 IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_ENABLED);
281 IF_EQUAL_RETURN(guid, MF_MT_AVG_BITRATE);
282 IF_EQUAL_RETURN(guid, MF_MT_AVG_BIT_ERROR_RATE);
283 IF_EQUAL_RETURN(guid, MF_MT_MAX_KEYFRAME_SPACING);
284 IF_EQUAL_RETURN(guid, MF_MT_DEFAULT_STRIDE);
285 IF_EQUAL_RETURN(guid, MF_MT_PALETTE);
286 IF_EQUAL_RETURN(guid, MF_MT_USER_DATA);
287 IF_EQUAL_RETURN(guid, MF_MT_AM_FORMAT_TYPE);
288 IF_EQUAL_RETURN(guid, MF_MT_MPEG_START_TIME_CODE);
289 IF_EQUAL_RETURN(guid, MF_MT_MPEG2_PROFILE);
290 IF_EQUAL_RETURN(guid, MF_MT_MPEG2_LEVEL);
291 IF_EQUAL_RETURN(guid, MF_MT_MPEG2_FLAGS);
292 IF_EQUAL_RETURN(guid, MF_MT_MPEG_SEQUENCE_HEADER);
293 IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_SRC_PACK_0);
294 IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_CTRL_PACK_0);
295 IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_SRC_PACK_1);
296 IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_CTRL_PACK_1);
297 IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_SRC_PACK);
298 IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_CTRL_PACK);
299 IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_HEADER);
300 IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_FORMAT);
301 IF_EQUAL_RETURN(guid, MF_MT_IMAGE_LOSS_TOLERANT);
302 IF_EQUAL_RETURN(guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION);
303 IF_EQUAL_RETURN(guid, MF_MT_MPEG4_CURRENT_SAMPLE_ENTRY);
304 IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_4CC);
305 IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_WAVE_FORMAT_TAG);
306
307 // Media types
308
309 IF_EQUAL_RETURN(guid, MFMediaType_Audio);
310 IF_EQUAL_RETURN(guid, MFMediaType_Video);
311 IF_EQUAL_RETURN(guid, MFMediaType_Protected);
312 IF_EQUAL_RETURN(guid, MFMediaType_SAMI);
313 IF_EQUAL_RETURN(guid, MFMediaType_Script);
314 IF_EQUAL_RETURN(guid, MFMediaType_Image);
315 IF_EQUAL_RETURN(guid, MFMediaType_HTML);
316 IF_EQUAL_RETURN(guid, MFMediaType_Binary);
317 IF_EQUAL_RETURN(guid, MFMediaType_FileTransfer);
318
319 IF_EQUAL_RETURN(guid, MFVideoFormat_AI44); // FCC('AI44')
320 IF_EQUAL_RETURN(guid, MFVideoFormat_ARGB32); // D3DFMT_A8R8G8B8
321 IF_EQUAL_RETURN(guid, MFVideoFormat_AYUV); // FCC('AYUV')
322 IF_EQUAL_RETURN(guid, MFVideoFormat_DV25); // FCC('dv25')
323 IF_EQUAL_RETURN(guid, MFVideoFormat_DV50); // FCC('dv50')
324 IF_EQUAL_RETURN(guid, MFVideoFormat_DVH1); // FCC('dvh1')
325 IF_EQUAL_RETURN(guid, MFVideoFormat_DVSD); // FCC('dvsd')
326 IF_EQUAL_RETURN(guid, MFVideoFormat_DVSL); // FCC('dvsl')
327 IF_EQUAL_RETURN(guid, MFVideoFormat_H264); // FCC('H264')
328 IF_EQUAL_RETURN(guid, MFVideoFormat_I420); // FCC('I420')
329 IF_EQUAL_RETURN(guid, MFVideoFormat_IYUV); // FCC('IYUV')
330 IF_EQUAL_RETURN(guid, MFVideoFormat_M4S2); // FCC('M4S2')
331 IF_EQUAL_RETURN(guid, MFVideoFormat_MJPG);
332 IF_EQUAL_RETURN(guid, MFVideoFormat_MP43); // FCC('MP43')
333 IF_EQUAL_RETURN(guid, MFVideoFormat_MP4S); // FCC('MP4S')
334 IF_EQUAL_RETURN(guid, MFVideoFormat_MP4V); // FCC('MP4V')
335 IF_EQUAL_RETURN(guid, MFVideoFormat_MPG1); // FCC('MPG1')
336 IF_EQUAL_RETURN(guid, MFVideoFormat_MSS1); // FCC('MSS1')
337 IF_EQUAL_RETURN(guid, MFVideoFormat_MSS2); // FCC('MSS2')
338 IF_EQUAL_RETURN(guid, MFVideoFormat_NV11); // FCC('NV11')
339 IF_EQUAL_RETURN(guid, MFVideoFormat_NV12); // FCC('NV12')
340 IF_EQUAL_RETURN(guid, MFVideoFormat_P010); // FCC('P010')
341 IF_EQUAL_RETURN(guid, MFVideoFormat_P016); // FCC('P016')
342 IF_EQUAL_RETURN(guid, MFVideoFormat_P210); // FCC('P210')
343 IF_EQUAL_RETURN(guid, MFVideoFormat_P216); // FCC('P216')
344 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB24); // D3DFMT_R8G8B8
345 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB32); // D3DFMT_X8R8G8B8
346 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB555); // D3DFMT_X1R5G5B5
347 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB565); // D3DFMT_R5G6B5
348 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB8);
349 IF_EQUAL_RETURN(guid, MFVideoFormat_UYVY); // FCC('UYVY')
350 IF_EQUAL_RETURN(guid, MFVideoFormat_v210); // FCC('v210')
351 IF_EQUAL_RETURN(guid, MFVideoFormat_v410); // FCC('v410')
352 IF_EQUAL_RETURN(guid, MFVideoFormat_WMV1); // FCC('WMV1')
353 IF_EQUAL_RETURN(guid, MFVideoFormat_WMV2); // FCC('WMV2')
354 IF_EQUAL_RETURN(guid, MFVideoFormat_WMV3); // FCC('WMV3')
355 IF_EQUAL_RETURN(guid, MFVideoFormat_WVC1); // FCC('WVC1')
356 IF_EQUAL_RETURN(guid, MFVideoFormat_Y210); // FCC('Y210')
357 IF_EQUAL_RETURN(guid, MFVideoFormat_Y216); // FCC('Y216')
358 IF_EQUAL_RETURN(guid, MFVideoFormat_Y410); // FCC('Y410')
359 IF_EQUAL_RETURN(guid, MFVideoFormat_Y416); // FCC('Y416')
360 IF_EQUAL_RETURN(guid, MFVideoFormat_Y41P);
361 IF_EQUAL_RETURN(guid, MFVideoFormat_Y41T);
362 IF_EQUAL_RETURN(guid, MFVideoFormat_YUY2); // FCC('YUY2')
363 IF_EQUAL_RETURN(guid, MFVideoFormat_YV12); // FCC('YV12')
364 IF_EQUAL_RETURN(guid, MFVideoFormat_YVYU);
365
366 IF_EQUAL_RETURN(guid, MFAudioFormat_PCM); // WAVE_FORMAT_PCM
367 IF_EQUAL_RETURN(guid, MFAudioFormat_Float); // WAVE_FORMAT_IEEE_FLOAT
368 IF_EQUAL_RETURN(guid, MFAudioFormat_DTS); // WAVE_FORMAT_DTS
369 IF_EQUAL_RETURN(guid, MFAudioFormat_Dolby_AC3_SPDIF); // WAVE_FORMAT_DOLBY_AC3_SPDIF
370 IF_EQUAL_RETURN(guid, MFAudioFormat_DRM); // WAVE_FORMAT_DRM
371 IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV8); // WAVE_FORMAT_WMAUDIO2
372 IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV9); // WAVE_FORMAT_WMAUDIO3
373 IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudio_Lossless); // WAVE_FORMAT_WMAUDIO_LOSSLESS
374 IF_EQUAL_RETURN(guid, MFAudioFormat_WMASPDIF); // WAVE_FORMAT_WMASPDIF
375 IF_EQUAL_RETURN(guid, MFAudioFormat_MSP1); // WAVE_FORMAT_WMAVOICE9
376 IF_EQUAL_RETURN(guid, MFAudioFormat_MP3); // WAVE_FORMAT_MPEGLAYER3
377 IF_EQUAL_RETURN(guid, MFAudioFormat_MPEG); // WAVE_FORMAT_MPEG
378 IF_EQUAL_RETURN(guid, MFAudioFormat_AAC); // WAVE_FORMAT_MPEG_HEAAC
379 IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); // WAVE_FORMAT_MPEG_ADTS_AAC
380
381 return NULL;
382 }