1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2013 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | |
---|
5 | #pragma once |
---|
6 | |
---|
7 | #include "AboutDialog.h" |
---|
8 | #include <dshow.h> |
---|
9 | #include <d3d9.h> |
---|
10 | #include <vmr9.h> |
---|
11 | #include "rodshow.h" |
---|
12 | |
---|
13 | //////////////////////////////////////////////////////////// |
---|
14 | // CVmr7Window |
---|
15 | |
---|
16 | class CVmr7Window : |
---|
17 | public CControlWindowT<CVmr7Window> |
---|
18 | { |
---|
19 | public: |
---|
20 | |
---|
21 | BEGIN_MSG_MAP_EX(CVmr7Window) |
---|
22 | //CHAIN_MSG_MAP(CControlWindowT<CVmr7Window>) |
---|
23 | MSG_WM_ERASEBKGND(OnEraseBkgnd) |
---|
24 | MSG_WM_PAINT(OnPaint) |
---|
25 | MSG_WM_DISPLAYCHANGE(OnDisplayChange) |
---|
26 | MSG_WM_SIZE(OnSize) |
---|
27 | MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) |
---|
28 | END_MSG_MAP() |
---|
29 | |
---|
30 | public: |
---|
31 | CComPtr<IBaseFilter> m_pBaseFilter; |
---|
32 | CComPtr<IVMRWindowlessControl> m_pVmrWindowlessControl; |
---|
33 | |
---|
34 | public: |
---|
35 | // CVmr7Window |
---|
36 | static CLSID GetRendererClassIdentifier() throw() |
---|
37 | { |
---|
38 | return CLSID_VideoMixingRenderer; |
---|
39 | } |
---|
40 | static CComPtr<IBaseFilter> CoCreateBaseFilterInstance() |
---|
41 | { |
---|
42 | CComPtr<IBaseFilter> pBaseFilter; |
---|
43 | __C(pBaseFilter.CoCreateInstance(GetRendererClassIdentifier())); |
---|
44 | return pBaseFilter; |
---|
45 | } |
---|
46 | VOID Initialize(IBaseFilter* pBaseFilter) |
---|
47 | { |
---|
48 | _A(pBaseFilter); |
---|
49 | _A(!m_pBaseFilter && !m_pVmrWindowlessControl); |
---|
50 | m_pBaseFilter = pBaseFilter; |
---|
51 | CComQIPtr<IVMRFilterConfig> pVmrFilterConfig = pBaseFilter; |
---|
52 | __D(pVmrFilterConfig, E_NOINTERFACE); |
---|
53 | __C(pVmrFilterConfig->SetRenderingMode(VMRMode_Windowless)); |
---|
54 | // NOTE: Cause the VMR to load the mixer and compositor |
---|
55 | // See http://msdn.microsoft.com/en-us/library/windows/desktop/dd390448%28v=vs.85%29.aspx |
---|
56 | __C(pVmrFilterConfig->SetNumberOfStreams(1)); |
---|
57 | m_pVmrWindowlessControl = CComQIPtr<IVMRWindowlessControl>(m_pBaseFilter); |
---|
58 | __D(m_pVmrWindowlessControl, E_NOINTERFACE); |
---|
59 | __C(m_pVmrWindowlessControl->SetVideoClippingWindow(m_hWnd)); |
---|
60 | CRect VideoPosition = GetVideoPosition(); |
---|
61 | _Z4(atlTraceGeneral, 4, _T(".m_pVmrWindowlessControl 0x%p, VideoPosition at (%d, %d) size (%d, %d)\n"), m_pVmrWindowlessControl, VideoPosition.left, VideoPosition.top, VideoPosition.Width(), VideoPosition.Height()); |
---|
62 | __C(m_pVmrWindowlessControl->SetVideoPosition(NULL, VideoPosition)); |
---|
63 | } |
---|
64 | VOID Terminate() throw() |
---|
65 | { |
---|
66 | m_pBaseFilter = NULL; |
---|
67 | m_pVmrWindowlessControl = NULL; |
---|
68 | } |
---|
69 | CRect GetVideoPosition() const throw() |
---|
70 | { |
---|
71 | CRect Position; |
---|
72 | _W(GetClientRect(Position)); |
---|
73 | return Position; |
---|
74 | } |
---|
75 | |
---|
76 | // Window Message Handlers |
---|
77 | LRESULT OnEraseBkgnd(CDCHandle Dc) |
---|
78 | { |
---|
79 | Dc; |
---|
80 | if(m_pVmrWindowlessControl) |
---|
81 | { |
---|
82 | return TRUE; |
---|
83 | } else |
---|
84 | SetMsgHandled(FALSE); |
---|
85 | return 0; |
---|
86 | } |
---|
87 | LRESULT OnPaint(CDCHandle) |
---|
88 | { |
---|
89 | if(m_pVmrWindowlessControl) |
---|
90 | { |
---|
91 | CPaintDC Dc(m_hWnd); |
---|
92 | const HRESULT nRepaintVideoResult = m_pVmrWindowlessControl->RepaintVideo(m_hWnd, Dc); |
---|
93 | _Z4(atlTraceUI, SUCCEEDED(nRepaintVideoResult) ? 6 : 4, _T("nRepaintVideoResult 0x%08x\n"), nRepaintVideoResult); |
---|
94 | } else |
---|
95 | SetMsgHandled(FALSE); |
---|
96 | return 0; |
---|
97 | } |
---|
98 | LRESULT OnDisplayChange(UINT nDepth, CSize Extent) |
---|
99 | { |
---|
100 | if(m_pVmrWindowlessControl) |
---|
101 | { |
---|
102 | const HRESULT nDisplayModeChangedResult = m_pVmrWindowlessControl->DisplayModeChanged(); |
---|
103 | _Z4(atlTraceUI, 4, _T("nDisplayModeChangedResult 0x%08x\n"), nDisplayModeChangedResult); |
---|
104 | } |
---|
105 | return 0; |
---|
106 | } |
---|
107 | LRESULT OnSize(UINT nType, CSize) |
---|
108 | { |
---|
109 | if(nType != SIZE_MINIMIZED) |
---|
110 | if(m_pVmrWindowlessControl) |
---|
111 | { |
---|
112 | CRect VideoPosition = GetVideoPosition(); |
---|
113 | const HRESULT nSetVideoPositionResult = m_pVmrWindowlessControl->SetVideoPosition(NULL, &VideoPosition); |
---|
114 | _Z4(atlTraceUI, SUCCEEDED(nSetVideoPositionResult) ? 6 : 4, _T("nSetVideoPositionResult 0x%08x\n"), nSetVideoPositionResult); |
---|
115 | } |
---|
116 | return 0; |
---|
117 | } |
---|
118 | LRESULT OnLButtonDblClk(UINT, CPoint Position) |
---|
119 | { |
---|
120 | COlePropertyFrameDialog Dialog; |
---|
121 | Dialog.SetObject(m_pBaseFilter); |
---|
122 | Dialog.SetObjectPages(); |
---|
123 | Dialog.DoModal(m_hWnd); |
---|
124 | return 0; |
---|
125 | } |
---|
126 | }; |
---|
127 | |
---|
128 | //////////////////////////////////////////////////////////// |
---|
129 | // CMainPropertySheet |
---|
130 | |
---|
131 | class CMainPropertySheet : |
---|
132 | public CSizablePropertySheetT<CMainPropertySheet> |
---|
133 | { |
---|
134 | public: |
---|
135 | |
---|
136 | BEGIN_MSG_MAP_EX(CMainPropertySheet) |
---|
137 | CHAIN_MSG_MAP(CSizablePropertySheet) |
---|
138 | MESSAGE_HANDLER_EX(WM_SETLARGERINITIALPOSITION, OnSetLargerInitialPosition) |
---|
139 | END_MSG_MAP() |
---|
140 | |
---|
141 | public: |
---|
142 | |
---|
143 | //////////////////////////////////////////////////////// |
---|
144 | // Window Message Identifiers |
---|
145 | |
---|
146 | enum |
---|
147 | { |
---|
148 | MW_FIRST = WM_APP + 100, |
---|
149 | WM_SETLARGERINITIALPOSITION, |
---|
150 | }; |
---|
151 | |
---|
152 | //////////////////////////////////////////////////////// |
---|
153 | // CSourceFilter |
---|
154 | |
---|
155 | class ATL_NO_VTABLE CSourceFilter : |
---|
156 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
157 | public CComCoClass<CSourceFilter>, |
---|
158 | public CPushSourceFilterT<CSourceFilter>, |
---|
159 | public CBasePersistT<CSourceFilter>, |
---|
160 | public CAmFilterMiscFlagsT<CSourceFilter, AM_FILTER_MISC_FLAGS_IS_SOURCE> |
---|
161 | { |
---|
162 | public: |
---|
163 | |
---|
164 | DECLARE_NO_REGISTRY() |
---|
165 | |
---|
166 | DECLARE_PROTECT_FINAL_CONSTRUCT() |
---|
167 | |
---|
168 | //DECLARE_QI_TRACE(CSourceFilter) |
---|
169 | |
---|
170 | BEGIN_COM_MAP(CSourceFilter) |
---|
171 | COM_INTERFACE_ENTRY(IBaseFilter) |
---|
172 | COM_INTERFACE_ENTRY(IMediaFilter) |
---|
173 | COM_INTERFACE_ENTRY_IID(__uuidof(IPersist), IBaseFilter) |
---|
174 | COM_INTERFACE_ENTRY(IAMFilterMiscFlags) |
---|
175 | END_COM_MAP() |
---|
176 | |
---|
177 | public: |
---|
178 | |
---|
179 | //////////////////////////////////////////////////////// |
---|
180 | // CThreadContext |
---|
181 | |
---|
182 | class CThreadContext : |
---|
183 | public CPushSourceFilter::CThreadContext |
---|
184 | { |
---|
185 | public: |
---|
186 | SIZE_T m_nMediaSampleIndex; |
---|
187 | |
---|
188 | public: |
---|
189 | // CThreadContext |
---|
190 | CThreadContext(CEvent& TerminationEvent) throw() : |
---|
191 | CPushSourceFilter::CThreadContext(TerminationEvent), |
---|
192 | m_nMediaSampleIndex(0) |
---|
193 | { |
---|
194 | } |
---|
195 | }; |
---|
196 | |
---|
197 | //////////////////////////////////////////////////////// |
---|
198 | // COutputPin |
---|
199 | |
---|
200 | class ATL_NO_VTABLE COutputPin : |
---|
201 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
202 | public CPushSourceFilterT<CSourceFilter>::COutputPinT<COutputPin, CSourceFilter, CThreadContext>, |
---|
203 | public CAmPushSourceT<COutputPin, 0> |
---|
204 | { |
---|
205 | public: |
---|
206 | |
---|
207 | //DECLARE_QI_TRACE(CSourceFilter::COutputPin) |
---|
208 | |
---|
209 | BEGIN_COM_MAP(COutputPin) |
---|
210 | COM_INTERFACE_ENTRY(IPin) |
---|
211 | COM_INTERFACE_ENTRY(IAMPushSource) |
---|
212 | COM_INTERFACE_ENTRY(IAMLatency) |
---|
213 | END_COM_MAP() |
---|
214 | |
---|
215 | private: |
---|
216 | |
---|
217 | public: |
---|
218 | // COutputPin |
---|
219 | COutputPin() throw() |
---|
220 | { |
---|
221 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
222 | } |
---|
223 | ~COutputPin() throw() |
---|
224 | { |
---|
225 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
226 | } |
---|
227 | VOID EnumerateMediaTypes(CAtlList<CMediaType>& MediaTypeList) |
---|
228 | { |
---|
229 | //CRoCriticalSectionLock DataLock(GetDataCriticalSection()); |
---|
230 | _W(MediaTypeList.AddTail(GetFilter()->m_pRequestedMediaType)); |
---|
231 | } |
---|
232 | BOOL CheckMediaType(const CMediaType& pMediaType) const throw() |
---|
233 | { |
---|
234 | _A(pMediaType); |
---|
235 | if(pMediaType->majortype != MEDIATYPE_Video) |
---|
236 | return FALSE; |
---|
237 | //CRoCriticalSectionLock DataLock(GetDataCriticalSection()); |
---|
238 | _A(GetFilter()->m_pRequestedMediaType); |
---|
239 | //if(GetFilter()->m_pRequestedMediaType.Compare(pMediaType)) |
---|
240 | // return TRUE; |
---|
241 | return CVideoInfoHeader::Compare(&GetFilter()->m_pRequestedMediaType.GetCompatibleVideoInfoHeader(), &pMediaType.GetCompatibleVideoInfoHeader(), FALSE); |
---|
242 | } |
---|
243 | BOOL DecideMemAllocatorProperties(IMemAllocator* pMemAllocator, ALLOCATOR_PROPERTIES Properties) throw() |
---|
244 | { |
---|
245 | static const SIZE_T g_nMiminalBufferCount = 8; |
---|
246 | Properties.cBuffers = max(Properties.cBuffers, (LONG) g_nMiminalBufferCount); |
---|
247 | CRoCriticalSectionLock DataLock(GetDataCriticalSection()); |
---|
248 | const CMediaType& pMediaType = GetMediaTypeReference(); |
---|
249 | const CVideoInfoHeader VideoInfoHeader = pMediaType.GetCompatibleVideoInfoHeader(); |
---|
250 | return SetMemAllocatorBufferSize(pMemAllocator, Properties, VideoInfoHeader.GetDataSize()); |
---|
251 | } |
---|
252 | BOOL ComposeMediaSample(CThreadContext& ThreadContext, IMediaSample* pMediaSample) |
---|
253 | { |
---|
254 | CMediaSampleProperties OutputProperties(pMediaSample); |
---|
255 | #pragma region Dynamic Type Change |
---|
256 | if(OutputProperties.dwSampleFlags & AM_SAMPLE_TYPECHANGED) |
---|
257 | { |
---|
258 | _A(OutputProperties.pMediaType); |
---|
259 | _A(CheckMediaType(OutputProperties.pMediaType)); |
---|
260 | SetMediaType(OutputProperties.pMediaType); |
---|
261 | } else |
---|
262 | _A(!OutputProperties.pMediaType); |
---|
263 | #pragma endregion |
---|
264 | const CMediaType pMediaType = GetMediaType(); |
---|
265 | const CVideoInfoHeader VideoInfoHeader = pMediaType.GetCompatibleVideoInfoHeader(); |
---|
266 | OutputProperties.dwTypeSpecificFlags = 0; |
---|
267 | OutputProperties.dwSampleFlags = AM_SAMPLE_SPLICEPOINT | (ThreadContext.m_nMediaSampleIndex ? 0 : AM_SAMPLE_DATADISCONTINUITY) | AM_SAMPLE_TIMEVALID | AM_SAMPLE_STOPVALID; |
---|
268 | OutputProperties.lActual = VideoInfoHeader.GetDataSize(); |
---|
269 | OutputProperties.tStart = ThreadContext.m_nMediaSampleIndex * VideoInfoHeader.AvgTimePerFrame; |
---|
270 | OutputProperties.tStop = OutputProperties.tStart + 1; |
---|
271 | OutputProperties.dwStreamId = 0; |
---|
272 | #pragma region Data |
---|
273 | const CSize Extent = VideoInfoHeader.GetExtent(); |
---|
274 | const CBitmapInfoHeader& BitmapInfoHeader = VideoInfoHeader.GetBitmapInfoHeader(); |
---|
275 | SSIZE_T nFirstRowOffset, nNextRowOffset; |
---|
276 | VideoInfoHeader.GetData(nFirstRowOffset, nNextRowOffset); |
---|
277 | _A(BitmapInfoHeader.biCompression == FOURCC_YV12 && BitmapInfoHeader.biCompression == pMediaType->subtype.Data1); |
---|
278 | const BYTE nD = 0x80 + (CHAR) (0x70 * sin((2 * M_PI * ThreadContext.m_nMediaSampleIndex) / 20)); |
---|
279 | const BYTE nE = 0x00 + (CHAR) (0x70 * sin((2 * M_PI * ThreadContext.m_nMediaSampleIndex) / 170)); |
---|
280 | const BYTE nF = 0x00 + (CHAR) (0x70 * sin((2 * M_PI * ThreadContext.m_nMediaSampleIndex) / 190)); |
---|
281 | //_Z4(atlTraceGeneral, 4, _T("m_nMediaSampleIndex %d, tStart %s, %02X %02X %02X\n"), ThreadContext.m_nMediaSampleIndex, _FilterGraphHelper::FormatReferenceTime(OutputProperties.tStart), nD, nE, nF); |
---|
282 | BYTE* pnData = OutputProperties.pbBuffer; |
---|
283 | _A(!nFirstRowOffset); |
---|
284 | FillMemory(OutputProperties.pbBuffer, Extent.cy * nNextRowOffset, nD); |
---|
285 | FillMemory(OutputProperties.pbBuffer + Extent.cy * nNextRowOffset, Extent.cy * nNextRowOffset / 4, nE); |
---|
286 | FillMemory(OutputProperties.pbBuffer + Extent.cy * nNextRowOffset + Extent.cy * nNextRowOffset / 4, Extent.cy * nNextRowOffset / 4, nF); |
---|
287 | #pragma endregion |
---|
288 | OutputProperties.Set(); |
---|
289 | ThreadContext.m_nMediaSampleIndex++; |
---|
290 | return TRUE; |
---|
291 | } |
---|
292 | }; |
---|
293 | |
---|
294 | private: |
---|
295 | CObjectPtr<COutputPin> m_pOutputPin; |
---|
296 | CMediaType m_pRequestedMediaType; |
---|
297 | |
---|
298 | public: |
---|
299 | // CSourceFilter |
---|
300 | CSourceFilter() throw() : |
---|
301 | CBasePersistT<CSourceFilter>(GetDataCriticalSection()) |
---|
302 | { |
---|
303 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
304 | } |
---|
305 | ~CSourceFilter() throw() |
---|
306 | { |
---|
307 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
308 | } |
---|
309 | HRESULT FinalConstruct() throw() |
---|
310 | { |
---|
311 | _ATLTRY |
---|
312 | { |
---|
313 | m_pOutputPin.Construct()->Initialize(this, L"Output"); |
---|
314 | AddPin(m_pOutputPin); |
---|
315 | } |
---|
316 | _ATLCATCH(Exception) |
---|
317 | { |
---|
318 | _C(Exception); |
---|
319 | } |
---|
320 | return S_OK; |
---|
321 | } |
---|
322 | VOID FinalRelease() throw() |
---|
323 | { |
---|
324 | m_pOutputPin = NULL; |
---|
325 | } |
---|
326 | VOID DeliverBeginFlush(IPin*) |
---|
327 | { |
---|
328 | m_pOutputPin->DeliverBeginFlush(); |
---|
329 | } |
---|
330 | VOID DeliverEndFlush(IPin*) |
---|
331 | { |
---|
332 | m_pOutputPin->DeliverEndFlush(); |
---|
333 | } |
---|
334 | VOID DeliverNewSegment(IPin*, REFERENCE_TIME nStartTime, REFERENCE_TIME nStopTime, DOUBLE fRate) |
---|
335 | { |
---|
336 | m_pOutputPin->DeliverNewSegment(nStartTime, nStopTime, fRate); |
---|
337 | } |
---|
338 | static BOOL CanCue() throw() |
---|
339 | { |
---|
340 | return FALSE; |
---|
341 | } |
---|
342 | VOID CueFilter() |
---|
343 | { |
---|
344 | m_pOutputPin->CuePin(); |
---|
345 | } |
---|
346 | VOID RunFilter(REFERENCE_TIME nStartTime) |
---|
347 | { |
---|
348 | m_pOutputPin->RunPin(nStartTime); |
---|
349 | } |
---|
350 | VOID PauseFilter() throw() |
---|
351 | { |
---|
352 | m_pOutputPin->PausePin(); |
---|
353 | } |
---|
354 | VOID StopFilter() throw() |
---|
355 | { |
---|
356 | m_pOutputPin->StopPin(); |
---|
357 | } |
---|
358 | const CObjectPtr<COutputPin>& GetOutputPin() const throw() |
---|
359 | { |
---|
360 | return m_pOutputPin; |
---|
361 | } |
---|
362 | VOID Initialize() |
---|
363 | { |
---|
364 | _A(!m_pRequestedMediaType); |
---|
365 | CMediaType pMediaType; |
---|
366 | pMediaType.AllocateVideoInfo(720, 480, 12, FOURCC_YV12, 1000 * 10000i64 / 40); |
---|
367 | pMediaType->bFixedSizeSamples = TRUE; |
---|
368 | pMediaType->lSampleSize = pMediaType.GetVideoInfoHeader()->GetDataSize(); |
---|
369 | m_pRequestedMediaType = pMediaType; |
---|
370 | } |
---|
371 | const CMediaType& GetRequestedMediaType() const throw() |
---|
372 | { |
---|
373 | return m_pRequestedMediaType; |
---|
374 | } |
---|
375 | }; |
---|
376 | |
---|
377 | //////////////////////////////////////////////////////////// |
---|
378 | // CAmGraphBuilderCallback |
---|
379 | |
---|
380 | class ATL_NO_VTABLE CAmGraphBuilderCallback : |
---|
381 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
382 | public IAMGraphBuilderCallback |
---|
383 | { |
---|
384 | public: |
---|
385 | |
---|
386 | BEGIN_COM_MAP(CAmGraphBuilderCallback) |
---|
387 | COM_INTERFACE_ENTRY(IAMGraphBuilderCallback) |
---|
388 | END_COM_MAP() |
---|
389 | |
---|
390 | public: |
---|
391 | // CAmGraphBuilderCallback |
---|
392 | CAmGraphBuilderCallback() throw() |
---|
393 | { |
---|
394 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
395 | } |
---|
396 | ~CAmGraphBuilderCallback() throw() |
---|
397 | { |
---|
398 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
399 | } |
---|
400 | VOID SetGraphBuilder(IUnknown* pGraphBuilderUnknown) |
---|
401 | { |
---|
402 | const CComQIPtr<IObjectWithSite> pObjectWithSite = pGraphBuilderUnknown; |
---|
403 | __D(pObjectWithSite, E_NOINTERFACE); |
---|
404 | __C(pObjectWithSite->SetSite(this)); |
---|
405 | } |
---|
406 | |
---|
407 | // IAMGraphBuilderCallback |
---|
408 | STDMETHOD(SelectedFilter)(IMoniker* pMoniker) throw() |
---|
409 | { |
---|
410 | _Z5(atlTraceCOM, 5, _T("...\n")); |
---|
411 | _ATLTRY |
---|
412 | { |
---|
413 | _A(pMoniker); |
---|
414 | CComPtr<IBindCtx> pBindCtx; |
---|
415 | __C(CreateBindCtx(0, &pBindCtx)); |
---|
416 | if(_FilterGraphHelper::IsFilterNonGrata(pMoniker)) |
---|
417 | return E_FAIL; |
---|
418 | const CStringW sMonikerDisplayName = _FilterGraphHelper::GetMonikerDisplayName(pMoniker, pBindCtx); |
---|
419 | CComPtr<IPropertyBag> pPropertyBag; |
---|
420 | __C(pMoniker->BindToStorage(pBindCtx, NULL, __uuidof(IPropertyBag), (VOID**) &pPropertyBag)); |
---|
421 | const CStringW sFriendlyName = _FilterGraphHelper::ReadPropertyBagString(pPropertyBag, OLESTR("FriendlyName")); |
---|
422 | const CStringW sClassIdentifierString = _FilterGraphHelper::ReadPropertyBagString(pPropertyBag, OLESTR("CLSID")); |
---|
423 | const CStringW sPath = _RegKeyHelper::QueryStringValue(HKEY_CLASSES_ROOT, AtlFormatString(_T("CLSID\\%ls\\InprocServer32"), sClassIdentifierString)); |
---|
424 | _Z4(atlTraceGeneral, 4, _T("sMonikerDisplayName \"%ls\", sFriendlyName \"%ls\", sClassIdentifierString %ls, sPath \"%ls\"\n"), sMonikerDisplayName, sFriendlyName, sClassIdentifierString, sPath); |
---|
425 | } |
---|
426 | _ATLCATCH(Exception) |
---|
427 | { |
---|
428 | _C(Exception); |
---|
429 | } |
---|
430 | return S_OK; |
---|
431 | } |
---|
432 | STDMETHOD(CreatedFilter)(IBaseFilter* pBaseFilter) throw() |
---|
433 | { |
---|
434 | _Z5(atlTraceCOM, 5, _T("...\n")); |
---|
435 | _ATLTRY |
---|
436 | { |
---|
437 | _A(pBaseFilter); |
---|
438 | _Z4(atlTraceGeneral, 4, _T("pBaseFilter %ls \"%ls\"\n"), _FilterGraphHelper::GetFilterClassIdentifierString(pBaseFilter), _FilterGraphHelper::GetFilterName(pBaseFilter)); |
---|
439 | } |
---|
440 | _ATLCATCH(Exception) |
---|
441 | { |
---|
442 | _C(Exception); |
---|
443 | } |
---|
444 | return S_OK; |
---|
445 | } |
---|
446 | }; |
---|
447 | |
---|
448 | //////////////////////////////////////////////////// |
---|
449 | // CVmr7PropertyPage |
---|
450 | |
---|
451 | class CVmr7PropertyPage : |
---|
452 | public CPropertyPageT<CVmr7PropertyPage>, |
---|
453 | public CDialogResize<CVmr7PropertyPage> |
---|
454 | { |
---|
455 | public: |
---|
456 | enum { IDD = IDD_MAIN_VMR7 }; |
---|
457 | |
---|
458 | BEGIN_MSG_MAP_EX(CVmr7PropertyPage) |
---|
459 | CHAIN_MSG_MAP(CPropertyPageT<CVmr7PropertyPage>) |
---|
460 | CHAIN_MSG_MAP(CDialogResize<CVmr7PropertyPage>) |
---|
461 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
462 | MSG_WM_DESTROY(OnDestroy) |
---|
463 | COMMAND_ID_HANDLER_EX(IDC_MAIN_VMR7_RUN, OnRunButtonClicked) |
---|
464 | COMMAND_ID_HANDLER_EX(IDC_MAIN_VMR7_PAUSE, OnPauseButtonClicked) |
---|
465 | COMMAND_ID_HANDLER_EX(IDC_MAIN_VMR7_STOP, OnStopButtonClicked) |
---|
466 | MESSAGE_HANDLER_EX(WM_FILTERGRAPHEVENT, OnFilterGraphEvent) |
---|
467 | REFLECT_NOTIFICATIONS() |
---|
468 | END_MSG_MAP() |
---|
469 | |
---|
470 | BEGIN_DLGRESIZE_MAP(CVmr7PropertyPage) |
---|
471 | DLGRESIZE_CONTROL(IDC_MAIN_VMR7_VIDEO, DLSZ_SIZE_X | DLSZ_SIZE_Y) |
---|
472 | DLGRESIZE_CONTROL(IDC_MAIN_VMR7_RUN, DLSZ_MOVE_X) |
---|
473 | DLGRESIZE_CONTROL(IDC_MAIN_VMR7_PAUSE, DLSZ_MOVE_X) |
---|
474 | DLGRESIZE_CONTROL(IDC_MAIN_VMR7_STOP, DLSZ_MOVE_X) |
---|
475 | END_DLGRESIZE_MAP() |
---|
476 | |
---|
477 | public: |
---|
478 | |
---|
479 | //////////////////////////////////////////////////////// |
---|
480 | // Window Message Identifiers |
---|
481 | |
---|
482 | enum |
---|
483 | { |
---|
484 | WM_FIRST = WM_APP, |
---|
485 | WM_FILTERGRAPHEVENT, |
---|
486 | }; |
---|
487 | |
---|
488 | private: |
---|
489 | CMainPropertySheet& m_Owner; |
---|
490 | CStatic m_VideoStatic; |
---|
491 | CGenericFilterGraph m_FilterGraph; |
---|
492 | CObjectPtr<CSourceFilter> m_pSourceFilter; |
---|
493 | CVmr7Window m_RendererWindow; |
---|
494 | CButton m_RunButton; |
---|
495 | CButton m_PauseButton; |
---|
496 | CButton m_StopButton; |
---|
497 | |
---|
498 | VOID UpdateControls() |
---|
499 | { |
---|
500 | OAFilterState State; |
---|
501 | if(SUCCEEDED(m_FilterGraph.m_pMediaControl->GetState(0, &State))) |
---|
502 | { |
---|
503 | m_RunButton.EnableWindow(State != State_Running); |
---|
504 | m_PauseButton.EnableWindow(State != State_Paused); |
---|
505 | m_StopButton.EnableWindow(State != State_Stopped); |
---|
506 | } else |
---|
507 | { |
---|
508 | m_RunButton.EnableWindow(FALSE); |
---|
509 | m_PauseButton.EnableWindow(FALSE); |
---|
510 | m_StopButton.EnableWindow(FALSE); |
---|
511 | } |
---|
512 | } |
---|
513 | |
---|
514 | public: |
---|
515 | // CVmr7PropertyPage |
---|
516 | CVmr7PropertyPage(CMainPropertySheet* pOwner) : |
---|
517 | m_Owner(*pOwner) |
---|
518 | { |
---|
519 | } |
---|
520 | |
---|
521 | // CDialogResize |
---|
522 | VOID DlgResize_UpdateLayout(INT nWidth, INT nHeight) |
---|
523 | { |
---|
524 | __super::DlgResize_UpdateLayout(nWidth, nHeight); |
---|
525 | CRect VideoPosition; |
---|
526 | _W(m_VideoStatic.GetWindowRect(VideoPosition)); |
---|
527 | _W(ScreenToClient(VideoPosition)); |
---|
528 | _W(m_RendererWindow.MoveWindow(VideoPosition)); |
---|
529 | } |
---|
530 | |
---|
531 | // Window Message Handelrs |
---|
532 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
533 | { |
---|
534 | m_VideoStatic = GetDlgItem(IDC_MAIN_VMR7_VIDEO); |
---|
535 | m_VideoStatic.ShowWindow(SW_HIDE); |
---|
536 | CRect VideoPosition; |
---|
537 | _W(m_VideoStatic.GetWindowRect(VideoPosition)); |
---|
538 | _W(ScreenToClient(VideoPosition)); |
---|
539 | m_RunButton = GetDlgItem(IDC_MAIN_VMR7_RUN); |
---|
540 | m_PauseButton = GetDlgItem(IDC_MAIN_VMR7_PAUSE); |
---|
541 | m_StopButton = GetDlgItem(IDC_MAIN_VMR7_STOP); |
---|
542 | DlgResize_Init(FALSE); |
---|
543 | m_FilterGraph.CoCreateInstance(); |
---|
544 | CObjectPtr<CAmGraphBuilderCallback> pAmGraphBuilderCallback; |
---|
545 | pAmGraphBuilderCallback.Construct(); |
---|
546 | pAmGraphBuilderCallback->SetGraphBuilder(m_FilterGraph.m_pFilterGraph); |
---|
547 | const CComPtr<IBaseFilter> pBaseFilter = m_RendererWindow.CoCreateBaseFilterInstance(); |
---|
548 | __C(m_FilterGraph->AddFilter(pBaseFilter, CT2CW(_T("VMR-7")))); |
---|
549 | m_RendererWindow.Create(m_hWnd); |
---|
550 | _W(m_RendererWindow.MoveWindow(VideoPosition)); |
---|
551 | m_RendererWindow.ShowWindow(SW_SHOWNORMAL); |
---|
552 | m_RendererWindow.Initialize(pBaseFilter); |
---|
553 | CObjectPtr<CSourceFilter> pSourceFilter; |
---|
554 | pSourceFilter.Construct()->Initialize(); |
---|
555 | m_pSourceFilter = pSourceFilter; |
---|
556 | __C(m_FilterGraph->AddFilter(pSourceFilter, CT2CW(_T("Source")))); |
---|
557 | __C(m_FilterGraph->Connect(pSourceFilter->GetOutputPin(), _FilterGraphHelper::GetFilterPin(m_RendererWindow.m_pBaseFilter))); |
---|
558 | __C(m_FilterGraph.m_pMediaEventEx->SetNotifyWindow((OAHWND) m_hWnd, WM_FILTERGRAPHEVENT, (LONG_PTR) this)); |
---|
559 | UpdateControls(); |
---|
560 | return 0; |
---|
561 | } |
---|
562 | LRESULT OnDestroy() throw() |
---|
563 | { |
---|
564 | if(m_FilterGraph.m_pMediaControl) |
---|
565 | _V(m_FilterGraph.m_pMediaControl->Stop()); |
---|
566 | m_RendererWindow.Terminate(); |
---|
567 | m_pSourceFilter.Release(); |
---|
568 | m_FilterGraph.Release(); |
---|
569 | return 0; |
---|
570 | } |
---|
571 | LRESULT OnRunButtonClicked(UINT, INT, HWND) |
---|
572 | { |
---|
573 | CWaitCursor WaitCursor; |
---|
574 | __D(m_FilterGraph.m_pMediaControl, E_NOINTERFACE); |
---|
575 | __C(m_FilterGraph.m_pMediaControl->Run()); |
---|
576 | UpdateControls(); |
---|
577 | return 0; |
---|
578 | } |
---|
579 | LRESULT OnPauseButtonClicked(UINT, INT, HWND) |
---|
580 | { |
---|
581 | CWaitCursor WaitCursor; |
---|
582 | __D(m_FilterGraph.m_pMediaControl, E_NOINTERFACE); |
---|
583 | __C(m_FilterGraph.m_pMediaControl->Pause()); |
---|
584 | UpdateControls(); |
---|
585 | return 0; |
---|
586 | } |
---|
587 | LRESULT OnStopButtonClicked(UINT, INT, HWND) |
---|
588 | { |
---|
589 | CWaitCursor WaitCursor; |
---|
590 | if(m_FilterGraph.m_pMediaControl) |
---|
591 | _V(m_FilterGraph.m_pMediaControl->Stop()); |
---|
592 | UpdateControls(); |
---|
593 | return 0; |
---|
594 | } |
---|
595 | LRESULT OnFilterGraphEvent(UINT, WPARAM, LPARAM) |
---|
596 | { |
---|
597 | if(!m_FilterGraph.m_pMediaEventEx) |
---|
598 | return 0; |
---|
599 | _ATLTRY |
---|
600 | { |
---|
601 | for(; ; ) |
---|
602 | { |
---|
603 | LONG nEventCode; |
---|
604 | LONG_PTR nParameter1, nParameter2; |
---|
605 | const HRESULT nGetEventResult = m_FilterGraph.m_pMediaEventEx->GetEvent(&nEventCode, &nParameter1, &nParameter2, 0); |
---|
606 | if(nGetEventResult == E_ABORT) |
---|
607 | break; |
---|
608 | __C(nGetEventResult); |
---|
609 | _ATLTRY |
---|
610 | { |
---|
611 | switch(nEventCode) |
---|
612 | { |
---|
613 | case EC_ERRORABORT: |
---|
614 | _Z2(atlTraceGeneral, 2, _T("nEventCode EC_ERRORABORT 0x%02X, nParameter1 0x%08x, nParameter2 0x%08x\n"), nEventCode, nParameter1, nParameter2); |
---|
615 | _A(FAILED(nParameter1)); |
---|
616 | AtlMessageBoxEx(m_hWnd, (LPCTSTR) AtlFormatString(_T("EC_ERRORABORT Event: %s."), AtlFormatSystemMessage((HRESULT) nParameter1).TrimRight(_T("\t\n\r ."))), IDS_ERROR, MB_ICONERROR | MB_OK); |
---|
617 | break; |
---|
618 | default: |
---|
619 | _Z1(atlTraceGeneral, 1, _T("nEventCode 0x%02X, nParameter1 0x%08x, nParameter2 0x%08x\n"), nEventCode, nParameter1, nParameter2); |
---|
620 | } |
---|
621 | } |
---|
622 | _ATLCATCHALL() |
---|
623 | { |
---|
624 | _V(m_FilterGraph.m_pMediaEventEx->FreeEventParams(nEventCode, nParameter1, nParameter2)); |
---|
625 | _ATLRETHROW; |
---|
626 | } |
---|
627 | _V(m_FilterGraph.m_pMediaEventEx->FreeEventParams(nEventCode, nParameter1, nParameter2)); |
---|
628 | } |
---|
629 | } |
---|
630 | _ATLCATCHALL() |
---|
631 | { |
---|
632 | _Z_EXCEPTION(); |
---|
633 | } |
---|
634 | return 0; |
---|
635 | } |
---|
636 | INT OnKillActive() |
---|
637 | { |
---|
638 | m_StopButton.Click(); |
---|
639 | return 0; |
---|
640 | } |
---|
641 | }; |
---|
642 | |
---|
643 | public: |
---|
644 | CVmr7PropertyPage m_Vmr7PropertyPage; |
---|
645 | |
---|
646 | public: |
---|
647 | // CMainPropertySheet |
---|
648 | CMainPropertySheet() : |
---|
649 | CSizablePropertySheetT<CMainPropertySheet>(_T("RenderVideoSync")), |
---|
650 | m_Vmr7PropertyPage(this) |
---|
651 | { |
---|
652 | AddPage(m_Vmr7PropertyPage); |
---|
653 | } |
---|
654 | BOOL SetInitialPosition() |
---|
655 | { |
---|
656 | if(!__super::SetInitialPosition()) |
---|
657 | return FALSE; |
---|
658 | _W(PostMessage(WM_SETLARGERINITIALPOSITION)); |
---|
659 | return TRUE; |
---|
660 | } |
---|
661 | |
---|
662 | // Window Message Handelrs |
---|
663 | LRESULT OnSetLargerInitialPosition(UINT, WPARAM, LPARAM) |
---|
664 | { |
---|
665 | CRect Position; |
---|
666 | _W(GetWindowRect(Position)); |
---|
667 | Position.right += Position.Width(); |
---|
668 | Position.bottom += Position.Height() / 4; |
---|
669 | _W(SetWindowPos(NULL, Position, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE)); |
---|
670 | _W(CenterWindow()); |
---|
671 | return 0; |
---|
672 | } |
---|
673 | }; |
---|