1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2015 |
---|
3 | // Created by Roman Ryltsov roman@alax.info, http://alax.info |
---|
4 | // |
---|
5 | // This source code is published to complement DirectShowSpy developer powertoy |
---|
6 | // and demonstrate the internal use of APIs and tricks powering the tool. It is |
---|
7 | // allowed to freely re-use the portions of the code in other projects, commercial |
---|
8 | // or otherwise (provided that you dont pretend that you wrote the original tool). |
---|
9 | // |
---|
10 | // Please keep in mind that DirectShowSpy is a developer tool, it is strongly recommended |
---|
11 | // that it is not shipped with release grade software. It is allowed to distribute |
---|
12 | // DirectShowSpy if only it is not registered with Windows by default and either |
---|
13 | // used privately, or registered on specific throubleshooting request. The advice applies |
---|
14 | // to hooking methods used by DirectShowSpy in general as well. |
---|
15 | |
---|
16 | #include "stdafx.h" |
---|
17 | #include "resource.h" |
---|
18 | #include "FilterGraphHelper.h" |
---|
19 | #include "FilterGraphTable.h" |
---|
20 | #include "MediaSampleTrace.h" |
---|
21 | |
---|
22 | //////////////////////////////////////////////////////////// |
---|
23 | // Test |
---|
24 | |
---|
25 | #if _DEVELOPMENT && FALSE |
---|
26 | |
---|
27 | COMPILER_MESSAGE("Development: CFilterGraphHelper::DoPropertyFrameModal as Test") |
---|
28 | |
---|
29 | #if defined(_WIN64) |
---|
30 | extern "C" __declspec(dllexport) |
---|
31 | #else |
---|
32 | #pragma comment(linker, "/EXPORT:Test=_Test@16,PRIVATE") |
---|
33 | extern "C" // __declspec(dllexport) |
---|
34 | #endif // defined(_WIN64) |
---|
35 | |
---|
36 | HRESULT STDMETHODCALLTYPE Test(HWND hParentWindow, HINSTANCE, LPSTR pszCommandLine, INT nShowCommand) |
---|
37 | { |
---|
38 | hParentWindow; pszCommandLine; nShowCommand; |
---|
39 | _ATLTRY |
---|
40 | { |
---|
41 | CSingleThreadedApartment SingleThreadedApartment; |
---|
42 | CGenericFilterGraph FilterGraph; |
---|
43 | FilterGraph.CoCreateInstance(); |
---|
44 | __C(FilterGraph.m_pFilterGraph->RenderFile(_T("E:\\Media\\Robotica_1080.wmv"), NULL)); |
---|
45 | _ATLTRY |
---|
46 | { |
---|
47 | const CComQIPtr<ISpy> pSpy = FilterGraph.m_pFilterGraph; |
---|
48 | if(pSpy) |
---|
49 | __C(pSpy->put_FriendlyName(CComBSTR(_T("Test")))); |
---|
50 | } |
---|
51 | _ATLCATCHALL() |
---|
52 | { |
---|
53 | _Z_EXCEPTION(); |
---|
54 | } |
---|
55 | CLocalObjectPtr<CFilterGraphHelper> pHelper; |
---|
56 | pHelper->SetFilterGraph(FilterGraph.m_pFilterGraph); |
---|
57 | pHelper->DoPropertyFrameModal(0); |
---|
58 | } |
---|
59 | _ATLCATCH(Exception) |
---|
60 | { |
---|
61 | _C(Exception); |
---|
62 | } |
---|
63 | return S_OK; |
---|
64 | } |
---|
65 | |
---|
66 | #endif // _DEVELOPMENT |
---|
67 | |
---|
68 | #if _DEVELOPMENT && FALSE |
---|
69 | |
---|
70 | COMPILER_MESSAGE("Development: MediaSampleTrace test as Test") |
---|
71 | |
---|
72 | //////////////////////////////////////////////////////////// |
---|
73 | // CRendererFilter |
---|
74 | |
---|
75 | class ATL_NO_VTABLE CRendererFilter : |
---|
76 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
77 | //public CComCoClass<CRendererFilter>, |
---|
78 | public CBaseFilterT<CRendererFilter>, |
---|
79 | public CBasePersistT<CRendererFilter>, |
---|
80 | public CAmFilterMiscFlagsT<CRendererFilter, AM_FILTER_MISC_FLAGS_IS_RENDERER>, |
---|
81 | public CUpstreamMediaPositionAwareRendererFilterT<CRendererFilter> |
---|
82 | { |
---|
83 | public: |
---|
84 | //enum { IDR = }; |
---|
85 | |
---|
86 | DECLARE_NO_REGISTRY() //DECLARE_REGISTRY_RESOURCEID(IDR) |
---|
87 | |
---|
88 | DECLARE_PROTECT_FINAL_CONSTRUCT() |
---|
89 | |
---|
90 | //DECLARE_QI_TRACE(CRendererFilter) |
---|
91 | |
---|
92 | BEGIN_COM_MAP(CRendererFilter) |
---|
93 | COM_INTERFACE_ENTRY(IBaseFilter) |
---|
94 | COM_INTERFACE_ENTRY(IMediaFilter) |
---|
95 | COM_INTERFACE_ENTRY_IID(__uuidof(IPersist), IBaseFilter) |
---|
96 | COM_INTERFACE_ENTRY(IAMFilterMiscFlags) |
---|
97 | COM_INTERFACE_ENTRY_FUNC(__uuidof(IMediaSeeking), 0, QueryUpstreamMediaPositionInterface) |
---|
98 | COM_INTERFACE_ENTRY_FUNC(__uuidof(IDispatch), 0, QueryUpstreamMediaPositionInterface) |
---|
99 | COM_INTERFACE_ENTRY_FUNC(__uuidof(IMediaPosition), 0, QueryUpstreamMediaPositionInterface) |
---|
100 | END_COM_MAP() |
---|
101 | |
---|
102 | public: |
---|
103 | |
---|
104 | //////////////////////////////////////////////////////// |
---|
105 | // CInputPin |
---|
106 | |
---|
107 | class ATL_NO_VTABLE CInputPin : |
---|
108 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
109 | public CInputPinT<CInputPin, CRendererFilter> |
---|
110 | { |
---|
111 | public: |
---|
112 | |
---|
113 | //DECLARE_QI_TRACE(CRendererFilter::CInputPin) |
---|
114 | |
---|
115 | BEGIN_COM_MAP(CInputPin) |
---|
116 | COM_INTERFACE_ENTRY(IPin) |
---|
117 | COM_INTERFACE_ENTRY(IMemInputPin) |
---|
118 | END_COM_MAP() |
---|
119 | |
---|
120 | public: |
---|
121 | // CInputPin |
---|
122 | CInputPin() |
---|
123 | { |
---|
124 | _Z5_THIS(); |
---|
125 | } |
---|
126 | ~CInputPin() |
---|
127 | { |
---|
128 | _Z5_THIS(); |
---|
129 | } |
---|
130 | BOOL CheckMediaType(const CMediaType& pMediaType) const |
---|
131 | { |
---|
132 | _A(pMediaType); |
---|
133 | return TRUE; |
---|
134 | } |
---|
135 | }; |
---|
136 | |
---|
137 | private: |
---|
138 | CObjectPtr<CInputPin> m_pInputPin; |
---|
139 | mutable CRoCriticalSection m_ReceiveCriticalSection; |
---|
140 | CComPtr<IMediaSampleTrace> m_pMediaSampleTrace; |
---|
141 | |
---|
142 | public: |
---|
143 | // CRendererFilter |
---|
144 | CRendererFilter() : |
---|
145 | CBasePersistT<CRendererFilter>(GetDataCriticalSection()) |
---|
146 | { |
---|
147 | _Z4_THIS(); |
---|
148 | } |
---|
149 | ~CRendererFilter() |
---|
150 | { |
---|
151 | _Z4_THIS(); |
---|
152 | } |
---|
153 | HRESULT FinalConstruct() |
---|
154 | { |
---|
155 | _ATLTRY |
---|
156 | { |
---|
157 | m_pInputPin.Construct()->Initialize(this, L"Input"); |
---|
158 | AddPin(m_pInputPin); |
---|
159 | CreateUpstreamMediaPosition(); |
---|
160 | } |
---|
161 | _ATLCATCH(Exception) |
---|
162 | { |
---|
163 | _C(Exception); |
---|
164 | } |
---|
165 | return S_OK; |
---|
166 | } |
---|
167 | VOID FinalRelease() |
---|
168 | { |
---|
169 | DestroyUpstreamMediaPosition(); |
---|
170 | m_pInputPin.Release(); |
---|
171 | } |
---|
172 | VOID DeliverNewSegment(IPin*, REFERENCE_TIME nStartTime, REFERENCE_TIME nStopTime, DOUBLE fRate) |
---|
173 | { |
---|
174 | CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection); |
---|
175 | if(m_pMediaSampleTrace) |
---|
176 | _V(m_pMediaSampleTrace->RegisterNewSegment((IBaseFilter*) this, L"Main", nStartTime, nStopTime, fRate, NULL, 0)); |
---|
177 | } |
---|
178 | VOID DeliverEndOfStream(CInputPin*) |
---|
179 | { |
---|
180 | CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection); |
---|
181 | if(m_pMediaSampleTrace) |
---|
182 | _V(m_pMediaSampleTrace->RegisterEndOfStream((IBaseFilter*) this, L"Main", L"That's All!", 0)); |
---|
183 | NotifyComplete(S_OK); |
---|
184 | } |
---|
185 | VOID CueFilter() |
---|
186 | { |
---|
187 | CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection); |
---|
188 | CRoCriticalSectionLock DataLock(GetDataCriticalSection()); |
---|
189 | if(!m_pInputPin->IsPeerPinAvailable()) |
---|
190 | { |
---|
191 | NotifyComplete(S_FALSE); |
---|
192 | return; |
---|
193 | } |
---|
194 | const CComQIPtr<ISpy> pSpy = GetFilterGraph(); |
---|
195 | _A(pSpy); |
---|
196 | CComPtr<IMediaSampleTrace> pMediaSampleTrace; |
---|
197 | __C(pSpy->CreateMediaSampleTrace(&pMediaSampleTrace)); |
---|
198 | m_pMediaSampleTrace = pMediaSampleTrace; |
---|
199 | } |
---|
200 | VOID StopFilter() |
---|
201 | { |
---|
202 | CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection); |
---|
203 | CRoCriticalSectionLock DataLock(GetDataCriticalSection()); |
---|
204 | m_pMediaSampleTrace.Release(); |
---|
205 | } |
---|
206 | VOID ReceiveMediaSample(CInputPin* pInputPin, IMediaSample2* pMediaSample, HRESULT& nReceiveResult) |
---|
207 | { |
---|
208 | CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection); |
---|
209 | CMediaSampleProperties Properties(pMediaSample); |
---|
210 | CRoCriticalSectionLock DataLock(GetDataCriticalSection()); |
---|
211 | if(m_pMediaSampleTrace) |
---|
212 | _V(m_pMediaSampleTrace->RegisterMediaSample((IBaseFilter*) this, L"Main", (BYTE*) (AM_SAMPLE2_PROPERTIES*) &Properties, NULL, 0)); |
---|
213 | nReceiveResult = S_OK; |
---|
214 | } |
---|
215 | const CObjectPtr<CInputPin>& GetInputPin() const |
---|
216 | { |
---|
217 | return m_pInputPin; |
---|
218 | } |
---|
219 | }; |
---|
220 | |
---|
221 | #if defined(_WIN64) |
---|
222 | extern "C" __declspec(dllexport) |
---|
223 | #else |
---|
224 | #pragma comment(linker, "/EXPORT:Test=_Test@16,PRIVATE") |
---|
225 | extern "C" // __declspec(dllexport) |
---|
226 | #endif // defined(_WIN64) |
---|
227 | |
---|
228 | HRESULT STDMETHODCALLTYPE Test(HWND hParentWindow, HINSTANCE, LPSTR pszCommandLine, INT nShowCommand) |
---|
229 | { |
---|
230 | hParentWindow; pszCommandLine; nShowCommand; |
---|
231 | _ATLTRY |
---|
232 | { |
---|
233 | CSingleThreadedApartment SingleThreadedApartment; |
---|
234 | CGenericFilterGraph FilterGraph; |
---|
235 | FilterGraph.CoCreateInstance(); |
---|
236 | const CComPtr<IBaseFilter> pSourceBaseFilter = FilterGraph.AddSourceFilter( |
---|
237 | _T("E:\\Media\\Robotica_1080.wmv") |
---|
238 | //_T("E:\\Media\\Windows Phone - Design for Developers.mp4") |
---|
239 | ); |
---|
240 | CComPtr<IPin> pOutputPin = _FilterGraphHelper::GetFilterPin(pSourceBaseFilter, PINDIR_OUTPUT); |
---|
241 | if(FALSE) |
---|
242 | { |
---|
243 | class __declspec(uuid("{025BE2E4-1787-4DA4-A585-C5B2B9EEB57C}")) Demultiplexer; |
---|
244 | CComPtr<IBaseFilter> pBaseFilter; |
---|
245 | __C(pBaseFilter.CoCreateInstance(__uuidof(Demultiplexer))); |
---|
246 | __C(FilterGraph.AddFilter(pBaseFilter, _T("Demultiplexer"))); |
---|
247 | __C(FilterGraph.Connect(pOutputPin, _FilterGraphHelper::GetFilterPin(pBaseFilter, PINDIR_INPUT))); |
---|
248 | pOutputPin = _FilterGraphHelper::GetFilterPin(pBaseFilter, PINDIR_OUTPUT); |
---|
249 | } |
---|
250 | CObjectPtr<CRendererFilter> pRendererFilter; |
---|
251 | pRendererFilter.Construct(); |
---|
252 | __C(FilterGraph.AddFilter(pRendererFilter, _T("Renderer"))); |
---|
253 | __C(FilterGraph.Connect(pOutputPin, pRendererFilter->GetInputPin())); |
---|
254 | __C(FilterGraph.m_pMediaFilter->SetSyncSource(NULL)); |
---|
255 | const CComQIPtr<ISpy> pSpy = FilterGraph.m_pFilterGraph; |
---|
256 | _A(pSpy); |
---|
257 | __C(pSpy->put_FriendlyName(CComBSTR(_T("Test")))); |
---|
258 | __C(FilterGraph.m_pMediaControl->Run()); |
---|
259 | __C(FilterGraph.WaitForCompletionDispatchingMessages()); |
---|
260 | CMediaSampleTracePropertySheet PropertySheet; |
---|
261 | PropertySheet.DoModal(GetActiveWindow()); |
---|
262 | } |
---|
263 | _ATLCATCH(Exception) |
---|
264 | { |
---|
265 | _C(Exception); |
---|
266 | } |
---|
267 | return S_OK; |
---|
268 | } |
---|
269 | |
---|
270 | #endif // _DEVELOPMENT |
---|
271 | |
---|
272 | #if _DEVELOPMENT //&& FALSE |
---|
273 | |
---|
274 | COMPILER_MESSAGE("Development: CFilterGraphHelper::DoPropertyFrameModal as Test") |
---|
275 | |
---|
276 | #if defined(_WIN64) |
---|
277 | extern "C" __declspec(dllexport) |
---|
278 | #else |
---|
279 | #pragma comment(linker, "/EXPORT:Test=_Test@16,PRIVATE") |
---|
280 | extern "C" // __declspec(dllexport) |
---|
281 | #endif // defined(_WIN64) |
---|
282 | |
---|
283 | HRESULT STDMETHODCALLTYPE Test(HWND hParentWindow, HINSTANCE, LPSTR pszCommandLine, INT nShowCommand) |
---|
284 | { |
---|
285 | hParentWindow; pszCommandLine; nShowCommand; |
---|
286 | _ATLTRY |
---|
287 | { |
---|
288 | CSingleThreadedApartment SingleThreadedApartment; |
---|
289 | /* |
---|
290 | CGenericFilterGraph FilterGraph; |
---|
291 | FilterGraph.CoCreateInstance(); |
---|
292 | __C(FilterGraph.m_pFilterGraph->RenderFile(_T("E:\\Media\\Robotica_1080.wmv"), NULL)); |
---|
293 | _ATLTRY |
---|
294 | { |
---|
295 | const CComQIPtr<ISpy> pSpy = FilterGraph.m_pFilterGraph; |
---|
296 | if(pSpy) |
---|
297 | __C(pSpy->put_FriendlyName(CComBSTR(_T("Test")))); |
---|
298 | } |
---|
299 | _ATLCATCHALL() |
---|
300 | { |
---|
301 | _Z_EXCEPTION(); |
---|
302 | } |
---|
303 | //CLocalObjectPtr<CFilterGraphTableItem> pFilterGraphTableItem; |
---|
304 | //__C(pFilterGraphTableItem->put_FilterGraph(FilterGraph.m_pFilterGraph)); |
---|
305 | //CLocalObjectPtr<CFilterGraphTable> pFilterGraphTable; |
---|
306 | */ |
---|
307 | CLocalObjectPtr<CFilterGraphHelper> pFilterGraphHelper; |
---|
308 | pFilterGraphHelper->DoFilterGraphListModal(0); |
---|
309 | //__C(pFilterGraphTableItem->put_FilterGraph(NULL)); |
---|
310 | } |
---|
311 | _ATLCATCH(Exception) |
---|
312 | { |
---|
313 | _C(Exception); |
---|
314 | } |
---|
315 | return S_OK; |
---|
316 | } |
---|
317 | |
---|
318 | #endif // _DEVELOPMENT |
---|
319 | |
---|