hlink: Use an iface instead of a vtbl pointer in HlinkBCImpl.
[wine] / dlls / quartz / videorenderer.c
1 /*
2  * Video Renderer (Fullscreen and Windowed using Direct Draw)
3  *
4  * Copyright 2004 Christian Costa
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
25 #include "quartz_private.h"
26 #include "control_private.h"
27 #include "pin.h"
28
29 #include "uuids.h"
30 #include "vfwmsgs.h"
31 #include "amvideo.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "dshow.h"
35 #include "evcode.h"
36 #include "strmif.h"
37 #include "ddraw.h"
38 #include "dvdmedia.h"
39
40 #include <assert.h>
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45
46 static BOOL wnd_class_registered = FALSE;
47
48 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
49
50 static const IBaseFilterVtbl VideoRenderer_Vtbl;
51 static const IUnknownVtbl IInner_VTable;
52 static const IBasicVideoVtbl IBasicVideo_VTable;
53 static const IVideoWindowVtbl IVideoWindow_VTable;
54 static const IPinVtbl VideoRenderer_InputPin_Vtbl;
55 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl;
56 static const IQualityControlVtbl VideoRenderer_QualityControl_Vtbl = {
57     QualityControlImpl_QueryInterface,
58     QualityControlImpl_AddRef,
59     QualityControlImpl_Release,
60     QualityControlImpl_Notify,
61     QualityControlImpl_SetSink
62 };
63
64 typedef struct VideoRendererImpl
65 {
66     BaseFilter filter;
67     const IBasicVideoVtbl * IBasicVideo_vtbl;
68     const IVideoWindowVtbl * IVideoWindow_vtbl;
69     const IUnknownVtbl * IInner_vtbl;
70     const IAMFilterMiscFlagsVtbl *IAMFilterMiscFlags_vtbl;
71     IUnknown *seekthru_unk;
72     QualityControlImpl qcimpl;
73
74     BaseInputPin *pInputPin;
75
76     BOOL init;
77     HANDLE hThread;
78     HANDLE blocked;
79
80     DWORD ThreadID;
81     HANDLE hEvent;
82     BOOL ThreadResult;
83     HWND hWnd;
84     HWND hWndMsgDrain;
85     HWND hWndOwner;
86     BOOL AutoShow;
87     RECT SourceRect;
88     RECT DestRect;
89     RECT WindowPos;
90     LONG VideoWidth;
91     LONG VideoHeight;
92     IUnknown * pUnkOuter;
93     BOOL bUnkOuterValid;
94     BOOL bAggregatable;
95     LONG WindowStyle;
96
97     /* During pause we can hold a single sample, for use in GetCurrentImage */
98     IMediaSample *sample_held;
99 } VideoRendererImpl;
100
101 static LRESULT CALLBACK VideoWndProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
102 {
103     VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongPtrW(hwnd, 0);
104     LPRECT lprect = (LPRECT)lParam;
105
106     if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
107     {
108         switch(uMsg)
109         {
110             case WM_KEYDOWN:
111             case WM_KEYUP:
112             case WM_LBUTTONDBLCLK:
113             case WM_LBUTTONDOWN:
114             case WM_LBUTTONUP:
115             case WM_MBUTTONDBLCLK:
116             case WM_MBUTTONDOWN:
117             case WM_MBUTTONUP:
118             case WM_MOUSEACTIVATE:
119             case WM_MOUSEMOVE:
120             case WM_NCLBUTTONDBLCLK:
121             case WM_NCLBUTTONDOWN:
122             case WM_NCLBUTTONUP:
123             case WM_NCMBUTTONDBLCLK:
124             case WM_NCMBUTTONDOWN:
125             case WM_NCMBUTTONUP:
126             case WM_NCMOUSEMOVE:
127             case WM_NCRBUTTONDBLCLK:
128             case WM_NCRBUTTONDOWN:
129             case WM_NCRBUTTONUP:
130             case WM_RBUTTONDBLCLK:
131             case WM_RBUTTONDOWN:
132             case WM_RBUTTONUP:
133                 PostMessageW(pVideoRenderer->hWndMsgDrain, uMsg, wParam, lParam);
134                 break;
135             default:
136                 break;
137         }
138     }
139
140     switch(uMsg)
141     {
142         case WM_SIZING:
143             /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
144             SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
145             GetClientRect(hwnd, &pVideoRenderer->DestRect);
146             TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
147                 pVideoRenderer->DestRect.left,
148                 pVideoRenderer->DestRect.top,
149                 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
150                 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
151             return TRUE;
152         case WM_SIZE:
153             TRACE("WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
154             GetClientRect(hwnd, &pVideoRenderer->DestRect);
155             TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
156                 pVideoRenderer->DestRect.left,
157                 pVideoRenderer->DestRect.top,
158                 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
159                 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
160             return TRUE;
161         default:
162             return DefWindowProcW(hwnd, uMsg, wParam, lParam);
163     }
164     return 0;
165 }
166
167 static const WCHAR classnameW[] = { 'W','i','n','e',' ','A','c','t','i','v','e','M','o','v','i','e',' ','C','l','a','s','s',0 };
168 static const WCHAR windownameW[] = { 'A','c','t','i','v','e','M','o','v','i','e',' ','W','i','n','d','o','w',0 };
169
170 static BOOL video_register_windowclass(void) {
171     WNDCLASSW winclass;
172     if (wnd_class_registered)
173         return 1;
174
175     winclass.style = 0;
176     winclass.lpfnWndProc = VideoWndProcW;
177     winclass.cbClsExtra = 0;
178     winclass.cbWndExtra = sizeof(VideoRendererImpl*);
179     winclass.hInstance = NULL;
180     winclass.hIcon = NULL;
181     winclass.hCursor = NULL;
182     winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
183     winclass.lpszMenuName = NULL;
184     winclass.lpszClassName = classnameW;
185     if (!RegisterClassW(&winclass))
186     {
187         ERR("Unable to register window class: %u\n", GetLastError());
188         return FALSE;
189     }
190     wnd_class_registered = 1;
191     return 1;
192 }
193
194 void video_unregister_windowclass(void) {
195     if (!wnd_class_registered)
196         return;
197     UnregisterClassW(classnameW, NULL);
198 }
199
200 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
201 {
202     TRACE("(%p)->()\n", This);
203     if (!video_register_windowclass())
204         return FALSE;
205     This->hWnd = CreateWindowExW(0, classnameW, windownameW, WS_SIZEBOX,
206                                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
207                                  NULL, NULL, NULL);
208
209     if (!This->hWnd)
210     {
211         ERR("Unable to create window\n");
212         return FALSE;
213     }
214
215     SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
216
217     return TRUE;
218 }
219
220 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
221 {
222     VideoRendererImpl* This = lpParameter;
223     MSG msg; 
224     BOOL fGotMessage;
225
226     TRACE("Starting message loop\n");
227
228     if (!CreateRenderingWindow(This))
229     {
230         This->ThreadResult = FALSE;
231         SetEvent(This->hEvent);
232         return 0;
233     }
234
235     This->ThreadResult = TRUE;
236     SetEvent(This->hEvent);
237
238     while ((fGotMessage = GetMessageW(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
239     {
240         TranslateMessage(&msg); 
241         DispatchMessageW(&msg);
242     }
243
244     TRACE("End of message loop\n");
245
246     return msg.wParam;
247 }
248
249 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
250 {
251     This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
252     if (!This->hEvent)
253         return FALSE;
254
255     This->hThread = CreateThread(NULL, 0, MessageLoop, This, 0, &This->ThreadID);
256     if (!This->hThread)
257     {
258         CloseHandle(This->hEvent);
259         return FALSE;
260     }
261
262     WaitForSingleObject(This->hEvent, INFINITE);
263
264     if (!This->ThreadResult)
265     {
266         CloseHandle(This->hEvent);
267         CloseHandle(This->hThread);
268         return FALSE;
269     }
270
271     return TRUE;
272 }
273
274 static void VideoRenderer_AutoShowWindow(VideoRendererImpl *This) {
275     if (!This->init && (!This->WindowPos.right || !This->WindowPos.top))
276     {
277         DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
278         DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
279
280         if (!This->WindowPos.right)
281         {
282             This->WindowPos.left = This->SourceRect.left;
283             This->WindowPos.right = This->SourceRect.right;
284         }
285         if (!This->WindowPos.bottom)
286         {
287             This->WindowPos.top = This->SourceRect.top;
288             This->WindowPos.bottom = This->SourceRect.bottom;
289         }
290
291         AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);
292
293         TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
294         SetWindowPos(This->hWnd, NULL,
295             This->WindowPos.left,
296             This->WindowPos.top,
297             This->WindowPos.right - This->WindowPos.left,
298             This->WindowPos.bottom - This->WindowPos.top,
299             SWP_NOZORDER|SWP_NOMOVE|SWP_DEFERERASE);
300
301         GetClientRect(This->hWnd, &This->DestRect);
302     }
303     else if (!This->init)
304         This->DestRect = This->WindowPos;
305     This->init = TRUE;
306     if (This->AutoShow)
307         ShowWindow(This->hWnd, SW_SHOW);
308 }
309
310 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
311 {
312     AM_MEDIA_TYPE amt;
313     HRESULT hr = S_OK;
314     DDSURFACEDESC sdesc;
315     HDC hDC;
316     BITMAPINFOHEADER *bmiHeader;
317
318     TRACE("(%p)->(%p, %d)\n", This, data, size);
319
320     sdesc.dwSize = sizeof(sdesc);
321     hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
322     if (FAILED(hr)) {
323         ERR("Unable to retrieve media type\n");
324         return hr;
325     }
326
327     if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
328     {
329         bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
330     }
331     else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
332     {
333         bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
334     }
335     else
336     {
337         FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
338         return VFW_E_RUNTIME_ERROR;
339     }
340
341     TRACE("biSize = %d\n", bmiHeader->biSize);
342     TRACE("biWidth = %d\n", bmiHeader->biWidth);
343     TRACE("biHeight = %d\n", bmiHeader->biHeight);
344     TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
345     TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
346     TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
347     TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
348
349     hDC = GetDC(This->hWnd);
350
351     if (!hDC) {
352         ERR("Cannot get DC from window!\n");
353         return E_FAIL;
354     }
355
356     TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
357     TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
358
359     StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
360                   This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
361                   This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
362                   data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
363
364     ReleaseDC(This->hWnd, hDC);
365
366     return S_OK;
367 }
368
369 static HRESULT WINAPI VideoRenderer_Receive(BaseInputPin* pin, IMediaSample * pSample)
370 {
371     VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
372     LPBYTE pbSrcStream = NULL;
373     LONG cbSrcStream = 0;
374     REFERENCE_TIME tStart, tStop;
375     HRESULT hr;
376
377     TRACE("(%p)->(%p)\n", pin, pSample);
378
379     EnterCriticalSection(&This->filter.csFilter);
380
381     if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
382     {
383         LeaveCriticalSection(&This->filter.csFilter);
384         return S_FALSE;
385     }
386
387     if (This->filter.state == State_Stopped)
388     {
389         LeaveCriticalSection(&This->filter.csFilter);
390         return VFW_E_WRONG_STATE;
391     }
392
393     if (IMediaSample_GetMediaTime(pSample, &tStart, &tStop) == S_OK)
394         MediaSeekingPassThru_RegisterMediaTime(This->seekthru_unk, tStart);
395
396     /* Preroll means the sample isn't shown, this is used for key frames and things like that */
397     if (IMediaSample_IsPreroll(pSample) == S_OK) {
398         LeaveCriticalSection(&This->filter.csFilter);
399         return S_OK;
400     }
401
402     hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
403     if (FAILED(hr))
404     {
405         ERR("Cannot get pointer to sample data (%x)\n", hr);
406         LeaveCriticalSection(&This->filter.csFilter);
407         return hr;
408     }
409
410     cbSrcStream = IMediaSample_GetActualDataLength(pSample);
411
412     TRACE("val %p %d\n", pbSrcStream, cbSrcStream);
413
414 #if 0 /* For debugging purpose */
415     {
416         int i;
417         for(i = 0; i < cbSrcStream; i++)
418         {
419             if ((i!=0) && !(i%16))
420                 TRACE("\n");
421                 TRACE("%02x ", pbSrcStream[i]);
422         }
423         TRACE("\n");
424     }
425 #endif
426
427     SetEvent(This->hEvent);
428     if (This->filter.state == State_Paused)
429     {
430         VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
431         This->sample_held = pSample;
432         LeaveCriticalSection(&This->filter.csFilter);
433         WaitForSingleObject(This->blocked, INFINITE);
434         EnterCriticalSection(&This->filter.csFilter);
435         This->sample_held = NULL;
436         if (This->filter.state == State_Paused)
437         {
438             /* Flushing */
439             LeaveCriticalSection(&This->filter.csFilter);
440             return S_OK;
441         }
442         if (This->filter.state == State_Stopped)
443         {
444             LeaveCriticalSection(&This->filter.csFilter);
445             return VFW_E_WRONG_STATE;
446         }
447     } else {
448         hr = QualityControlRender_WaitFor(&This->qcimpl, pSample, This->blocked);
449         if (hr == S_OK) {
450             QualityControlRender_BeginRender(&This->qcimpl);
451             VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
452             QualityControlRender_EndRender(&This->qcimpl);
453         }
454         QualityControlRender_DoQOS(&This->qcimpl);
455     }
456     LeaveCriticalSection(&This->filter.csFilter);
457     return S_OK;
458 }
459
460 static HRESULT WINAPI VideoRenderer_CheckMediaType(BasePin *iface, const AM_MEDIA_TYPE * pmt)
461 {
462     BaseInputPin* pin = (BaseInputPin*)iface;
463     VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
464
465     if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
466         return S_FALSE;
467
468     if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
469         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
470         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
471         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
472     {
473         LONG height;
474
475         if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
476         {
477             VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
478             This->SourceRect.left = 0;
479             This->SourceRect.top = 0;
480             This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
481             height = format->bmiHeader.biHeight;
482             if (height < 0)
483                 This->SourceRect.bottom = This->VideoHeight = -height;
484             else
485                 This->SourceRect.bottom = This->VideoHeight = height;
486         }
487         else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
488         {
489             VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
490
491             This->SourceRect.left = 0;
492             This->SourceRect.top = 0;
493             This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
494             height = format2->bmiHeader.biHeight;
495             if (height < 0)
496                 This->SourceRect.bottom = This->VideoHeight = -height;
497             else
498                 This->SourceRect.bottom = This->VideoHeight = height;
499         }
500         else
501         {
502             WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
503             return S_FALSE;
504         }
505         return S_OK;
506     }
507     return S_FALSE;
508 }
509
510 static IPin* WINAPI VideoRenderer_GetPin(BaseFilter *iface, int pos)
511 {
512     VideoRendererImpl *This = (VideoRendererImpl *)iface;
513
514     if (pos >= 1 || pos < 0)
515         return NULL;
516
517     IPin_AddRef((IPin *)This->pInputPin);
518     return (IPin *)This->pInputPin;
519 }
520
521 static LONG WINAPI VideoRenderer_GetPinCount(BaseFilter *iface)
522 {
523     return 1;
524 }
525
526 static const BaseFilterFuncTable BaseFuncTable = {
527     VideoRenderer_GetPin,
528     VideoRenderer_GetPinCount
529 };
530
531 static const  BasePinFuncTable input_BaseFuncTable = {
532     VideoRenderer_CheckMediaType,
533     NULL,
534     BasePinImpl_GetMediaTypeVersion,
535     BasePinImpl_GetMediaType
536 };
537
538 static const BaseInputPinFuncTable input_BaseInputFuncTable = {
539     VideoRenderer_Receive
540 };
541
542 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
543 {
544     HRESULT hr;
545     PIN_INFO piInput;
546     VideoRendererImpl * pVideoRenderer;
547     ISeekingPassThru *passthru;
548
549     TRACE("(%p, %p)\n", pUnkOuter, ppv);
550
551     *ppv = NULL;
552
553     pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
554     pVideoRenderer->pUnkOuter = pUnkOuter;
555     pVideoRenderer->bUnkOuterValid = FALSE;
556     pVideoRenderer->bAggregatable = FALSE;
557     pVideoRenderer->IInner_vtbl = &IInner_VTable;
558     pVideoRenderer->IAMFilterMiscFlags_vtbl = &IAMFilterMiscFlags_Vtbl;
559
560     BaseFilter_Init(&pVideoRenderer->filter, &VideoRenderer_Vtbl, &CLSID_VideoRenderer, (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter"), &BaseFuncTable);
561
562     pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
563     pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
564
565     pVideoRenderer->init = 0;
566     pVideoRenderer->AutoShow = 1;
567     ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
568     ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
569     ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
570     pVideoRenderer->hWndMsgDrain = pVideoRenderer->hWndOwner = NULL;
571     pVideoRenderer->WindowStyle = WS_OVERLAPPED;
572
573     /* construct input pin */
574     piInput.dir = PINDIR_INPUT;
575     piInput.pFilter = (IBaseFilter *)pVideoRenderer;
576     lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
577
578     hr = BaseInputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, &input_BaseFuncTable, &input_BaseInputFuncTable, &pVideoRenderer->filter.csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
579
580     if (SUCCEEDED(hr))
581     {
582         hr = CoCreateInstance(&CLSID_SeekingPassThru, pUnkOuter ? pUnkOuter : (IUnknown*)&pVideoRenderer->IInner_vtbl, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&pVideoRenderer->seekthru_unk);
583         if (FAILED(hr)) {
584             IPin_Release((IPin*)pVideoRenderer->pInputPin);
585             goto fail;
586         }
587         IUnknown_QueryInterface(pVideoRenderer->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
588         ISeekingPassThru_Init(passthru, TRUE, (IPin*)pVideoRenderer->pInputPin);
589         ISeekingPassThru_Release(passthru);
590         pVideoRenderer->sample_held = NULL;
591         *ppv = pVideoRenderer;
592     }
593     if (FAILED(hr))
594         goto fail;
595
596     QualityControlImpl_init(&pVideoRenderer->qcimpl, (IPin*)pVideoRenderer->pInputPin, (IBaseFilter*)pVideoRenderer);
597     pVideoRenderer->qcimpl.lpVtbl = &VideoRenderer_QualityControl_Vtbl;
598
599     if (!CreateRenderingSubsystem(pVideoRenderer))
600         return E_FAIL;
601
602     pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
603     if (!pVideoRenderer->blocked)
604     {
605         hr = HRESULT_FROM_WIN32(GetLastError());
606         IUnknown_Release((IUnknown *)pVideoRenderer);
607     }
608
609     return hr;
610 fail:
611     BaseFilterImpl_Release((IBaseFilter*)pVideoRenderer);
612     CoTaskMemFree(pVideoRenderer);
613     return hr;
614 }
615
616 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
617 {
618     /* TODO: Attempt to use the VMR-7 renderer instead when possible */
619     return VideoRenderer_create(pUnkOuter, ppv);
620 }
621
622 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
623 {
624     ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
625     TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
626
627     if (This->bAggregatable)
628         This->bUnkOuterValid = TRUE;
629
630     *ppv = NULL;
631
632     if (IsEqualIID(riid, &IID_IUnknown))
633         *ppv = &This->IInner_vtbl;
634     else if (IsEqualIID(riid, &IID_IPersist))
635         *ppv = This;
636     else if (IsEqualIID(riid, &IID_IMediaFilter))
637         *ppv = This;
638     else if (IsEqualIID(riid, &IID_IBaseFilter))
639         *ppv = This;
640     else if (IsEqualIID(riid, &IID_IBasicVideo))
641         *ppv = &This->IBasicVideo_vtbl;
642     else if (IsEqualIID(riid, &IID_IVideoWindow))
643         *ppv = &This->IVideoWindow_vtbl;
644     else if (IsEqualIID(riid, &IID_IMediaSeeking))
645         return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
646     else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
647         *ppv = &This->IAMFilterMiscFlags_vtbl;
648     else if (IsEqualIID(riid, &IID_IQualityControl))
649         *ppv = &This->qcimpl;
650
651     if (*ppv)
652     {
653         IUnknown_AddRef((IUnknown *)(*ppv));
654         return S_OK;
655     }
656
657     if (!IsEqualIID(riid, &IID_IPin))
658         FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
659
660     return E_NOINTERFACE;
661 }
662
663 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
664 {
665     ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
666     ULONG refCount = InterlockedIncrement(&This->filter.refCount);
667
668     TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
669
670     return refCount;
671 }
672
673 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
674 {
675     ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
676     ULONG refCount = InterlockedDecrement(&This->filter.refCount);
677
678     TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
679
680     if (!refCount)
681     {
682         IPin *pConnectedTo;
683
684         if (This->hWnd)
685             SendMessageW(This->hWnd, WM_CLOSE, 0, 0);
686         PostThreadMessageW(This->ThreadID, WM_QUIT, 0, 0);
687         WaitForSingleObject(This->hThread, INFINITE);
688         CloseHandle(This->hThread);
689         CloseHandle(This->hEvent);
690
691         if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
692         {
693             IPin_Disconnect(pConnectedTo);
694             IPin_Release(pConnectedTo);
695         }
696         IPin_Disconnect((IPin *)This->pInputPin);
697
698         IPin_Release((IPin *)This->pInputPin);
699
700         This->filter.lpVtbl = NULL;
701         IUnknown_Release(This->seekthru_unk);
702         This->filter.csFilter.DebugInfo->Spare[0] = 0;
703         DeleteCriticalSection(&This->filter.csFilter);
704
705         TRACE("Destroying Video Renderer\n");
706         CoTaskMemFree(This);
707         
708         return 0;
709     }
710     else
711         return refCount;
712 }
713
714 static const IUnknownVtbl IInner_VTable =
715 {
716     VideoRendererInner_QueryInterface,
717     VideoRendererInner_AddRef,
718     VideoRendererInner_Release
719 };
720
721 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
722 {
723     VideoRendererImpl *This = (VideoRendererImpl *)iface;
724
725     if (This->bAggregatable)
726         This->bUnkOuterValid = TRUE;
727
728     if (This->pUnkOuter)
729     {
730         if (This->bAggregatable)
731             return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
732
733         if (IsEqualIID(riid, &IID_IUnknown))
734         {
735             HRESULT hr;
736
737             IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
738             hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
739             IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
740             This->bAggregatable = TRUE;
741             return hr;
742         }
743
744         *ppv = NULL;
745         return E_NOINTERFACE;
746     }
747
748     return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
749 }
750
751 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
752 {
753     VideoRendererImpl *This = (VideoRendererImpl *)iface;
754
755     if (This->pUnkOuter && This->bUnkOuterValid)
756         return IUnknown_AddRef(This->pUnkOuter);
757     return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
758 }
759
760 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
761 {
762     VideoRendererImpl *This = (VideoRendererImpl *)iface;
763
764     if (This->pUnkOuter && This->bUnkOuterValid)
765         return IUnknown_Release(This->pUnkOuter);
766     return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
767 }
768
769 /** IMediaFilter methods **/
770
771 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
772 {
773     VideoRendererImpl *This = (VideoRendererImpl *)iface;
774
775     TRACE("(%p/%p)->()\n", This, iface);
776
777     EnterCriticalSection(&This->filter.csFilter);
778     {
779         This->filter.state = State_Stopped;
780         SetEvent(This->hEvent);
781         SetEvent(This->blocked);
782         MediaSeekingPassThru_ResetMediaTime(This->seekthru_unk);
783         if (This->AutoShow)
784             /* Black it out */
785             RedrawWindow(This->hWnd, NULL, NULL, RDW_INVALIDATE|RDW_ERASE);
786     }
787     LeaveCriticalSection(&This->filter.csFilter);
788
789     return S_OK;
790 }
791
792 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
793 {
794     VideoRendererImpl *This = (VideoRendererImpl *)iface;
795     
796     TRACE("(%p/%p)->()\n", This, iface);
797
798     EnterCriticalSection(&This->filter.csFilter);
799     if (This->filter.state != State_Paused)
800     {
801         if (This->filter.state == State_Stopped)
802         {
803             This->pInputPin->end_of_stream = 0;
804             ResetEvent(This->hEvent);
805             VideoRenderer_AutoShowWindow(This);
806         }
807
808         This->filter.state = State_Paused;
809         ResetEvent(This->blocked);
810     }
811     LeaveCriticalSection(&This->filter.csFilter);
812
813     return S_OK;
814 }
815
816 static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter *iface, IReferenceClock *clock) {
817     VideoRendererImpl *This = (VideoRendererImpl *)iface;
818     HRESULT hr;
819
820     EnterCriticalSection(&This->filter.csFilter);
821     QualityControlRender_SetClock(&This->qcimpl, clock);
822     hr = BaseFilterImpl_SetSyncSource(iface, clock);
823     LeaveCriticalSection(&This->filter.csFilter);
824     return hr;
825 }
826
827 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
828 {
829     HRESULT hr = S_OK;
830     VideoRendererImpl *This = (VideoRendererImpl *)iface;
831
832     TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
833
834     EnterCriticalSection(&This->filter.csFilter);
835     if (This->filter.state == State_Running)
836         goto out;
837     This->filter.rtStreamStart = tStart;
838     QualityControlRender_Start(&This->qcimpl, tStart);
839     if (This->pInputPin->pin.pConnectedTo && (This->filter.state == State_Stopped || !This->pInputPin->end_of_stream))
840     {
841         if (This->filter.state == State_Stopped)
842         {
843             ResetEvent(This->hEvent);
844             VideoRenderer_AutoShowWindow(This);
845             This->pInputPin->end_of_stream = 0;
846         }
847         SetEvent(This->blocked);
848     } else if (This->filter.filterInfo.pGraph) {
849         IMediaEventSink *pEventSink;
850         hr = IFilterGraph_QueryInterface(This->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
851         if (SUCCEEDED(hr))
852         {
853             hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)This);
854             IMediaEventSink_Release(pEventSink);
855         }
856         hr = S_OK;
857     }
858     if (SUCCEEDED(hr))
859         This->filter.state = State_Running;
860 out:
861     LeaveCriticalSection(&This->filter.csFilter);
862
863     return hr;
864 }
865
866 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
867 {
868     VideoRendererImpl *This = (VideoRendererImpl *)iface;
869     HRESULT hr;
870
871     TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
872
873     if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
874         hr = VFW_S_STATE_INTERMEDIATE;
875     else
876         hr = S_OK;
877
878     BaseFilterImpl_GetState(iface, dwMilliSecsTimeout, pState);
879
880     return hr;
881 }
882
883 /** IBaseFilter implementation **/
884
885 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
886 {
887     VideoRendererImpl *This = (VideoRendererImpl *)iface;
888
889     FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
890
891     /* FIXME: critical section */
892
893     return E_NOTIMPL;
894 }
895
896 static const IBaseFilterVtbl VideoRenderer_Vtbl =
897 {
898     VideoRenderer_QueryInterface,
899     VideoRenderer_AddRef,
900     VideoRenderer_Release,
901     BaseFilterImpl_GetClassID,
902     VideoRenderer_Stop,
903     VideoRenderer_Pause,
904     VideoRenderer_Run,
905     VideoRenderer_GetState,
906     VideoRenderer_SetSyncSource,
907     BaseFilterImpl_GetSyncSource,
908     BaseFilterImpl_EnumPins,
909     VideoRenderer_FindPin,
910     BaseFilterImpl_QueryFilterInfo,
911     BaseFilterImpl_JoinFilterGraph,
912     BaseFilterImpl_QueryVendorInfo
913 };
914
915 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
916 {
917     BaseInputPin* This = (BaseInputPin*)iface;
918     VideoRendererImpl *pFilter;
919     IMediaEventSink* pEventSink;
920     HRESULT hr = S_OK;
921
922     TRACE("(%p/%p)->()\n", This, iface);
923
924     EnterCriticalSection(This->pin.pCritSec);
925     pFilter = (VideoRendererImpl*)This->pin.pinInfo.pFilter;
926     if (This->flushing || This->end_of_stream)
927         goto out;
928     hr = IFilterGraph_QueryInterface(pFilter->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
929     if (SUCCEEDED(hr))
930     {
931         hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)pFilter);
932         IMediaEventSink_Release(pEventSink);
933     }
934     MediaSeekingPassThru_EOS(pFilter->seekthru_unk);
935     This->end_of_stream = 1;
936 out:
937     LeaveCriticalSection(This->pin.pCritSec);
938
939     return hr;
940 }
941
942 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
943 {
944     BaseInputPin* This = (BaseInputPin*)iface;
945     VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
946
947     TRACE("(%p/%p)->()\n", This, iface);
948
949     SetEvent(pVideoRenderer->blocked);
950     return BaseInputPinImpl_BeginFlush(iface);
951 }
952
953 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
954 {
955     BaseInputPin* This = (BaseInputPin*)iface;
956     VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
957     HRESULT hr;
958
959     TRACE("(%p/%p)->()\n", This, iface);
960
961     EnterCriticalSection(This->pin.pCritSec);
962     if (pVideoRenderer->filter.state == State_Paused) {
963         ResetEvent(pVideoRenderer->blocked);
964         ResetEvent(pVideoRenderer->hEvent);
965     }
966
967     QualityControlRender_Start(&pVideoRenderer->qcimpl, pVideoRenderer->filter.rtStreamStart);
968     hr = BaseInputPinImpl_EndFlush(iface);
969     LeaveCriticalSection(This->pin.pCritSec);
970     MediaSeekingPassThru_ResetMediaTime(pVideoRenderer->seekthru_unk);
971
972     return hr;
973 }
974
975 static const IPinVtbl VideoRenderer_InputPin_Vtbl = 
976 {
977     BaseInputPinImpl_QueryInterface,
978     BasePinImpl_AddRef,
979     BaseInputPinImpl_Release,
980     BaseInputPinImpl_Connect,
981     BaseInputPinImpl_ReceiveConnection,
982     BasePinImpl_Disconnect,
983     BasePinImpl_ConnectedTo,
984     BasePinImpl_ConnectionMediaType,
985     BasePinImpl_QueryPinInfo,
986     BasePinImpl_QueryDirection,
987     BasePinImpl_QueryId,
988     BaseInputPinImpl_QueryAccept,
989     BasePinImpl_EnumMediaTypes,
990     BasePinImpl_QueryInternalConnections,
991     VideoRenderer_InputPin_EndOfStream,
992     VideoRenderer_InputPin_BeginFlush,
993     VideoRenderer_InputPin_EndFlush,
994     BaseInputPinImpl_NewSegment
995 };
996
997 /*** IUnknown methods ***/
998 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
999                                                 REFIID riid,
1000                                                 LPVOID*ppvObj) {
1001     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1002
1003     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1004
1005     return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1006 }
1007
1008 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1009     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1010
1011     TRACE("(%p/%p)->()\n", This, iface);
1012
1013     return VideoRenderer_AddRef((IBaseFilter*)This);
1014 }
1015
1016 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1017     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1018
1019     TRACE("(%p/%p)->()\n", This, iface);
1020
1021     return VideoRenderer_Release((IBaseFilter*)This);
1022 }
1023
1024 /*** IDispatch methods ***/
1025 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1026                                                   UINT*pctinfo) {
1027     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1028
1029     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1030
1031     return S_OK;
1032 }
1033
1034 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1035                                              UINT iTInfo,
1036                                              LCID lcid,
1037                                              ITypeInfo**ppTInfo) {
1038     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1039
1040     FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1041
1042     return S_OK;
1043 }
1044
1045 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1046                                                REFIID riid,
1047                                                LPOLESTR*rgszNames,
1048                                                UINT cNames,
1049                                                LCID lcid,
1050                                                DISPID*rgDispId) {
1051     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1052
1053     FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1054
1055     return S_OK;
1056 }
1057
1058 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1059                                         DISPID dispIdMember,
1060                                         REFIID riid,
1061                                         LCID lcid,
1062                                         WORD wFlags,
1063                                         DISPPARAMS*pDispParams,
1064                                         VARIANT*pVarResult,
1065                                         EXCEPINFO*pExepInfo,
1066                                         UINT*puArgErr) {
1067     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1068
1069     FIXME("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1070
1071     return S_OK;
1072 }
1073
1074 /*** IBasicVideo methods ***/
1075 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1076                                                      REFTIME *pAvgTimePerFrame) {
1077     AM_MEDIA_TYPE *pmt;
1078     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1079
1080     if (!This->pInputPin->pin.pConnectedTo)
1081         return VFW_E_NOT_CONNECTED;
1082
1083     TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
1084
1085     pmt = &This->pInputPin->pin.mtCurrent;
1086     if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
1087         VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)pmt->pbFormat;
1088         *pAvgTimePerFrame = vih->AvgTimePerFrame;
1089     } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
1090         VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)pmt->pbFormat;
1091         *pAvgTimePerFrame = vih->AvgTimePerFrame;
1092     } else {
1093         ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
1094         *pAvgTimePerFrame = 0;
1095     }
1096     return S_OK;
1097 }
1098
1099 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1100                                              LONG *pBitRate) {
1101     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1102
1103     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1104
1105     return S_OK;
1106 }
1107
1108 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1109                                                   LONG *pBitErrorRate) {
1110     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1111
1112     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1113
1114     return S_OK;
1115 }
1116
1117 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1118                                                 LONG *pVideoWidth) {
1119     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1120
1121     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1122
1123     *pVideoWidth = This->VideoWidth;
1124
1125     return S_OK;
1126 }
1127
1128 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1129                                                  LONG *pVideoHeight) {
1130     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1131
1132     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1133
1134     *pVideoHeight = This->VideoHeight;
1135
1136     return S_OK;
1137 }
1138
1139 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1140                                                 LONG SourceLeft) {
1141     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1142
1143     TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
1144
1145     This->SourceRect.left = SourceLeft;
1146
1147     return S_OK;
1148 }
1149
1150 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1151                                                 LONG *pSourceLeft) {
1152     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1153
1154     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1155
1156     *pSourceLeft = This->SourceRect.left;
1157
1158     return S_OK;
1159 }
1160
1161 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1162                                                  LONG SourceWidth) {
1163     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1164
1165     TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
1166
1167     This->SourceRect.right = This->SourceRect.left + SourceWidth;
1168
1169     return S_OK;
1170 }
1171
1172 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1173                                                  LONG *pSourceWidth) {
1174     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1175
1176     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1177
1178     *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1179     
1180     return S_OK;
1181 }
1182
1183 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1184                                                LONG SourceTop) {
1185     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1186
1187     TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
1188
1189     This->SourceRect.top = SourceTop;
1190
1191     return S_OK;
1192 }
1193
1194 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1195                                                LONG *pSourceTop) {
1196     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1197
1198     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1199
1200     *pSourceTop = This->SourceRect.top;
1201
1202     return S_OK;
1203 }
1204
1205 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1206                                                   LONG SourceHeight) {
1207     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1208
1209     TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
1210
1211     This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1212
1213     return S_OK;
1214 }
1215
1216 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1217                                                   LONG *pSourceHeight) {
1218     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1219
1220     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1221
1222     *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1223
1224     return S_OK;
1225 }
1226
1227 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1228                                                      LONG DestinationLeft) {
1229     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1230
1231     TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
1232
1233     This->DestRect.left = DestinationLeft;
1234
1235     return S_OK;
1236 }
1237
1238 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1239                                                      LONG *pDestinationLeft) {
1240     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1241
1242     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1243
1244     *pDestinationLeft = This->DestRect.left;
1245
1246     return S_OK;
1247 }
1248
1249 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1250                                                       LONG DestinationWidth) {
1251     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1252
1253     TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
1254
1255     This->DestRect.right = This->DestRect.left + DestinationWidth;
1256
1257     return S_OK;
1258 }
1259
1260 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1261                                                       LONG *pDestinationWidth) {
1262     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1263
1264     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1265
1266     *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1267
1268     return S_OK;
1269 }
1270
1271 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1272                                                     LONG DestinationTop) {
1273     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1274
1275     TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
1276
1277     This->DestRect.top = DestinationTop;
1278     
1279     return S_OK;
1280 }
1281
1282 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1283                                                     LONG *pDestinationTop) {
1284     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1285
1286     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1287
1288     *pDestinationTop = This->DestRect.top;
1289
1290     return S_OK;
1291 }
1292
1293 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1294                                                        LONG DestinationHeight) {
1295     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1296
1297     TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
1298
1299     This->DestRect.right = This->DestRect.left + DestinationHeight;
1300
1301     return S_OK;
1302 }
1303
1304 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1305                                                        LONG *pDestinationHeight) {
1306     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1307
1308     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1309
1310     *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1311
1312     return S_OK;
1313 }
1314
1315 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1316                                                    LONG Left,
1317                                                    LONG Top,
1318                                                    LONG Width,
1319                                                    LONG Height) {
1320     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1321
1322     TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1323
1324     This->SourceRect.left = Left;
1325     This->SourceRect.top = Top;
1326     This->SourceRect.right = Left + Width;
1327     This->SourceRect.bottom = Top + Height;
1328     
1329     return S_OK;
1330 }
1331
1332 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1333                                                    LONG *pLeft,
1334                                                    LONG *pTop,
1335                                                    LONG *pWidth,
1336                                                    LONG *pHeight) {
1337     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1338
1339     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1340
1341     *pLeft = This->SourceRect.left;
1342     *pTop = This->SourceRect.top;
1343     *pWidth = This->SourceRect.right - This->SourceRect.left;
1344     *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1345     
1346     return S_OK;
1347 }
1348
1349 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1350     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1351
1352     TRACE("(%p/%p)->()\n", This, iface);
1353
1354     This->SourceRect.left = 0;
1355     This->SourceRect.top = 0;
1356     This->SourceRect.right = This->VideoWidth;
1357     This->SourceRect.bottom = This->VideoHeight;
1358
1359     return S_OK;
1360 }
1361
1362 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1363                                                         LONG Left,
1364                                                         LONG Top,
1365                                                         LONG Width,
1366                                                         LONG Height) {
1367     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1368
1369     TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1370
1371     This->DestRect.left = Left;
1372     This->DestRect.top = Top;
1373     This->DestRect.right = Left + Width;
1374     This->DestRect.bottom = Top + Height;
1375
1376     return S_OK;
1377 }
1378
1379 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1380                                                         LONG *pLeft,
1381                                                         LONG *pTop,
1382                                                         LONG *pWidth,
1383                                                         LONG *pHeight) {
1384     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1385
1386     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1387
1388     *pLeft = This->DestRect.left;
1389     *pTop = This->DestRect.top;
1390     *pWidth = This->DestRect.right - This->DestRect.left;
1391     *pHeight = This->DestRect.bottom - This->DestRect.top;
1392
1393     return S_OK;
1394 }
1395
1396 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1397     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1398     RECT rect;
1399
1400     TRACE("(%p/%p)->()\n", This, iface);
1401
1402     if (!GetClientRect(This->hWnd, &rect))
1403         return E_FAIL;
1404     
1405     This->SourceRect.left = 0;
1406     This->SourceRect.top = 0;
1407     This->SourceRect.right = rect.right;
1408     This->SourceRect.bottom = rect.bottom;
1409     
1410     return S_OK;
1411 }
1412
1413 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1414                                               LONG *pWidth,
1415                                               LONG *pHeight) {
1416     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1417
1418     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1419
1420     *pWidth = This->VideoWidth;
1421     *pHeight = This->VideoHeight;
1422     
1423     return S_OK;
1424 }
1425
1426 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1427                                                         LONG StartIndex,
1428                                                         LONG Entries,
1429                                                         LONG *pRetrieved,
1430                                                         LONG *pPalette) {
1431     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1432
1433     TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1434
1435     if (pRetrieved)
1436         *pRetrieved = 0;
1437     return VFW_E_NO_PALETTE_AVAILABLE;
1438 }
1439
1440 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1441                                                  LONG *pBufferSize,
1442                                                  LONG *pDIBImage) {
1443     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1444     BITMAPINFOHEADER *bmiHeader;
1445     LONG needed_size;
1446     AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1447     char *ptr;
1448
1449     FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1450
1451     EnterCriticalSection(&This->filter.csFilter);
1452
1453     if (!This->sample_held)
1454     {
1455          LeaveCriticalSection(&This->filter.csFilter);
1456          return (This->filter.state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1457     }
1458
1459     if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1460     {
1461         bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1462     }
1463     else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1464     {
1465         bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1466     }
1467     else
1468     {
1469         FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1470         LeaveCriticalSection(&This->filter.csFilter);
1471         return VFW_E_RUNTIME_ERROR;
1472     }
1473
1474     needed_size = bmiHeader->biSize;
1475     needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1476
1477     if (!pDIBImage)
1478     {
1479         *pBufferSize = needed_size;
1480         LeaveCriticalSection(&This->filter.csFilter);
1481         return S_OK;
1482     }
1483
1484     if (needed_size < *pBufferSize)
1485     {
1486         ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
1487         LeaveCriticalSection(&This->filter.csFilter);
1488         return E_FAIL;
1489     }
1490     *pBufferSize = needed_size;
1491
1492     memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1493     IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1494     memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1495
1496     LeaveCriticalSection(&This->filter.csFilter);
1497
1498     return S_OK;
1499 }
1500
1501 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1502     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1503
1504     FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1505
1506     return S_OK;
1507 }
1508
1509 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1510     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1511
1512     FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1513
1514     return S_OK;
1515 }
1516
1517
1518 static const IBasicVideoVtbl IBasicVideo_VTable =
1519 {
1520     Basicvideo_QueryInterface,
1521     Basicvideo_AddRef,
1522     Basicvideo_Release,
1523     Basicvideo_GetTypeInfoCount,
1524     Basicvideo_GetTypeInfo,
1525     Basicvideo_GetIDsOfNames,
1526     Basicvideo_Invoke,
1527     Basicvideo_get_AvgTimePerFrame,
1528     Basicvideo_get_BitRate,
1529     Basicvideo_get_BitErrorRate,
1530     Basicvideo_get_VideoWidth,
1531     Basicvideo_get_VideoHeight,
1532     Basicvideo_put_SourceLeft,
1533     Basicvideo_get_SourceLeft,
1534     Basicvideo_put_SourceWidth,
1535     Basicvideo_get_SourceWidth,
1536     Basicvideo_put_SourceTop,
1537     Basicvideo_get_SourceTop,
1538     Basicvideo_put_SourceHeight,
1539     Basicvideo_get_SourceHeight,
1540     Basicvideo_put_DestinationLeft,
1541     Basicvideo_get_DestinationLeft,
1542     Basicvideo_put_DestinationWidth,
1543     Basicvideo_get_DestinationWidth,
1544     Basicvideo_put_DestinationTop,
1545     Basicvideo_get_DestinationTop,
1546     Basicvideo_put_DestinationHeight,
1547     Basicvideo_get_DestinationHeight,
1548     Basicvideo_SetSourcePosition,
1549     Basicvideo_GetSourcePosition,
1550     Basicvideo_SetDefaultSourcePosition,
1551     Basicvideo_SetDestinationPosition,
1552     Basicvideo_GetDestinationPosition,
1553     Basicvideo_SetDefaultDestinationPosition,
1554     Basicvideo_GetVideoSize,
1555     Basicvideo_GetVideoPaletteEntries,
1556     Basicvideo_GetCurrentImage,
1557     Basicvideo_IsUsingDefaultSource,
1558     Basicvideo_IsUsingDefaultDestination
1559 };
1560
1561
1562 /*** IUnknown methods ***/
1563 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1564                                                  REFIID riid,
1565                                                  LPVOID*ppvObj) {
1566     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1567
1568     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1569
1570     return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1571 }
1572
1573 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1574     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1575
1576     TRACE("(%p/%p)->()\n", This, iface);
1577
1578     return VideoRenderer_AddRef((IBaseFilter*)This);
1579 }
1580
1581 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1582     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1583
1584     TRACE("(%p/%p)->()\n", This, iface);
1585
1586     return VideoRenderer_Release((IBaseFilter*)This);
1587 }
1588
1589 /*** IDispatch methods ***/
1590 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1591                                                    UINT*pctinfo) {
1592     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1593
1594     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1595
1596     return S_OK;
1597 }
1598
1599 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1600                                               UINT iTInfo,
1601                                               LCID lcid,
1602                                               ITypeInfo**ppTInfo) {
1603     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1604
1605     FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1606
1607     return S_OK;
1608 }
1609
1610 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1611                                                 REFIID riid,
1612                                                 LPOLESTR*rgszNames,
1613                                                 UINT cNames,
1614                                                 LCID lcid,
1615                                                 DISPID*rgDispId) {
1616     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1617
1618     FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1619
1620     return S_OK;
1621 }
1622
1623 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1624                                          DISPID dispIdMember,
1625                                          REFIID riid,
1626                                          LCID lcid,
1627                                          WORD wFlags,
1628                                          DISPPARAMS*pDispParams,
1629                                          VARIANT*pVarResult,
1630                                          EXCEPINFO*pExepInfo,
1631                                          UINT*puArgErr) {
1632     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1633
1634     FIXME("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1635
1636     return S_OK;
1637 }
1638
1639 /*** IVideoWindow methods ***/
1640 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1641                                               BSTR strCaption) {
1642     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1643
1644     TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1645
1646     if (!SetWindowTextW(This->hWnd, strCaption))
1647         return E_FAIL;
1648
1649     return S_OK;
1650 }
1651
1652 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1653                                               BSTR *strCaption) {
1654     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1655
1656     TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1657
1658     GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1659
1660     return S_OK;
1661 }
1662
1663 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1664                                                   LONG WindowStyle) {
1665     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1666     LONG old;
1667
1668     old = GetWindowLongW(This->hWnd, GWL_STYLE);
1669
1670     TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
1671
1672     if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1673         return E_INVALIDARG;
1674
1675     SetWindowLongW(This->hWnd, GWL_STYLE, WindowStyle);
1676     SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1677     This->WindowStyle = WindowStyle;
1678
1679     return S_OK;
1680 }
1681
1682 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1683                                                   LONG *WindowStyle) {
1684     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1685
1686     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1687
1688     *WindowStyle = This->WindowStyle;
1689
1690     return S_OK;
1691 }
1692
1693 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1694                                                     LONG WindowStyleEx) {
1695     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1696
1697     TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
1698
1699     if (!SetWindowLongW(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1700         return E_FAIL;
1701
1702     return S_OK;
1703 }
1704
1705 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1706                                                     LONG *WindowStyleEx) {
1707     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1708
1709     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1710
1711     *WindowStyleEx = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
1712
1713     return S_OK;
1714 }
1715
1716 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1717                                                LONG AutoShow) {
1718     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1719
1720     TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
1721
1722     This->AutoShow = AutoShow;
1723
1724     return S_OK;
1725 }
1726
1727 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1728                                                LONG *AutoShow) {
1729     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1730
1731     TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1732
1733     *AutoShow = This->AutoShow;
1734
1735     return S_OK;
1736 }
1737
1738 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1739                                                   LONG WindowState) {
1740     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1741
1742     TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
1743     ShowWindow(This->hWnd, WindowState);
1744     return S_OK;
1745 }
1746
1747 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1748                                                   LONG *WindowState) {
1749     WINDOWPLACEMENT place;
1750     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1751
1752     place.length = sizeof(place);
1753     GetWindowPlacement(This->hWnd, &place);
1754     TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
1755     *WindowState = place.showCmd;
1756
1757     return S_OK;
1758 }
1759
1760 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1761                                                         LONG BackgroundPalette) {
1762     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1763
1764     FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
1765
1766     return S_OK;
1767 }
1768
1769 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1770                                                         LONG *pBackgroundPalette) {
1771     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1772
1773     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1774
1775     return S_OK;
1776 }
1777
1778 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1779                                               LONG Visible) {
1780     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1781
1782     TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
1783
1784     ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1785
1786     return S_OK;
1787 }
1788
1789 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1790                                               LONG *pVisible) {
1791     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1792
1793     TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1794
1795     *pVisible = IsWindowVisible(This->hWnd);
1796
1797     return S_OK;
1798 }
1799
1800 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1801                                            LONG Left) {
1802     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1803
1804     TRACE("(%p/%p)->(%d)\n", This, iface, Left);
1805
1806     if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1807         return E_FAIL;
1808
1809     This->WindowPos.left = Left;
1810
1811     return S_OK;
1812 }
1813
1814 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1815                                            LONG *pLeft) {
1816     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1817
1818     TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1819
1820     *pLeft = This->WindowPos.left;
1821
1822     return S_OK;
1823 }
1824
1825 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1826                                             LONG Width) {
1827     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1828
1829     TRACE("(%p/%p)->(%d)\n", This, iface, Width);
1830
1831     if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1832         return E_FAIL;
1833
1834     This->WindowPos.right = This->WindowPos.left + Width;
1835
1836     return S_OK;
1837 }
1838
1839 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1840                                             LONG *pWidth) {
1841     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1842
1843     TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1844
1845     *pWidth = This->WindowPos.right - This->WindowPos.left;
1846
1847     return S_OK;
1848 }
1849
1850 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1851                                           LONG Top) {
1852     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1853
1854     TRACE("(%p/%p)->(%d)\n", This, iface, Top);
1855
1856     if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1857         return E_FAIL;
1858
1859     This->WindowPos.top = Top;
1860
1861     return S_OK;
1862 }
1863
1864 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1865                                           LONG *pTop) {
1866     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1867
1868     TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1869
1870     *pTop = This->WindowPos.top;
1871
1872     return S_OK;
1873 }
1874
1875 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1876                                              LONG Height) {
1877     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1878
1879     TRACE("(%p/%p)->(%d)\n", This, iface, Height);
1880
1881     if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1882         return E_FAIL;
1883
1884     This->WindowPos.bottom = This->WindowPos.top + Height;
1885
1886     return S_OK;
1887 }
1888
1889 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1890                                              LONG *pHeight) {
1891     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1892
1893     TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1894
1895     *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1896
1897     return S_OK;
1898 }
1899
1900 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1901                                             OAHWND Owner) {
1902     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1903
1904     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1905
1906     This->hWndOwner = (HWND)Owner;
1907     SetParent(This->hWnd, This->hWndOwner);
1908     if (This->WindowStyle & WS_CHILD)
1909     {
1910         LONG old = GetWindowLongW(This->hWnd, GWL_STYLE);
1911         if (old != This->WindowStyle)
1912         {
1913             SetWindowLongW(This->hWnd, GWL_STYLE, This->WindowStyle);
1914             SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1915         }
1916     }
1917
1918     return S_OK;
1919 }
1920
1921 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
1922                                             OAHWND *Owner) {
1923     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1924
1925     TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
1926
1927     *(HWND*)Owner = This->hWndOwner;
1928
1929     return S_OK;
1930 }
1931
1932 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
1933                                                    OAHWND Drain) {
1934     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1935
1936     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
1937
1938     This->hWndMsgDrain = (HWND)Drain;
1939
1940     return S_OK;
1941 }
1942
1943 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
1944                                                    OAHWND *Drain) {
1945     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1946
1947     TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
1948
1949     *Drain = (OAHWND)This->hWndMsgDrain;
1950
1951     return S_OK;
1952 }
1953
1954 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
1955                                                   LONG *Color) {
1956     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1957
1958     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
1959
1960     return S_OK;
1961 }
1962
1963 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
1964                                                   LONG Color) {
1965     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1966
1967     FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
1968
1969     return S_OK;
1970 }
1971
1972 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
1973                                                      LONG *FullScreenMode) {
1974     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1975
1976     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
1977
1978     return S_OK;
1979 }
1980
1981 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
1982                                                      LONG FullScreenMode) {
1983     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1984
1985     FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
1986
1987     if (FullScreenMode) {
1988         ShowWindow(This->hWnd, SW_HIDE);
1989         SetParent(This->hWnd, 0);
1990         SetWindowLongW(This->hWnd, GWL_STYLE, WS_POPUP);
1991         SetWindowPos(This->hWnd,HWND_TOP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SWP_SHOWWINDOW);
1992         GetWindowRect(This->hWnd, &This->DestRect);
1993         This->WindowPos = This->DestRect;
1994     } else {
1995         ShowWindow(This->hWnd, SW_HIDE);
1996         SetParent(This->hWnd, This->hWndOwner);
1997         SetWindowLongW(This->hWnd, GWL_STYLE, This->WindowStyle);
1998         GetClientRect(This->hWnd, &This->DestRect);
1999         SetWindowPos(This->hWnd,0,This->DestRect.left,This->DestRect.top,This->DestRect.right,This->DestRect.bottom,SWP_NOZORDER|SWP_SHOWWINDOW);
2000         This->WindowPos = This->DestRect;
2001     }
2002
2003     return S_OK;
2004 }
2005
2006 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2007                                                       LONG Focus) {
2008     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2009     BOOL ret;
2010     IPin* pPin;
2011     HRESULT hr;
2012
2013     TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
2014
2015     if ((Focus != FALSE) && (Focus != TRUE))
2016         return E_INVALIDARG;
2017
2018     hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2019     if ((hr != S_OK) || !pPin)
2020         return VFW_E_NOT_CONNECTED;
2021
2022     if (Focus)
2023         ret = SetForegroundWindow(This->hWnd);
2024     else
2025         ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2026
2027     if (!ret)
2028         return E_FAIL;
2029
2030     return S_OK;
2031 }
2032
2033 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2034                                                      OAHWND hwnd,
2035                                                      LONG uMsg,
2036                                                      LONG_PTR wParam,
2037                                                      LONG_PTR lParam) {
2038     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2039
2040     TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
2041
2042     if (!PostMessageW(This->hWnd, uMsg, wParam, lParam))
2043         return E_FAIL;
2044     
2045     return S_OK;
2046 }
2047
2048 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2049                                                     LONG Left,
2050                                                     LONG Top,
2051                                                     LONG Width,
2052                                                     LONG Height) {
2053     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2054
2055     TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
2056
2057     if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2058         return E_FAIL;
2059
2060     This->WindowPos.left = Left;
2061     This->WindowPos.top = Top;
2062     This->WindowPos.right = Left + Width;
2063     This->WindowPos.bottom = Top + Height;
2064     
2065     return S_OK;
2066 }
2067
2068 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2069                                                     LONG *pLeft,
2070                                                     LONG *pTop,
2071                                                     LONG *pWidth,
2072                                                     LONG *pHeight) {
2073     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2074
2075     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2076
2077     *pLeft = This->WindowPos.left;
2078     *pTop = This->WindowPos.top;
2079     *pWidth = This->WindowPos.right - This->WindowPos.left;
2080     *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2081
2082     return S_OK;
2083 }
2084
2085 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2086                                                        LONG *pWidth,
2087                                                        LONG *pHeight) {
2088     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2089
2090     FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2091
2092     *pWidth = This->VideoWidth;
2093     *pHeight = This->VideoHeight;
2094
2095     return S_OK;
2096 }
2097
2098 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2099                                                        LONG *pWidth,
2100                                                        LONG *pHeight) {
2101     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2102
2103     FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2104
2105     *pWidth = This->VideoWidth;
2106     *pHeight = This->VideoHeight;
2107
2108     return S_OK;
2109 }
2110
2111 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2112                                                      LONG *pLeft,
2113                                                      LONG *pTop,
2114                                                      LONG *pWidth,
2115                                                      LONG *pHeight) {
2116     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2117
2118     FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2119
2120     return S_OK;
2121 }
2122
2123 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2124                                              LONG HideCursor) {
2125     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2126
2127     FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
2128
2129     return S_OK;
2130 }
2131
2132 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2133                                                  LONG *CursorHidden) {
2134     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2135
2136     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2137
2138     return S_OK;
2139 }
2140
2141 static const IVideoWindowVtbl IVideoWindow_VTable =
2142 {
2143     Videowindow_QueryInterface,
2144     Videowindow_AddRef,
2145     Videowindow_Release,
2146     Videowindow_GetTypeInfoCount,
2147     Videowindow_GetTypeInfo,
2148     Videowindow_GetIDsOfNames,
2149     Videowindow_Invoke,
2150     Videowindow_put_Caption,
2151     Videowindow_get_Caption,
2152     Videowindow_put_WindowStyle,
2153     Videowindow_get_WindowStyle,
2154     Videowindow_put_WindowStyleEx,
2155     Videowindow_get_WindowStyleEx,
2156     Videowindow_put_AutoShow,
2157     Videowindow_get_AutoShow,
2158     Videowindow_put_WindowState,
2159     Videowindow_get_WindowState,
2160     Videowindow_put_BackgroundPalette,
2161     Videowindow_get_BackgroundPalette,
2162     Videowindow_put_Visible,
2163     Videowindow_get_Visible,
2164     Videowindow_put_Left,
2165     Videowindow_get_Left,
2166     Videowindow_put_Width,
2167     Videowindow_get_Width,
2168     Videowindow_put_Top,
2169     Videowindow_get_Top,
2170     Videowindow_put_Height,
2171     Videowindow_get_Height,
2172     Videowindow_put_Owner,
2173     Videowindow_get_Owner,
2174     Videowindow_put_MessageDrain,
2175     Videowindow_get_MessageDrain,
2176     Videowindow_get_BorderColor,
2177     Videowindow_put_BorderColor,
2178     Videowindow_get_FullScreenMode,
2179     Videowindow_put_FullScreenMode,
2180     Videowindow_SetWindowForeground,
2181     Videowindow_NotifyOwnerMessage,
2182     Videowindow_SetWindowPosition,
2183     Videowindow_GetWindowPosition,
2184     Videowindow_GetMinIdealImageSize,
2185     Videowindow_GetMaxIdealImageSize,
2186     Videowindow_GetRestorePosition,
2187     Videowindow_HideCursor,
2188     Videowindow_IsCursorHidden
2189 };
2190
2191 static VideoRendererImpl *from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface) {
2192     return (VideoRendererImpl*)((char*)iface - offsetof(VideoRendererImpl, IAMFilterMiscFlags_vtbl));
2193 }
2194
2195 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, const REFIID riid, void **ppv) {
2196     VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2197     return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
2198 }
2199
2200 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
2201     VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2202     return IUnknown_AddRef((IUnknown*)This);
2203 }
2204
2205 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
2206     VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2207     return IUnknown_Release((IUnknown*)This);
2208 }
2209
2210 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
2211     return AM_FILTER_MISC_FLAGS_IS_RENDERER;
2212 }
2213
2214 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
2215     AMFilterMiscFlags_QueryInterface,
2216     AMFilterMiscFlags_AddRef,
2217     AMFilterMiscFlags_Release,
2218     AMFilterMiscFlags_GetMiscFlags
2219 };