1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2013 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | |
---|
5 | #pragma once |
---|
6 | |
---|
7 | #include "rofiles.h" |
---|
8 | #include "rodshow.h" |
---|
9 | #include "DirectShowSpy_i.h" |
---|
10 | #include "Common.h" |
---|
11 | |
---|
12 | //////////////////////////////////////////////////////////// |
---|
13 | // CFilterGraphHelper |
---|
14 | |
---|
15 | class ATL_NO_VTABLE CFilterGraphHelper : |
---|
16 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
17 | public CComCoClass<CFilterGraphHelper, &__uuidof(FilterGraphHelper)>, |
---|
18 | public IProvideClassInfo2Impl<&__uuidof(FilterGraphHelper), &IID_NULL>, |
---|
19 | public IDispatchImpl<IFilterGraphHelper> |
---|
20 | { |
---|
21 | public: |
---|
22 | enum { IDR = IDR_FILTERGRAPHHELPER }; |
---|
23 | |
---|
24 | //DECLARE_REGISTRY_RESOURCEID(IDR) |
---|
25 | |
---|
26 | BEGIN_COM_MAP(CFilterGraphHelper) |
---|
27 | COM_INTERFACE_ENTRY(IFilterGraphHelper) |
---|
28 | COM_INTERFACE_ENTRY(IDispatch) |
---|
29 | COM_INTERFACE_ENTRY(IProvideClassInfo2) |
---|
30 | COM_INTERFACE_ENTRY(IProvideClassInfo) |
---|
31 | END_COM_MAP() |
---|
32 | |
---|
33 | public: |
---|
34 | |
---|
35 | //////////////////////////////////////////////////////// |
---|
36 | // CProcessData |
---|
37 | |
---|
38 | class CProcessData |
---|
39 | { |
---|
40 | public: |
---|
41 | CStringW m_sDisplayName; |
---|
42 | DWORD m_nIdentifier; |
---|
43 | CPath m_sImagePath; |
---|
44 | }; |
---|
45 | |
---|
46 | private: |
---|
47 | mutable CRoCriticalSection m_DataCriticalSection; |
---|
48 | CComPtr<IFilterGraph> m_pFilterGraph; |
---|
49 | |
---|
50 | public: |
---|
51 | // CFilterGraphHelper |
---|
52 | static HRESULT WINAPI UpdateRegistry(BOOL bRegister) throw() |
---|
53 | { |
---|
54 | _Z2(atlTraceRegistrar, 2, _T("bRegister %d\n"), bRegister); |
---|
55 | _ATLTRY |
---|
56 | { |
---|
57 | UpdateRegistryFromResource<CFilterGraphHelper>(bRegister); |
---|
58 | } |
---|
59 | _ATLCATCH(Exception) |
---|
60 | { |
---|
61 | _C(Exception); |
---|
62 | } |
---|
63 | return S_OK; |
---|
64 | } |
---|
65 | CFilterGraphHelper() |
---|
66 | { |
---|
67 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
68 | } |
---|
69 | ~CFilterGraphHelper() |
---|
70 | { |
---|
71 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
72 | } |
---|
73 | static CString FormatIdentifier(LPCSTR pszValue) |
---|
74 | { |
---|
75 | CString sText; |
---|
76 | if(pszValue && *pszValue) |
---|
77 | { |
---|
78 | sText = _T("``"); |
---|
79 | sText.Insert(1, CString(pszValue)); |
---|
80 | } |
---|
81 | return sText; |
---|
82 | } |
---|
83 | static CString FormatIdentifier(LPCWSTR pszValue) |
---|
84 | { |
---|
85 | CString sText; |
---|
86 | if(pszValue && *pszValue) |
---|
87 | { |
---|
88 | sText = _T("``"); |
---|
89 | sText.Insert(1, CString(pszValue)); |
---|
90 | } |
---|
91 | return sText; |
---|
92 | } |
---|
93 | static CString FormatIdentifier(LONG nValue) |
---|
94 | { |
---|
95 | CString sText; |
---|
96 | sText = _T("``"); |
---|
97 | sText.Insert(1, _StringHelper::FormatNumber(nValue)); |
---|
98 | return sText; |
---|
99 | } |
---|
100 | static CString FormatIdentifier(ULONG nValue) |
---|
101 | { |
---|
102 | return FormatIdentifier((LONG) nValue); |
---|
103 | } |
---|
104 | static CString FormatIdentifier(BOOL nValue) |
---|
105 | { |
---|
106 | return FormatIdentifier((LONG) nValue); |
---|
107 | } |
---|
108 | static CString FormatIdentifier(LONGLONG nValue) |
---|
109 | { |
---|
110 | CString sText; |
---|
111 | sText = _T("``"); |
---|
112 | sText.Insert(1, _StringHelper::FormatNumber(nValue)); |
---|
113 | return sText; |
---|
114 | } |
---|
115 | static CString FormatIdentifier(LONG nValue, LPCTSTR pszFormat) |
---|
116 | { |
---|
117 | CString sText; |
---|
118 | sText = _T("``"); |
---|
119 | sText.Insert(1, AtlFormatString(pszFormat, nValue)); |
---|
120 | return sText; |
---|
121 | } |
---|
122 | #define I FormatIdentifier |
---|
123 | static CString FormatPins(_FilterGraphHelper::CPinArray& PinArray) |
---|
124 | { |
---|
125 | CRoArrayT<CString> Array; |
---|
126 | for(SIZE_T nIndex = 0; nIndex < PinArray.GetCount(); nIndex++) |
---|
127 | { |
---|
128 | const CComPtr<IPin>& pPin = PinArray[nIndex]; |
---|
129 | CString sText = I(_FilterGraphHelper::GetPinName(pPin)); |
---|
130 | const CComPtr<IPin> pPeerPin = _FilterGraphHelper::GetPeerPin(pPin); |
---|
131 | if(pPeerPin) |
---|
132 | sText += AtlFormatString(_T(" (%s)"), I(_FilterGraphHelper::GetPinFullName(pPeerPin))); |
---|
133 | Array.Add(sText); |
---|
134 | } |
---|
135 | return _StringHelper::Join(Array, _T(", ")); |
---|
136 | } |
---|
137 | static CString GetText(IFilterGraph* pFilterGraph, const CProcessData* pProcessData = NULL) |
---|
138 | { |
---|
139 | if(!pFilterGraph) |
---|
140 | return (LPCTSTR) NULL; |
---|
141 | CString sText; |
---|
142 | sText += AtlFormatString(_T("# ") _T("Filter Graph") _T("\r\n") _T("\r\n")); |
---|
143 | #pragma region Graph Parameters |
---|
144 | if(pProcessData) |
---|
145 | sText += AtlFormatString(_T("* ") _T("Process: %s (%s) %s") _T("\r\n"), I(pProcessData->m_nIdentifier), I(pProcessData->m_nIdentifier, _T("0x%X")), I(FindFileName(pProcessData->m_sImagePath))); |
---|
146 | #pragma region IMediaControl |
---|
147 | const CComQIPtr<IMediaControl> pMediaControl = pFilterGraph; |
---|
148 | if(pMediaControl) |
---|
149 | _ATLTRY |
---|
150 | { |
---|
151 | OAFilterState State; |
---|
152 | const HRESULT nGetStateResult = pMediaControl->GetState(0, &State); |
---|
153 | _Z45_DSHRESULT(nGetStateResult); |
---|
154 | static const LPCTSTR g_ppszStates[] = { _T("Stopped"), _T("Paused"), _T("Running"), }; |
---|
155 | if(SUCCEEDED(nGetStateResult) && (SIZE_T) State < DIM(g_ppszStates)) |
---|
156 | sText += AtlFormatString(_T("* ") _T("State: %s") _T("\r\n"), I(g_ppszStates[(SIZE_T) State])); |
---|
157 | } |
---|
158 | _ATLCATCHALL() |
---|
159 | { |
---|
160 | _Z_EXCEPTION(); |
---|
161 | } |
---|
162 | #pragma endregion |
---|
163 | #pragma region IMediaPosition |
---|
164 | const CComQIPtr<IMediaPosition> pMediaPosition = pFilterGraph; |
---|
165 | if(pMediaPosition) |
---|
166 | _ATLTRY |
---|
167 | { |
---|
168 | DOUBLE fDuration = 0, fPosition = 0; |
---|
169 | const HRESULT nGetDurationResult = pMediaPosition->get_Duration(&fDuration); |
---|
170 | _Z45_DSHRESULT(nGetDurationResult); |
---|
171 | if(fDuration > 0) |
---|
172 | { |
---|
173 | sText += AtlFormatString(_T("* ") _T("Duration: %s (%s seconds)") _T("\r\n"), I(_FilterGraphHelper::FormatSecondTime(fDuration)), I(_StringHelper::FormatNumber(fDuration, 3))); |
---|
174 | const HRESULT nCurrentPositionResult = pMediaPosition->get_CurrentPosition(&fPosition); |
---|
175 | _Z45_DSHRESULT(nCurrentPositionResult); |
---|
176 | if(SUCCEEDED(nCurrentPositionResult)) |
---|
177 | sText += AtlFormatString(_T("* ") _T("Position: %s (%s seconds)") _T("\r\n"), I(_FilterGraphHelper::FormatSecondTime(fPosition)), I(_StringHelper::FormatNumber(fPosition, 3))); |
---|
178 | } |
---|
179 | } |
---|
180 | _ATLCATCHALL() |
---|
181 | { |
---|
182 | _Z_EXCEPTION(); |
---|
183 | } |
---|
184 | #pragma endregion |
---|
185 | if(pProcessData) |
---|
186 | { |
---|
187 | if(!pProcessData->m_sDisplayName.IsEmpty()) |
---|
188 | sText += AtlFormatString(_T("* ") _T("Display Name: %s") _T("\r\n"), I(pProcessData->m_sDisplayName)); |
---|
189 | const CString sDirectory = (LPCTSTR) GetPathDirectory(pProcessData->m_sImagePath); |
---|
190 | if(!sDirectory.IsEmpty()) |
---|
191 | sText += AtlFormatString(_T("* ") _T("Process Directory: %s") _T("\r\n"), I(sDirectory)); |
---|
192 | } |
---|
193 | sText += _T("\r\n"); |
---|
194 | #pragma endregion |
---|
195 | #pragma region Filter |
---|
196 | _FilterGraphHelper::CFilterArray FilterArray; |
---|
197 | _FilterGraphHelper::GetGraphFilters(pFilterGraph, FilterArray); |
---|
198 | if(!FilterArray.IsEmpty()) |
---|
199 | { |
---|
200 | sText += AtlFormatString(_T("## ") _T("Filters") _T("\r\n") _T("\r\n")); |
---|
201 | for(SIZE_T nIndex = 0; nIndex < FilterArray.GetCount(); nIndex++) |
---|
202 | _ATLTRY |
---|
203 | { |
---|
204 | const CComPtr<IBaseFilter>& pBaseFilter = FilterArray[nIndex]; |
---|
205 | sText += AtlFormatString(_T("%d. ") _T("%ls") _T("\r\n"), nIndex + 1, _FilterGraphHelper::GetFilterName(pBaseFilter)); |
---|
206 | const CStringW sClassIdentifierString = _FilterGraphHelper::GetFilterClassIdentifierString(pBaseFilter); |
---|
207 | if(!sClassIdentifierString.IsEmpty()) |
---|
208 | sText += AtlFormatString(_T(" * ") _T("Class: %s %s") _T("\r\n"), I(sClassIdentifierString), I(_FilterGraphHelper::GetFilterClassDescription(pBaseFilter))); |
---|
209 | _FilterGraphHelper::CPinArray InputPinArray; |
---|
210 | if(_FilterGraphHelper::GetFilterPins(pBaseFilter, PINDIR_INPUT, InputPinArray)) |
---|
211 | sText += AtlFormatString(_T(" * ") _T("Input Pins: %s") _T("\r\n"), FormatPins(InputPinArray)); |
---|
212 | _FilterGraphHelper::CPinArray OutputPinArray; |
---|
213 | if(_FilterGraphHelper::GetFilterPins(pBaseFilter, PINDIR_OUTPUT, OutputPinArray)) |
---|
214 | sText += AtlFormatString(_T(" * ") _T("Output Pins: %s") _T("\r\n"), FormatPins(OutputPinArray)); |
---|
215 | #pragma region IFileSourceFilter |
---|
216 | const CComQIPtr<IFileSourceFilter> pFileSourceFilter = pBaseFilter; |
---|
217 | if(pFileSourceFilter) |
---|
218 | { |
---|
219 | CComHeapPtr<OLECHAR> pszFileName; |
---|
220 | CMediaType pMediaType; |
---|
221 | pMediaType.Allocate(MEDIATYPE_NULL, MEDIASUBTYPE_NULL); |
---|
222 | const HRESULT nGetCurFileResult = pFileSourceFilter->GetCurFile(&pszFileName, pMediaType); |
---|
223 | _Z45_DSHRESULT(nGetCurFileResult); |
---|
224 | if(SUCCEEDED(nGetCurFileResult)) |
---|
225 | sText += AtlFormatString(_T(" * ") _T("File Source: %s") _T("\r\n"), I(pszFileName)); |
---|
226 | } |
---|
227 | #pragma endregion |
---|
228 | #pragma region IFileSinkFilter |
---|
229 | const CComQIPtr<IFileSinkFilter> pFileSinkFilter = pBaseFilter; |
---|
230 | if(pFileSinkFilter) |
---|
231 | { |
---|
232 | CComHeapPtr<OLECHAR> pszFileName; |
---|
233 | CMediaType pMediaType; |
---|
234 | pMediaType.Allocate(MEDIATYPE_NULL, MEDIASUBTYPE_NULL); |
---|
235 | const HRESULT nGetCurFileResult = pFileSinkFilter->GetCurFile(&pszFileName, pMediaType); |
---|
236 | _Z45_DSHRESULT(nGetCurFileResult); |
---|
237 | if(SUCCEEDED(nGetCurFileResult)) |
---|
238 | sText += AtlFormatString(_T(" * ") _T("File Sink: %s") _T("\r\n"), I(pszFileName)); |
---|
239 | } |
---|
240 | #pragma endregion |
---|
241 | } |
---|
242 | _ATLCATCHALL() |
---|
243 | { |
---|
244 | _Z_EXCEPTION(); |
---|
245 | } |
---|
246 | sText += _T("\r\n"); |
---|
247 | #pragma region Connection |
---|
248 | sText += AtlFormatString(_T("## ") _T("Connections") _T("\r\n") _T("\r\n")); |
---|
249 | INT nConnectionIndex = 0; |
---|
250 | for(SIZE_T nFilterIndex = 0; nFilterIndex < FilterArray.GetCount(); nFilterIndex++) |
---|
251 | { |
---|
252 | const CComPtr<IBaseFilter>& pBaseFilter = FilterArray[nFilterIndex]; |
---|
253 | _FilterGraphHelper::CPinArray PinArray; |
---|
254 | _FilterGraphHelper::GetFilterPins(pBaseFilter, PINDIR_OUTPUT, PinArray); |
---|
255 | for(SIZE_T nPinIndex = 0; nPinIndex < PinArray.GetCount(); nPinIndex++) |
---|
256 | { |
---|
257 | const CComPtr<IPin>& pOutputPin = PinArray[nPinIndex]; |
---|
258 | const CComPtr<IPin> pInputPin = _FilterGraphHelper::GetPeerPin(pOutputPin); |
---|
259 | if(!pInputPin) |
---|
260 | continue; |
---|
261 | CString sConnectionText = AtlFormatString(_T("%s - %s"), I(_FilterGraphHelper::GetPinFullName(pOutputPin)), I(_FilterGraphHelper::GetPinFullName(pInputPin))); |
---|
262 | _ATLTRY |
---|
263 | { |
---|
264 | const CMediaType pMediaType = _FilterGraphHelper::GetPinMediaType(pOutputPin); |
---|
265 | if(pMediaType) |
---|
266 | { |
---|
267 | CStringW sMajorType = _FilterGraphHelper::FormatMajorType(pMediaType->majortype); |
---|
268 | CStringW sSubtype; |
---|
269 | if(pMediaType->subtype != MEDIASUBTYPE_NULL) |
---|
270 | sSubtype = _FilterGraphHelper::FormatSubtype(pMediaType->majortype, pMediaType->subtype); |
---|
271 | CRoArrayT<CString> Array; |
---|
272 | Array.Add(I(sMajorType)); |
---|
273 | Array.Add(I(sSubtype)); |
---|
274 | #pragma region MEDIATYPE_Video |
---|
275 | if(pMediaType->majortype == MEDIATYPE_Video) |
---|
276 | { |
---|
277 | const CVideoInfoHeader2 VideoInfoHeader2 = pMediaType.GetCompatibleVideoInfoHeader2(); |
---|
278 | const CSize Extent = VideoInfoHeader2.GetExtent(); |
---|
279 | if(Extent.cx || Extent.cy) |
---|
280 | Array.Add(AtlFormatString(_T("%s x %s"), I(Extent.cx), I(Extent.cy))); |
---|
281 | } else |
---|
282 | #pragma endregion |
---|
283 | #pragma region MEDIATYPE_Audio |
---|
284 | if(pMediaType->majortype == MEDIATYPE_Audio) |
---|
285 | { |
---|
286 | const CWaveFormatEx* pWaveFormatEx = pMediaType.GetWaveFormatEx(); |
---|
287 | if(pWaveFormatEx) |
---|
288 | { |
---|
289 | if(pWaveFormatEx->nSamplesPerSec) |
---|
290 | Array.Add(AtlFormatString(_T("%s Hz"), I(pWaveFormatEx->nSamplesPerSec))); |
---|
291 | if(pWaveFormatEx->nChannels) |
---|
292 | Array.Add(AtlFormatString(_T("%s channels"), I(pWaveFormatEx->nChannels))); |
---|
293 | if(pWaveFormatEx->wBitsPerSample) |
---|
294 | Array.Add(AtlFormatString(_T("%s bits"), I(pWaveFormatEx->wBitsPerSample))); |
---|
295 | } |
---|
296 | } |
---|
297 | #pragma endregion |
---|
298 | sConnectionText += AtlFormatString(_T(" (%s)"), _StringHelper::Join(Array, _T(", "))); |
---|
299 | } |
---|
300 | } |
---|
301 | _ATLCATCHALL() |
---|
302 | { |
---|
303 | _Z_EXCEPTION(); |
---|
304 | } |
---|
305 | sText += AtlFormatString(_T("%d. ") _T("%s") _T("\r\n"), ++nConnectionIndex, sConnectionText); |
---|
306 | } |
---|
307 | } |
---|
308 | sText += _T("\r\n"); |
---|
309 | #pragma endregion |
---|
310 | #pragma region Media Type |
---|
311 | sText += AtlFormatString(_T("## ") _T("Media Types") _T("\r\n") _T("\r\n")); |
---|
312 | INT nGlobalPinIndex = 0; |
---|
313 | CRoListT<CComPtr<IPin>> PinList; |
---|
314 | for(SIZE_T nFilterIndex = 0; nFilterIndex < FilterArray.GetCount(); nFilterIndex++) |
---|
315 | { |
---|
316 | const CComPtr<IBaseFilter>& pBaseFilter = FilterArray[nFilterIndex]; |
---|
317 | _FilterGraphHelper::CPinArray PinArray; |
---|
318 | _FilterGraphHelper::GetFilterPins(pBaseFilter, PinArray); |
---|
319 | for(SIZE_T nPinIndex = 0; nPinIndex < PinArray.GetCount(); nPinIndex++) |
---|
320 | { |
---|
321 | const CComPtr<IPin>& pPin = PinArray[nPinIndex]; |
---|
322 | if(PinList.FindFirst(pPin)) |
---|
323 | continue; |
---|
324 | PinList.AddTail(pPin); |
---|
325 | CString sPinText = AtlFormatString(_T("%s"), I(_FilterGraphHelper::GetPinFullName(pPin))); |
---|
326 | const CComPtr<IPin> pPeerPin = _FilterGraphHelper::GetPeerPin(pPin); |
---|
327 | if(pPeerPin) |
---|
328 | { |
---|
329 | PinList.AddTail(pPeerPin); |
---|
330 | sPinText += AtlFormatString(_T(", %s"), I(_FilterGraphHelper::GetPinFullName(pPeerPin))); |
---|
331 | } |
---|
332 | sText += AtlFormatString(_T("%d. ") _T("%s") _T("\r\n"), ++nGlobalPinIndex, sPinText); |
---|
333 | _ATLTRY |
---|
334 | { |
---|
335 | CMediaType pMediaType; |
---|
336 | if(pPeerPin) |
---|
337 | pMediaType = _FilterGraphHelper::GetPinMediaType(pPin); |
---|
338 | else |
---|
339 | pMediaType = _FilterGraphHelper::EnumerateFirstPinMediaType(pPin); |
---|
340 | if(!pMediaType) |
---|
341 | continue; |
---|
342 | #pragma region AM_MEDIA_TYPE |
---|
343 | #define J(x) I(pMediaType->x) |
---|
344 | #define K1(x) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), J(x)) |
---|
345 | sText += AtlFormatString(_T(" * ") _T("Data: %s") _T("\r\n"), I(AtlFormatData((const BYTE*) (const AM_MEDIA_TYPE*) pMediaType, sizeof *pMediaType).TrimRight())); |
---|
346 | sText += AtlFormatString(_T(" * ") _T("`majortype`: %s") _T("\r\n"), I(_FilterGraphHelper::FormatMajorType(pMediaType->majortype))); |
---|
347 | if(pMediaType->subtype != MEDIASUBTYPE_NULL) |
---|
348 | sText += AtlFormatString(_T(" * ") _T("`subtype`: %s") _T("\r\n"), I(_FilterGraphHelper::FormatSubtype(pMediaType->majortype, pMediaType->subtype))); |
---|
349 | K1(bFixedSizeSamples); |
---|
350 | K1(bTemporalCompression); |
---|
351 | K1(lSampleSize); |
---|
352 | if(pMediaType->formattype != GUID_NULL) |
---|
353 | sText += AtlFormatString(_T(" * ") _T("`formattype`: %s") _T("\r\n"), I(_FilterGraphHelper::FormatFormatType(pMediaType->formattype))); |
---|
354 | if(pMediaType->pUnk) |
---|
355 | sText += AtlFormatString(_T(" * ") _T("`pUnk`: %s") _T("\r\n"), I(AtlFormatString(_T("0x%p"), pMediaType->pUnk))); |
---|
356 | if(pMediaType->cbFormat) |
---|
357 | { |
---|
358 | K1(cbFormat); |
---|
359 | if(pMediaType->pbFormat) |
---|
360 | sText += AtlFormatString(_T(" * ") _T("Format Data, `pbFormat`: %s") _T("\r\n"), I(AtlFormatData(pMediaType->pbFormat, pMediaType->cbFormat).TrimRight())); |
---|
361 | } |
---|
362 | #undef J |
---|
363 | #undef K1 |
---|
364 | #pragma endregion |
---|
365 | const BYTE* pnExtraData = NULL; |
---|
366 | SIZE_T nExtraDataSize = 0; |
---|
367 | #pragma region FORMAT_VideoInfo |
---|
368 | if(pMediaType->formattype == FORMAT_VideoInfo) |
---|
369 | { |
---|
370 | sText += AtlFormatString(_T(" * ") _T("As `VIDEOINFOHEADER`:") _T("\r\n")); |
---|
371 | const VIDEOINFOHEADER* pVideoInfoHeader = (const VIDEOINFOHEADER*) pMediaType->pbFormat; |
---|
372 | #define J(x) I(pVideoInfoHeader->x) |
---|
373 | #define K1(x) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), J(x)) |
---|
374 | sText += AtlFormatString(_T(" * ") _T("`rcSource`: (%s, %s) - (%s, %s)") _T("\r\n"), J(rcSource.left), J(rcSource.top), J(rcSource.right), J(rcSource.bottom)); |
---|
375 | sText += AtlFormatString(_T(" * ") _T("`rcTarget`: (%s, %s) - (%s, %s)") _T("\r\n"), J(rcTarget.left), J(rcTarget.top), J(rcTarget.right), J(rcTarget.bottom)); |
---|
376 | K1(dwBitRate); |
---|
377 | K1(dwBitErrorRate); |
---|
378 | sText += AtlFormatString(_T(" * ") _T("`AvgTimePerFrame`: %s units") _T("\r\n"), I(_FilterGraphHelper::FormatReferenceTime(pVideoInfoHeader->AvgTimePerFrame))); |
---|
379 | K1(bmiHeader.biSize); |
---|
380 | K1(bmiHeader.biWidth); |
---|
381 | K1(bmiHeader.biHeight); |
---|
382 | K1(bmiHeader.biPlanes); |
---|
383 | K1(bmiHeader.biBitCount); |
---|
384 | sText += AtlFormatString(_T(" * ") _T("`bmiHeader.biCompression`: %s") _T("\r\n"), I(_FilterGraphHelper::GetFourccCodeString(pVideoInfoHeader->bmiHeader.biCompression))); |
---|
385 | K1(bmiHeader.biSizeImage); |
---|
386 | K1(bmiHeader.biXPelsPerMeter); |
---|
387 | K1(bmiHeader.biYPelsPerMeter); |
---|
388 | K1(bmiHeader.biClrUsed); |
---|
389 | K1(bmiHeader.biClrImportant); |
---|
390 | #undef J |
---|
391 | #undef K1 |
---|
392 | nExtraDataSize = pMediaType->cbFormat - sizeof *pVideoInfoHeader; |
---|
393 | } else |
---|
394 | #pragma endregion |
---|
395 | #pragma region FORMAT_VideoInfo2 |
---|
396 | if(pMediaType->formattype == FORMAT_VideoInfo2) |
---|
397 | { |
---|
398 | sText += AtlFormatString(_T(" * ") _T("As `VIDEOINFOHEADER2`:") _T("\r\n")); |
---|
399 | const VIDEOINFOHEADER2* pVideoInfoHeader2 = (const VIDEOINFOHEADER2*) pMediaType->pbFormat; |
---|
400 | #define J(x) I(pVideoInfoHeader2->x) |
---|
401 | #define K1(x) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), J(x)) |
---|
402 | #define K2(x, y) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), I(pVideoInfoHeader2->x, y)) |
---|
403 | sText += AtlFormatString(_T(" * ") _T("rcSource: (%s, %s) - (%s, %s)") _T("\r\n"), J(rcSource.left), J(rcSource.top), J(rcSource.right), J(rcSource.bottom)); |
---|
404 | sText += AtlFormatString(_T(" * ") _T("rcTarget: (%s, %s) - (%s, %s)") _T("\r\n"), J(rcTarget.left), J(rcTarget.top), J(rcTarget.right), J(rcTarget.bottom)); |
---|
405 | K1(dwBitRate); |
---|
406 | K1(dwBitErrorRate); |
---|
407 | sText += AtlFormatString(_T(" * ") _T("`AvgTimePerFrame`: %s units") _T("\r\n"), I(_FilterGraphHelper::FormatReferenceTime(pVideoInfoHeader2->AvgTimePerFrame))); |
---|
408 | K2(dwInterlaceFlags, _T("0x%X")); |
---|
409 | K2(dwCopyProtectFlags, _T("0x%X")); |
---|
410 | K1(dwPictAspectRatioX); |
---|
411 | K1(dwPictAspectRatioY); |
---|
412 | K2(dwControlFlags, _T("0x%X")); |
---|
413 | K1(bmiHeader.biSize); |
---|
414 | K1(bmiHeader.biWidth); |
---|
415 | K1(bmiHeader.biHeight); |
---|
416 | K1(bmiHeader.biPlanes); |
---|
417 | K1(bmiHeader.biBitCount); |
---|
418 | sText += AtlFormatString(_T(" * ") _T("`bmiHeader.biCompression`: %s") _T("\r\n"), I(_FilterGraphHelper::GetFourccCodeString(pVideoInfoHeader2->bmiHeader.biCompression))); |
---|
419 | K1(bmiHeader.biSizeImage); |
---|
420 | K1(bmiHeader.biXPelsPerMeter); |
---|
421 | K1(bmiHeader.biYPelsPerMeter); |
---|
422 | K1(bmiHeader.biClrUsed); |
---|
423 | K1(bmiHeader.biClrImportant); |
---|
424 | #undef J |
---|
425 | #undef K1 |
---|
426 | #undef K2 |
---|
427 | nExtraDataSize = pMediaType->cbFormat - sizeof *pVideoInfoHeader2; |
---|
428 | if(nExtraDataSize) |
---|
429 | { |
---|
430 | sText += AtlFormatString(_T(" * ") _T("Extra Data: (%d bytes)") _T("\r\n"), nExtraDataSize); |
---|
431 | nExtraDataSize = 0; |
---|
432 | } |
---|
433 | } else |
---|
434 | #pragma endregion |
---|
435 | #pragma region FORMAT_MPEG2Video |
---|
436 | if(pMediaType->formattype == FORMAT_MPEG2Video) |
---|
437 | { |
---|
438 | sText += AtlFormatString(_T(" * ") _T("As `MPEG2VIDEOINFO`:") _T("\r\n")); |
---|
439 | const MPEG2VIDEOINFO* pMpeg2VideoInfo = (const MPEG2VIDEOINFO*) pMediaType->pbFormat; |
---|
440 | #define J(x) I(pMpeg2VideoInfo->x) |
---|
441 | #define K1(x) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), J(x)) |
---|
442 | #define K2(x, y) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), I(pMpeg2VideoInfo->x, y)) |
---|
443 | sText += AtlFormatString(_T(" * ") _T("`hdr.rcSource`: (%s, %s) - (%s, %s)") _T("\r\n"), J(hdr.rcSource.left), J(hdr.rcSource.top), J(hdr.rcSource.right), J(hdr.rcSource.bottom)); |
---|
444 | sText += AtlFormatString(_T(" * ") _T("`hdr.rcTarget`: (%s, %s) - (%s, %s)") _T("\r\n"), J(hdr.rcTarget.left), J(hdr.rcTarget.top), J(hdr.rcTarget.right), J(hdr.rcTarget.bottom)); |
---|
445 | K1(hdr.dwBitRate); |
---|
446 | K1(hdr.dwBitErrorRate); |
---|
447 | sText += AtlFormatString(_T(" * ") _T("`hdr.AvgTimePerFrame`: %s") _T("\r\n"), I(_FilterGraphHelper::FormatReferenceTime(pMpeg2VideoInfo->hdr.AvgTimePerFrame))); |
---|
448 | K2(hdr.dwInterlaceFlags, _T("0x%X")); |
---|
449 | K2(hdr.dwCopyProtectFlags, _T("0x%X")); |
---|
450 | K1(hdr.dwPictAspectRatioX); |
---|
451 | K1(hdr.dwPictAspectRatioY); |
---|
452 | K2(hdr.dwControlFlags, _T("0x%X")); |
---|
453 | K1(hdr.bmiHeader.biSize); |
---|
454 | K1(hdr.bmiHeader.biWidth); |
---|
455 | K1(hdr.bmiHeader.biHeight); |
---|
456 | K1(hdr.bmiHeader.biPlanes); |
---|
457 | K1(hdr.bmiHeader.biBitCount); |
---|
458 | sText += AtlFormatString(_T(" * ") _T("`hdr.bmiHeader.biCompression`: %s") _T("\r\n"), I(_FilterGraphHelper::GetFourccCodeString(pMpeg2VideoInfo->hdr.bmiHeader.biCompression))); |
---|
459 | K1(hdr.bmiHeader.biSizeImage); |
---|
460 | K1(hdr.bmiHeader.biXPelsPerMeter); |
---|
461 | K1(hdr.bmiHeader.biYPelsPerMeter); |
---|
462 | K1(hdr.bmiHeader.biClrUsed); |
---|
463 | K1(hdr.bmiHeader.biClrImportant); |
---|
464 | K2(dwStartTimeCode, _T("0x%08X")); |
---|
465 | K1(cbSequenceHeader); |
---|
466 | K1(dwProfile); |
---|
467 | K1(dwLevel); |
---|
468 | K2(dwFlags, _T("0x%08X")); |
---|
469 | #undef J |
---|
470 | #undef K1 |
---|
471 | #undef K2 |
---|
472 | #undef J |
---|
473 | nExtraDataSize = pMediaType->cbFormat - (sizeof *pMpeg2VideoInfo - sizeof pMpeg2VideoInfo->dwSequenceHeader); |
---|
474 | } else |
---|
475 | #pragma endregion |
---|
476 | #pragma region FORMAT_WaveFormatEx |
---|
477 | if(pMediaType->formattype == FORMAT_WaveFormatEx) |
---|
478 | { |
---|
479 | const WAVEFORMATEX* pWaveFormatEx = (const WAVEFORMATEX*) pMediaType->pbFormat; |
---|
480 | if(pWaveFormatEx->wFormatTag == WAVE_FORMAT_EXTENSIBLE) |
---|
481 | { |
---|
482 | const WAVEFORMATEXTENSIBLE* pWaveFormatExtensible = (const WAVEFORMATEXTENSIBLE*) pMediaType->pbFormat; |
---|
483 | #define J(x) I(pWaveFormatExtensible->x) |
---|
484 | #define K1(x) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), J(x)) |
---|
485 | #define K2(x, y) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), I(pWaveFormatExtensible->x, y)) |
---|
486 | sText += AtlFormatString(_T(" * ") _T("As `WAVEFORMATEXTENSIBLE`:") _T("\r\n")); |
---|
487 | K2(Format.wFormatTag, _T("0x%02X")); |
---|
488 | K1(Format.nChannels); |
---|
489 | K1(Format.nSamplesPerSec); |
---|
490 | K1(Format.nAvgBytesPerSec); |
---|
491 | K1(Format.nBlockAlign); |
---|
492 | K1(Format.wBitsPerSample); |
---|
493 | K1(Format.cbSize); |
---|
494 | K1(Samples.wValidBitsPerSample); |
---|
495 | K2(dwChannelMask, _T("0x%02X")); |
---|
496 | sText += AtlFormatString(_T(" * ") _T("`SubFormat`: %s") _T("\r\n"), I(_PersistHelper::StringFromIdentifier(pWaveFormatExtensible->SubFormat))); |
---|
497 | #undef J |
---|
498 | #undef K1 |
---|
499 | #undef K2 |
---|
500 | nExtraDataSize = pWaveFormatEx->cbSize - (sizeof *pWaveFormatExtensible - sizeof *pWaveFormatEx); |
---|
501 | } else |
---|
502 | { |
---|
503 | #define J(x) I(pWaveFormatEx->x) |
---|
504 | #define K1(x) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), J(x)) |
---|
505 | #define K2(x, y) sText += AtlFormatString(_T(" * `") _T(#x) _T("`: %s") _T("\r\n"), I(pWaveFormatEx->x, y)) |
---|
506 | K2(wFormatTag, _T("0x%02X")); |
---|
507 | K1(nChannels); |
---|
508 | K1(nSamplesPerSec); |
---|
509 | K1(nAvgBytesPerSec); |
---|
510 | K1(nBlockAlign); |
---|
511 | K1(wBitsPerSample); |
---|
512 | K1(cbSize); |
---|
513 | #undef J |
---|
514 | #undef K1 |
---|
515 | #undef K2 |
---|
516 | nExtraDataSize = pWaveFormatEx->cbSize; |
---|
517 | } |
---|
518 | } |
---|
519 | #pragma endregion |
---|
520 | #pragma region Extra Data |
---|
521 | if(nExtraDataSize) |
---|
522 | { |
---|
523 | if(!pnExtraData) |
---|
524 | pnExtraData = pMediaType->pbFormat + pMediaType->cbFormat - nExtraDataSize; |
---|
525 | sText += AtlFormatString(_T(" * ") _T("Extra Data: %s") _T("\r\n"), I(AtlFormatData(pnExtraData, nExtraDataSize).TrimRight())); |
---|
526 | } |
---|
527 | #pragma endregion |
---|
528 | } |
---|
529 | _ATLCATCHALL() |
---|
530 | { |
---|
531 | _Z_EXCEPTION(); |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | sText += _T("\r\n"); |
---|
536 | #pragma endregion |
---|
537 | } |
---|
538 | #pragma endregion |
---|
539 | return sText; |
---|
540 | } |
---|
541 | #undef I |
---|
542 | |
---|
543 | // IFilterGraphHelper |
---|
544 | STDMETHOD(get_FilterGraph)(IUnknown** ppFilterGraphUnknown) throw() |
---|
545 | { |
---|
546 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
547 | _ATLTRY |
---|
548 | { |
---|
549 | __D(ppFilterGraphUnknown, E_POINTER); |
---|
550 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
551 | *ppFilterGraphUnknown = CComPtr<IUnknown>(m_pFilterGraph).Detach(); |
---|
552 | } |
---|
553 | _ATLCATCH(Exception) |
---|
554 | { |
---|
555 | _C(Exception); |
---|
556 | } |
---|
557 | return S_OK; |
---|
558 | } |
---|
559 | STDMETHOD(put_FilterGraph)(IUnknown* pFilterGraphUnknown) throw() |
---|
560 | { |
---|
561 | _Z4(atlTraceCOM, 4, _T("pFilterGraphUnknown 0x%p\n"), pFilterGraphUnknown); |
---|
562 | _ATLTRY |
---|
563 | { |
---|
564 | const CComQIPtr<IFilterGraph> pFilterGraph = pFilterGraphUnknown; |
---|
565 | __D(!pFilterGraphUnknown || pFilterGraph, E_INVALIDARG); |
---|
566 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
567 | m_pFilterGraph = pFilterGraph; |
---|
568 | } |
---|
569 | _ATLCATCH(Exception) |
---|
570 | { |
---|
571 | _C(Exception); |
---|
572 | } |
---|
573 | return S_OK; |
---|
574 | } |
---|
575 | STDMETHOD(get_Text)(BSTR* psText) throw() |
---|
576 | { |
---|
577 | _Z4(atlTraceCOM, 4, _T("...\n")); |
---|
578 | _ATLTRY |
---|
579 | { |
---|
580 | __D(psText, E_POINTER); |
---|
581 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
582 | *psText = CComBSTR(GetText(m_pFilterGraph)).Detach(); |
---|
583 | } |
---|
584 | _ATLCATCH(Exception) |
---|
585 | { |
---|
586 | _C(Exception); |
---|
587 | } |
---|
588 | return S_OK; |
---|
589 | } |
---|
590 | }; |
---|
591 | |
---|
592 | OBJECT_ENTRY_AUTO(__uuidof(FilterGraphHelper), CFilterGraphHelper) |
---|