Alax.Info ATL/WTL Utilities is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

Commit 287

User picture
  • Author: alax
  • 2011-07-06 17:31 (almost 3 years ago)

VMR-7 Allocator-Presenter

Files Affected

 
286287
65
    END_MSG_MAP()
65
    END_MSG_MAP()
66
 
66
 
67
    public:
67
    public:
 
 
68
 
 
 
69
        ////////////////////////////////////////////////////////
 
 
70
        // CAllocatorPresenter
 
 
71
 
 
 
72
        class ATL_NO_VTABLE CAllocatorPresenter :
 
 
73
            public CComObjectRootEx<CComMultiThreadModelNoCS>,
 
 
74
            public IVMRSurfaceAllocator,
 
 
75
            public IVMRImagePresenter
 
 
76
        {
 
 
77
        public:
 
 
78
 
 
 
79
        DECLARE_PROTECT_FINAL_CONSTRUCT()
 
 
80
 
 
 
81
        DECLARE_QI_TRACE(CAllocatorPresenter)
 
 
82
 
 
 
83
        // SUGG: IVMRImagePresenterConfig {9F3A1C85-8555-49BA-935F-BE5B5B29D178}
 
 
84
        //       IVMRMonitorConfig {9CF0B1B6-FBAA-4B7F-88CF-CF1F130A0DCE}
 
 
85
 
 
 
86
        BEGIN_COM_MAP(CAllocatorPresenter)
 
 
87
            COM_INTERFACE_ENTRY(IVMRSurfaceAllocator)
 
 
88
            COM_INTERFACE_ENTRY(IVMRImagePresenter)
 
 
89
        END_COM_MAP()
 
 
90
 
 
 
91
        private:
 
 
92
            CComPtr<IVMRSurfaceAllocator> m_pInnerVmrSurfaceAllocator;
 
 
93
            CComPtr<IVMRImagePresenter> m_pInnerVmrImagePresenter;
 
 
94
 
 
 
95
        public:
 
 
96
        // CAllocatorPresenter
 
 
97
            static CComPtr<IVMRSurfaceAllocator> CoCreateDefaultAllocatorPresenterInstance()
 
 
98
            {
 
 
99
                CComPtr<IVMRSurfaceAllocator> pVmrSurfaceAllocator;
 
 
100
                __C(pVmrSurfaceAllocator.CoCreateInstance(CLSID_AllocPresenter));
 
 
101
                return pVmrSurfaceAllocator;
 
 
102
            }
 
 
103
            CAllocatorPresenter() throw()
 
 
104
            {
 
 
105
                _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this);
 
 
106
                m_pInnerVmrSurfaceAllocator = CoCreateDefaultAllocatorPresenterInstance();
 
 
107
                m_pInnerVmrImagePresenter = CComQIPtr<IVMRImagePresenter>(m_pInnerVmrSurfaceAllocator);
 
 
108
            }
 
 
109
            ~CAllocatorPresenter() throw()
 
 
110
            {
 
 
111
                _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this);
 
 
112
            }
 
 
113
            const CComPtr<IVMRSurfaceAllocator>& GetInnerVmrSurfaceAllocator() const throw()
 
 
114
            {
 
 
115
                return m_pInnerVmrSurfaceAllocator;
 
 
116
            }
 
 
117
            CComPtr<IVMRWindowlessControl> GetInnerVmrWindowlessControl() const throw()
 
 
118
            {
 
 
119
                return CComQIPtr<IVMRWindowlessControl>(m_pInnerVmrSurfaceAllocator);
 
 
120
            }
 
 
121
 
 
 
122
        // IVMRSurfaceAllocator
 
 
