source: trunk/DirectShowSpy/Helper.cpp @ 503

Last change on this file since 503 was 503, checked in by roman, 9 years ago

Improved event code logging, added non-ROT FGT (incomplete)

File size: 9.3 KB
Line 
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 don’t 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
27COMPILER_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@0,PRIVATE")
33        extern "C" // __declspec(dllexport)
34#endif // defined(_WIN64)
35
36HRESULT STDMETHODCALLTYPE Test()
37{
38        _ATLTRY
39        {
40                CSingleThreadedApartment SingleThreadedApartment;
41                CGenericFilterGraph FilterGraph;
42                FilterGraph.CoCreateInstance();
43                __C(FilterGraph.m_pFilterGraph->RenderFile(_T("E:\\Media\\Robotica_1080.wmv"), NULL));
44                _ATLTRY
45                {
46                        const CComQIPtr<ISpy> pSpy = FilterGraph.m_pFilterGraph;
47                        if(pSpy)
48                                __C(pSpy->put_FriendlyName(CComBSTR(_T("Test"))));
49                }
50                _ATLCATCHALL()
51                {
52                        _Z_EXCEPTION();
53                }
54                CLocalObjectPtr<CFilterGraphHelper> pHelper;
55                pHelper->SetFilterGraph(FilterGraph.m_pFilterGraph);
56                pHelper->DoPropertyFrameModal(0);
57        }
58        _ATLCATCH(Exception)
59        {
60                _C(Exception);
61        }
62        return S_OK;
63}
64
65#endif // _DEVELOPMENT
66
67#if _DEVELOPMENT && FALSE
68
69COMPILER_MESSAGE("Development: MediaSampleTrace test as Test")
70
71////////////////////////////////////////////////////////////
72// CRendererFilter
73
74class ATL_NO_VTABLE CRendererFilter :
75        public CComObjectRootEx<CComMultiThreadModelNoCS>,
76        //public CComCoClass<CRendererFilter>,
77        public CBaseFilterT<CRendererFilter>,
78        public CBasePersistT<CRendererFilter>,
79        public CAmFilterMiscFlagsT<CRendererFilter, AM_FILTER_MISC_FLAGS_IS_RENDERER>,
80        public CUpstreamMediaPositionAwareRendererFilterT<CRendererFilter>
81{
82public:
83        //enum { IDR = };
84
85DECLARE_NO_REGISTRY() //DECLARE_REGISTRY_RESOURCEID(IDR)
86
87DECLARE_PROTECT_FINAL_CONSTRUCT()
88
89//DECLARE_QI_TRACE(CRendererFilter)
90
91BEGIN_COM_MAP(CRendererFilter)
92        COM_INTERFACE_ENTRY(IBaseFilter)
93        COM_INTERFACE_ENTRY(IMediaFilter)
94        COM_INTERFACE_ENTRY_IID(__uuidof(IPersist), IBaseFilter)
95        COM_INTERFACE_ENTRY(IAMFilterMiscFlags)
96        COM_INTERFACE_ENTRY_FUNC(__uuidof(IMediaSeeking), 0, QueryUpstreamMediaPositionInterface)
97        COM_INTERFACE_ENTRY_FUNC(__uuidof(IDispatch), 0, QueryUpstreamMediaPositionInterface)
98        COM_INTERFACE_ENTRY_FUNC(__uuidof(IMediaPosition), 0, QueryUpstreamMediaPositionInterface)
99END_COM_MAP()
100
101public:
102
103        ////////////////////////////////////////////////////////
104        // CInputPin
105
106        class ATL_NO_VTABLE CInputPin :
107                public CComObjectRootEx<CComMultiThreadModelNoCS>,
108                public CInputPinT<CInputPin, CRendererFilter>
109        {
110        public:
111
112        //DECLARE_QI_TRACE(CRendererFilter::CInputPin)
113
114        BEGIN_COM_MAP(CInputPin)
115                COM_INTERFACE_ENTRY(IPin)
116                COM_INTERFACE_ENTRY(IMemInputPin)
117        END_COM_MAP()
118
119        public:
120        // CInputPin
121                CInputPin()
122                {
123                        _Z5_THIS();
124                }
125                ~CInputPin()
126                {
127                        _Z5_THIS();
128                }
129                BOOL CheckMediaType(const CMediaType& pMediaType) const
130                {
131                        _A(pMediaType);
132                        return TRUE;
133                }
134        };
135
136private:
137        CObjectPtr<CInputPin> m_pInputPin;
138        mutable CRoCriticalSection m_ReceiveCriticalSection;
139        CComPtr<IMediaSampleTrace> m_pMediaSampleTrace;
140
141public:
142// CRendererFilter
143        CRendererFilter() :
144                CBasePersistT<CRendererFilter>(GetDataCriticalSection())
145        {
146                _Z4_THIS();
147        }
148        ~CRendererFilter()
149        {
150                _Z4_THIS();
151        }
152        HRESULT FinalConstruct()
153        {
154                _ATLTRY
155                {
156                        m_pInputPin.Construct()->Initialize(this, L"Input");
157                        AddPin(m_pInputPin);
158                        CreateUpstreamMediaPosition();
159                }
160                _ATLCATCH(Exception)
161                {
162                        _C(Exception);
163                }
164                return S_OK;
165        }
166        VOID FinalRelease()
167        {
168                DestroyUpstreamMediaPosition();
169                m_pInputPin.Release();
170        }
171        VOID DeliverNewSegment(IPin*, REFERENCE_TIME nStartTime, REFERENCE_TIME nStopTime, DOUBLE fRate)
172        {
173                CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection);
174                if(m_pMediaSampleTrace)
175                        _V(m_pMediaSampleTrace->RegisterNewSegment((IBaseFilter*) this, L"Main", nStartTime, nStopTime, fRate, NULL, 0));
176        }
177        VOID DeliverEndOfStream(CInputPin*)
178        {
179                CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection);
180                if(m_pMediaSampleTrace)
181                        _V(m_pMediaSampleTrace->RegisterEndOfStream((IBaseFilter*) this, L"Main", L"That's All!", 0));
182                NotifyComplete(S_OK);
183        }
184        VOID CueFilter()
185        {
186                CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection);
187                CRoCriticalSectionLock DataLock(GetDataCriticalSection());
188                if(!m_pInputPin->IsPeerPinAvailable())
189                {
190                        NotifyComplete(S_FALSE);
191                        return;
192                }
193                const CComQIPtr<ISpy> pSpy = GetFilterGraph();
194                _A(pSpy);
195                CComPtr<IMediaSampleTrace> pMediaSampleTrace;
196                __C(pSpy->CreateMediaSampleTrace(&pMediaSampleTrace));
197                m_pMediaSampleTrace = pMediaSampleTrace;
198        }
199        VOID StopFilter()
200        {
201                CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection);
202                CRoCriticalSectionLock DataLock(GetDataCriticalSection());
203                m_pMediaSampleTrace.Release();
204        }
205        VOID ReceiveMediaSample(CInputPin* pInputPin, IMediaSample2* pMediaSample, HRESULT& nReceiveResult)
206        {
207                CRoCriticalSectionLock ReceiveLock(m_ReceiveCriticalSection);
208                CMediaSampleProperties Properties(pMediaSample);
209                CRoCriticalSectionLock DataLock(GetDataCriticalSection());
210                if(m_pMediaSampleTrace)
211                        _V(m_pMediaSampleTrace->RegisterMediaSample((IBaseFilter*) this, L"Main", (BYTE*) (AM_SAMPLE2_PROPERTIES*) &Properties, NULL, 0));
212                nReceiveResult = S_OK;
213        }
214        const CObjectPtr<CInputPin>& GetInputPin() const
215        {
216                return m_pInputPin;
217        }
218};
219
220#if defined(_WIN64)
221        extern "C" __declspec(dllexport) 
222#else
223        #pragma comment(linker, "/EXPORT:Test=_Test@0,PRIVATE")
224        extern "C" // __declspec(dllexport)
225#endif // defined(_WIN64)
226
227HRESULT STDMETHODCALLTYPE Test()
228{
229        _ATLTRY
230        {
231                CSingleThreadedApartment SingleThreadedApartment;
232                CGenericFilterGraph FilterGraph;
233                FilterGraph.CoCreateInstance();
234                const CComPtr<IBaseFilter> pSourceBaseFilter = FilterGraph.AddSourceFilter(
235                        _T("E:\\Media\\Robotica_1080.wmv")
236                        //_T("E:\\Media\\Windows Phone - Design for Developers.mp4")
237                        );
238                CComPtr<IPin> pOutputPin = _FilterGraphHelper::GetFilterPin(pSourceBaseFilter, PINDIR_OUTPUT);
239                if(FALSE)
240                {
241                        class __declspec(uuid("{025BE2E4-1787-4DA4-A585-C5B2B9EEB57C}")) Demultiplexer;
242                        CComPtr<IBaseFilter> pBaseFilter;
243                        __C(pBaseFilter.CoCreateInstance(__uuidof(Demultiplexer)));
244                        __C(FilterGraph.AddFilter(pBaseFilter, _T("Demultiplexer")));
245                        __C(FilterGraph.Connect(pOutputPin, _FilterGraphHelper::GetFilterPin(pBaseFilter, PINDIR_INPUT)));
246                        pOutputPin = _FilterGraphHelper::GetFilterPin(pBaseFilter, PINDIR_OUTPUT);
247                }
248                CObjectPtr<CRendererFilter> pRendererFilter;
249                pRendererFilter.Construct();
250                __C(FilterGraph.AddFilter(pRendererFilter, _T("Renderer")));
251                __C(FilterGraph.Connect(pOutputPin, pRendererFilter->GetInputPin()));
252                __C(FilterGraph.m_pMediaFilter->SetSyncSource(NULL));
253                const CComQIPtr<ISpy> pSpy = FilterGraph.m_pFilterGraph;
254                _A(pSpy);
255                __C(pSpy->put_FriendlyName(CComBSTR(_T("Test"))));
256                __C(FilterGraph.m_pMediaControl->Run());
257                __C(FilterGraph.WaitForCompletionDispatchingMessages());
258                CMediaSampleTracePropertySheet PropertySheet;
259                PropertySheet.DoModal(GetActiveWindow());
260        }
261        _ATLCATCH(Exception)
262        {
263                _C(Exception);
264        }
265        return S_OK;
266}
267
268#endif // _DEVELOPMENT
269
270#if _DEVELOPMENT //&& FALSE
271
272COMPILER_MESSAGE("Development: CFilterGraphHelper::DoPropertyFrameModal as Test")
273
274#if defined(_WIN64)
275        extern "C" __declspec(dllexport) 
276#else
277        #pragma comment(linker, "/EXPORT:Test=_Test@0,PRIVATE")
278        extern "C" // __declspec(dllexport)
279#endif // defined(_WIN64)
280
281HRESULT STDMETHODCALLTYPE Test()
282{
283        _ATLTRY
284        {
285                CSingleThreadedApartment SingleThreadedApartment;
286/*
287                CGenericFilterGraph FilterGraph;
288                FilterGraph.CoCreateInstance();
289                __C(FilterGraph.m_pFilterGraph->RenderFile(_T("E:\\Media\\Robotica_1080.wmv"), NULL));
290                _ATLTRY
291                {
292                        const CComQIPtr<ISpy> pSpy = FilterGraph.m_pFilterGraph;
293                        if(pSpy)
294                                __C(pSpy->put_FriendlyName(CComBSTR(_T("Test"))));
295                }
296                _ATLCATCHALL()
297                {
298                        _Z_EXCEPTION();
299                }
300                //CLocalObjectPtr<CFilterGraphTableItem> pFilterGraphTableItem;
301                //__C(pFilterGraphTableItem->put_FilterGraph(FilterGraph.m_pFilterGraph));
302                //CLocalObjectPtr<CFilterGraphTable> pFilterGraphTable;
303*/
304                CLocalObjectPtr<CFilterGraphHelper> pFilterGraphHelper;
305                pFilterGraphHelper->DoFilterGraphListModal(0);
306                //__C(pFilterGraphTableItem->put_FilterGraph(NULL));
307        }
308        _ATLCATCH(Exception)
309        {
310                _C(Exception);
311        }
312        return S_OK;
313}
314
315#endif // _DEVELOPMENT
316
Note: See TracBrowser for help on using the repository browser.