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