123
            STDMETHOD(AllocateSurface)(DWORD_PTR nParameter, VMRALLOCATIONINFO* pAllocationInformation, DWORD* pnActualBufferCount, LPDIRECTDRAWSURFACE7*
ppSurface) throw()
 
 
124
            {
 
 
125
                _Z4(atlTraceCOM, 4, _T("nParameter 0x%p, *pnActualBufferCount %d\n"), nParameter, pnActualBufferCount ? *pnActualBufferCount : 0);
 
 
126
                _ATLTRY
 
 
127
                {
 
 
128
                    _Z4(atlTraceGeneral, 4, _T("pAllocationInformation->dwFlags 0x%x\n"), pAllocationInformation->dwFlags);
 
 
129
                    if(pAllocationInformation->lpPixFmt)
 
 
130
                        _Z4(atlTraceGeneral, 4, _T("pAllocationInformation->lpPixFmt->dwFlags 0x%x, ->dwFourCC %s\n"),
pAllocationInformation->lpPixFmt->dwFlags, _FilterGraphHelper::GetFourccCodeString(pAllocationInformation->lpPixFmt->dwFourCC));
 
 
131
                    const HRESULT nAllocateSurfaceResult = m_pInnerVmrSurfaceAllocator->AllocateSurface(nParameter, pAllocationInformation,
pnActualBufferCount, ppSurface);
 
 
132
                    if(SUCCEEDED(nAllocateSurfaceResult))
 
 
133
                    {
 
 
134
                        _Z4(atlTraceGeneral, 4, _T("nAllocateSurfaceResult 0x%08x, *pnActualBufferCount %d\n"), nAllocateSurfaceResult,
*pnActualBufferCount);
 
 
135
                        DDSCAPS2 Capabilities;
 
 
136
                        __C((*ppSurface)->GetCaps(&Capabilities));
 
 
137
                        _Z4(atlTraceGeneral, 4, _T("Capabilities.dwCaps 0x%x, .dwCaps2 0x%x, .dwCaps3 0x%x, .dwCaps4 0x%x\n"), Capabilities.dwCaps,
Capabilities.dwCaps2, Capabilities.dwCaps3, Capabilities.dwCaps4);
 
 
138
                        DDSURFACEDESC2 Descriptor = { sizeof Descriptor };
 
 
139
                        __C((*ppSurface)->GetSurfaceDesc(&Descriptor));
 
 
140
                        _Z4(atlTraceGeneral, 4, _T("Descriptor.dwFlags 0x%x, .dwHeight %d, dwWidth %d, .lPitch %d, .dwBackBufferCount %d\n"),
Descriptor.dwFlags, Descriptor.dwHeight, Descriptor.dwWidth, Descriptor.lPitch, Descriptor.dwBackBufferCount);
 
 
141
 
 
 
142
                        CComPtr<IDirectDraw7> pDirectDraw7;
 
 
143
                        __C((*ppSurface)->GetDDInterface((VOID**) (IDirectDraw7**) &pDirectDraw7));
 
 
144
 
 
 
145
                        //Descriptor.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
 
 
146
                        //Descriptor.ddsCaps.dwCaps2 |= DDSCAPS2_HINTANTIALIASING;
 
 
147
                        //CComPtr<IDirectDrawSurface7> pDirectDrawSurface7;
 
 
148
                        //const HRESULT nCreateSurfaceResult = pDirectDraw7->CreateSurface(&Descriptor, &pDirectDrawSurface7, NULL);
 
 
149
                        //_Z4(atlTraceGeneral, 4, _T("nCreateSurfaceResult 0x%08x, DDERR_INVALIDCAPS 0x%08x\n"), nCreateSurfaceResult,
DDERR_INVALIDCAPS);
 
 
150
                        //__asm nop; 
 
 
151
 
 
 
152
                    }
 
 
153
                    __C(nAllocateSurfaceResult);
 
 
154
                }
 
 
155
                _ATLCATCH(Exception)
 
 
156
                {
 
 
157
                    _C(Exception);
 
 
158
                }
 
 
159
                return S_OK;
 
 
160
            }
 
 
161
            STDMETHOD(FreeSurface)(DWORD_PTR nParameter) throw()
 
 
162
            {
 
 
163
                _Z4(atlTraceCOM, 4, _T("nParameter 0x%p\n"), nParameter);
 
 
164
                _ATLTRY
 
 
165
                {
 
 
166
                    const HRESULT nResult = m_pInnerVmrSurfaceAllocator->FreeSurface(nParameter);
 
 
167
                    __C(nResult);
 
 
168
                }
 
 
169
                _ATLCATCH(Exception)
 
 
170
                {
 
 
171
                    _C(Exception);
 
 
172
                }
 
 
173
                return S_OK;
 
 
174
            }
 
 
175
            STDMETHOD(PrepareSurface)(DWORD_PTR nParameter, LPDIRECTDRAWSURFACE7 pSurface, DWORD nSurfaceFlags) throw()
 
 
176
            {
 
 
177
                _Z4(atlTraceCOM, 4, _T("nParameter 0x%p, nSurfaceFlags 0x%x\n"), nParameter, nSurfaceFlags);
 
 
178
                _ATLTRY
 
 
179
                {
 
 
180
                    const HRESULT nResult = m_pInnerVmrSurfaceAllocator->PrepareSurface(nParameter, pSurface, nSurfaceFlags);
 
 
181
                    __C(nResult);
 
 
182
                }
 
 
183
                _ATLCATCH(Exception)
 
 
184
                {
 
 
185
                    _C(Exception);
 
 
186
                }
 
 
187
                return S_OK;
 
 
188
            }
 
 
189
            STDMETHOD(AdviseNotify)(IVMRSurfaceAllocatorNotify* pVmrSurfaceAllocatorNotify) throw()
 
 
190
            {
 
 
191
                _Z4(atlTraceCOM, 4, _T("...\n"));
 
 
192
                _ATLTRY
 
 
193
                {
 
 
194
                    const HRESULT nResult = m_pInnerVmrSurfaceAllocator->AdviseNotify(pVmrSurfaceAllocatorNotify);
 
 
195
                    __C(nResult);
 
 
196
                }
 
 
197
                _ATLCATCH(Exception)
 
 
198
                {
 
 
199
                    _C(Exception);
 
 
200
                }
 
 
201
                return S_OK;
 
 
202
            }
 
 
203
 
 
 
204
        // IVMRImagePresenter
 
 
205
            STDMETHOD(StartPresenting)(DWORD_PTR nParameter) throw()
 
 
206
            {
 
 
207
                _Z4(atlTraceCOM, 4, _T("nParameter 0x%p\n"), nParameter);
 
 
208
                _ATLTRY
 
 
209
                {
 
 
210
                    const HRESULT nResult = m_pInnerVmrImagePresenter->StartPresenting(nParameter);
 
 
211
                    __C(nResult);
 
 
212
                }
 
 
213
                _ATLCATCH(Exception)
 
 
214
                {
 
 
215
                    _C(Exception);
 
 
216
                }
 
 
217
                return S_OK;
 
 
218
            }
 
 
219
            STDMETHOD(StopPresenting)(DWORD_PTR nParameter) throw()
 
 
220
            {
 
 
221
                _Z4(atlTraceCOM, 4, _T("nParameter 0x%p\n"), nParameter);
 
 
222
                _ATLTRY
 
 
223
                {
 
 
224
                    const HRESULT nResult = m_pInnerVmrImagePresenter->StopPresenting(nParameter);
 
 
225
                    __C(nResult);
 
 
226
                }
 
 
227
                _ATLCATCH(Exception)
 
 
228
                {
 
 
229
                    _C(Exception);
 
 
230
                }
 
 
231
                return S_OK;
 
 
232
            }
 
 
233
            STDMETHOD(PresentImage)(DWORD_PTR nParameter, VMRPRESENTATIONINFO* pPresentationInformation) throw()
 
 
234
            {
 
 
235
                _Z4(atlTraceCOM, 4, _T("nParameter 0x%p\n"), nParameter);
 
 
236
                _ATLTRY
 
 
237
                {
 
 
238
                    _A(pPresentationInformation);
 
 
239
                    _Z4(atlTraceCOM, 4, _T("pPresentationInformation->dwFlags 0x%x\n"), pPresentationInformation->dwFlags);
 
 
240
                    _Z4(atlTraceCOM, 4, _T("pPresentationInformation->rtStart %s, ->rtStop %s\n"),
_FilterGraphHelper::FormatReferenceTime(pPresentationInformation->rtStart), _FilterGraphHelper::FormatReferenceTime(pPresentationInformation->rtEnd));
 
 
241
                    _Z4(atlTraceCOM, 4, _T("pPresentationInformation->rcSrc (%d, %d) - (%d, %d), ->rcDst (%d, %d) - (%d, %d)\n"),
pPresentationInformation->rcSrc, pPresentationInformation->rcDst);
 
 
242
                    _Z4(atlTraceCOM, 4, _T("pPresentationInformation->dwTypeSpecificFlags 0x%x, ->dwInterlaceFlags 0x%x\n"),
pPresentationInformation->dwTypeSpecificFlags, pPresentationInformation->dwInterlaceFlags);
 
 
243
                    const HRESULT nResult = m_pInnerVmrImagePresenter->PresentImage(nParameter, pPresentationInformation);
 
 
244
                    __C(nResult);
 
 
245
                }
 
 
246
                _ATLCATCH(Exception)
 
 
247
                {
 
 
248
                    _C(Exception);
 
 
249
                }
 
 
250
                return S_OK;
 
 
251
            }
 
 
252
        };
 
 
253
 
 
 
254
    public:
68
        CComPtr<IBaseFilter> m_pBaseFilter;
255
        CComPtr<IBaseFilter> m_pBaseFilter;
69
        CComPtr<IVMRWindowlessControl> m_pVmrWindowlessControl;
256
        CComPtr<IVMRWindowlessControl> m_pVmrWindowlessControl;
70
 
257
 
71
    public:
258
    public:
72
    // CEvrWindow
259
    // CVmr7Window
73
        VOID Initialize(IBaseFilter* pBaseFilter)
260
        VOID Initialize(IBaseFilter* pBaseFilter)
74
        {
261
        {
75
            _A(pBaseFilter);
262
            _A(pBaseFilter);
...
 
...
 
77
            m_pBaseFilter = pBaseFilter;
264
            m_pBaseFilter = pBaseFilter;
78
            CComQIPtr<IVMRFilterConfig> pVmrFilterConfig = pBaseFilter;
265
            CComQIPtr<IVMRFilterConfig> pVmrFilterConfig = pBaseFilter;
79
            __D(pVmrFilterConfig, E_NOINTERFACE);
266
            __D(pVmrFilterConfig, E_NOINTERFACE);
 
 
267
#if TRUE
 
 
268
            __C(pVmrFilterConfig->SetRenderingMode(VMRMode_Renderless));
 
 
269
            CComQIPtr<IVMRSurfaceAllocatorNotify> pVmrSurfaceAllocatorNotify = pBaseFilter;
 
 
270
            __D(pVmrSurfaceAllocatorNotify, E_NOINTERFACE);
 
 
271
            CObjectPtr<CAllocatorPresenter> pAllocatorPresenter;
 
 
272
            pAllocatorPresenter.Construct();
 
 
273
            __C(pVmrSurfaceAllocatorNotify->AdviseSurfaceAllocator(1, pAllocatorPresenter));
 
 
274
            __C(pAllocatorPresenter->GetInnerVmrSurfaceAllocator()->AdviseNotify(pVmrSurfaceAllocatorNotify));
 
 
275
            m_pVmrWindowlessControl = CComQIPtr<IVMRWindowlessControl>(pAllocatorPresenter->GetInnerVmrWindowlessControl());
 
 
276
            __D(m_pVmrWindowlessControl, E_NOINTERFACE);
 
 
277
            __C(m_pVmrWindowlessControl->SetVideoClippingWindow(m_hWnd));
 
 
278
#else
80
            __C(pVmrFilterConfig->SetRenderingMode(VMRMode_Windowless));
279
            __C(pVmrFilterConfig->SetRenderingMode(VMRMode_Windowless));
81
            m_pVmrWindowlessControl = CComQIPtr<IVMRWindowlessControl>(m_pBaseFilter);
280
            m_pVmrWindowlessControl = CComQIPtr<IVMRWindowlessControl>(m_pBaseFilter);
82
            __D(m_pVmrWindowlessControl, E_NOINTERFACE);
281
            __D(m_pVmrWindowlessControl, E_NOINTERFACE);
83
            __C(m_pVmrWindowlessControl->SetVideoClippingWindow(m_hWnd));
282
            __C(m_pVmrWindowlessControl->SetVideoClippingWindow(m_hWnd));
 
 
283
#endif
84
            CRect VideoPosition = GetVideoPosition();
284
            CRect VideoPosition = GetVideoPosition();
85
            _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());
285
            _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());
86
            __C(m_pVmrWindowlessControl->SetVideoPosition(NULL, VideoPosition));
286
            __C(m_pVmrWindowlessControl->SetVideoPosition(NULL, VideoPosition));
...
 
...
 
464
    }
664
    }
465
    LRESULT OnRunButtonClicked(UINT, INT, HWND)
665
    LRESULT OnRunButtonClicked(UINT, INT, HWND)
466
    {
666
    {
 
 
667
#if _DEVELOPMENT
 
 
668
        static BOOL g_bWindowPositionSet = FALSE;
 
 
669
        if(!g_bWindowPositionSet)
 
 
670
        {
 
 
671
            CRect MonitorPosition;
 
 
672
            _W(SystemParametersInfo(SPI_GETWORKAREA, 0, MonitorPosition, 0));
 
 
673
            _W(MoveWindow(MonitorPosition.left + MonitorPosition.Width() / 32, MonitorPosition.top + MonitorPosition.Height() / 32, MonitorPosition.Width() * 62
/ 32, MonitorPosition.Height() * 30 / 32));
 
 
674
            g_bWindowPositionSet = TRUE;
 
 
675
        }
 
 
676
#endif // _DEVELOPMENT
467
        CWaitCursor WaitCursor;
677
        CWaitCursor WaitCursor;
468
        __D(m_pMediaControl, E_NOINTERFACE);
678
        __D(m_pMediaControl, E_NOINTERFACE);
469
        __C(m_pMediaControl->Run());
679
        __C(m_pMediaControl->Run());
286287
125
//
125
//
126
 
126
 
127
VS_VERSION_INFO VERSIONINFO
127
VS_VERSION_INFO VERSIONINFO
128
 FILEVERSION  1, 0, 0, 129
128
 FILEVERSION  1, 0, 0, 163
129
 PRODUCTVERSION 1,0,0,1
129
 PRODUCTVERSION 1,0,0,1
130
 FILEFLAGSMASK 0x3fL
130
 FILEFLAGSMASK 0x3fL
131
#ifdef _DEBUG
131
#ifdef _DEBUG
...
 
...
 
144
            VALUE "CompanyName", "Alax.Info"
144
            VALUE "CompanyName", "Alax.Info"
145
            VALUE "Created By", "Roman Ryltsov <roman@alax.info>"
145
            VALUE "Created By", "Roman Ryltsov <roman@alax.info>"
146
            VALUE "FileDescription", "VMR-7 Custom Allocator-Presenter Sample Application"
146
            VALUE "FileDescription", "VMR-7 Custom Allocator-Presenter Sample Application"
147
            VALUE "FileVersion",  "1, 0, 0, 129\0"
147
            VALUE "FileVersion",  "1, 0, 0, 163\0"
148
            VALUE "InternalName", "VmrAllocatorPresenter"
148
            VALUE "InternalName", "VmrAllocatorPresenter"
149
            VALUE "LegalCopyright", "Copyright ゥ Alax.Info, Roman Ryltsov, 2008-2011"
149
            VALUE "LegalCopyright", "Copyright ゥ Alax.Info, Roman Ryltsov, 2008-2011"
150
            VALUE "OriginalFilename", "VmrAllocatorPresenter.exe"
150
            VALUE "OriginalFilename", "VmrAllocatorPresenter.exe"