wined3d: Shaders will never have a NULL function.
[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*)GetWindowLongA(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     SetWindowLongA(This->hWnd, 0, (LONG)This);
201
202     return TRUE;
203 }
204
205 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
206 {
207     VideoRendererImpl* This = (VideoRendererImpl*) 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, (LPVOID)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 const IMemInputPinVtbl MemInputPin_Vtbl = 
260 {
261     MemInputPin_QueryInterface,
262     MemInputPin_AddRef,
263     MemInputPin_Release,
264     MemInputPin_GetAllocator,
265     MemInputPin_NotifyAllocator,
266     MemInputPin_GetAllocatorRequirements,
267     MemInputPin_Receive,
268     MemInputPin_ReceiveMultiple,
269     MemInputPin_ReceiveCanBlock
270 };
271
272 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
273 {
274     AM_MEDIA_TYPE amt;
275     HRESULT hr = S_OK;
276     DDSURFACEDESC sdesc;
277     HDC hDC;
278     BITMAPINFOHEADER *bmiHeader;
279
280     TRACE("%p %p %d\n", This, data, size);
281
282     sdesc.dwSize = sizeof(sdesc);
283     hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
284     if (FAILED(hr)) {
285         ERR("Unable to retrieve media type\n");
286         return hr;
287     }
288
289     if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
290     {
291         bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
292     }
293     else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
294     {
295         bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
296     }
297     else
298     {
299         FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
300         return VFW_E_RUNTIME_ERROR;
301     }
302
303
304     TRACE("biSize = %d\n", bmiHeader->biSize);
305     TRACE("biWidth = %d\n", bmiHeader->biWidth);
306     TRACE("biHeight = %d\n", bmiHeader->biHeight);
307     TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
308     TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
309     TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
310     TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
311
312     if (!This->init)
313     {
314         if (!This->WindowPos.right || !This->WindowPos.bottom)
315             This->WindowPos = This->SourceRect;
316
317         TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
318         SetWindowPos(This->hWnd, NULL,
319             This->WindowPos.left,
320             This->WindowPos.top,
321             This->WindowPos.right - This->WindowPos.left,
322             This->WindowPos.bottom - This->WindowPos.top,
323             SWP_NOZORDER|SWP_NOMOVE);
324
325         GetClientRect(This->hWnd, &This->DestRect);
326         This->init = TRUE;
327     }
328
329     hDC = GetDC(This->hWnd);
330
331     if (!hDC) {
332         ERR("Cannot get DC from window!\n");
333         return E_FAIL;
334     }
335
336     TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
337     TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
338
339     StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
340                   This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
341                   This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
342                   data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
343
344     ReleaseDC(This->hWnd, hDC);
345     if (This->AutoShow)
346         ShowWindow(This->hWnd, SW_SHOW);
347
348     return S_OK;
349 }
350
351 static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
352 {
353     VideoRendererImpl *This = (VideoRendererImpl *)iface;
354     LPBYTE pbSrcStream = NULL;
355     long cbSrcStream = 0;
356     REFERENCE_TIME tStart, tStop;
357     HRESULT hr;
358
359     EnterCriticalSection(&This->csFilter);
360
361     if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
362     {
363         LeaveCriticalSection(&This->csFilter);
364         return S_FALSE;
365     }
366
367     if (This->state == State_Stopped)
368     {
369         LeaveCriticalSection(&This->csFilter);
370         return VFW_E_WRONG_STATE;
371     }
372
373     TRACE("%p %p\n", iface, pSample);
374
375     hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
376     if (FAILED(hr))
377         ERR("Cannot get sample time (%x)\n", hr);
378
379     if (This->rtLastStop != tStart)
380     {
381         if (IMediaSample_IsDiscontinuity(pSample) == S_FALSE)
382             ERR("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
383                 (DWORD)(This->rtLastStop / 10000000),
384                 (DWORD)((This->rtLastStop / 10000)%1000),
385                 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
386         This->rtLastStop = tStart;
387     }
388
389     /* Preroll means the sample isn't shown, this is used for key frames and things like that */
390     if (IMediaSample_IsPreroll(pSample) == S_OK)
391     {
392         This->rtLastStop = tStop;
393         LeaveCriticalSection(&This->csFilter);
394         return S_OK;
395     }
396
397     hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
398     if (FAILED(hr))
399     {
400         ERR("Cannot get pointer to sample data (%x)\n", hr);
401         LeaveCriticalSection(&This->csFilter);
402         return hr;
403     }
404
405     cbSrcStream = IMediaSample_GetActualDataLength(pSample);
406
407     TRACE("val %p %ld\n", pbSrcStream, cbSrcStream);
408
409 #if 0 /* For debugging purpose */
410     {
411         int i;
412         for(i = 0; i < cbSrcStream; i++)
413         {
414             if ((i!=0) && !(i%16))
415                 TRACE("\n");
416                 TRACE("%02x ", pbSrcStream[i]);
417         }
418         TRACE("\n");
419     }
420 #endif
421
422     SetEvent(This->hEvent);
423     if (This->state == State_Paused)
424     {
425         This->sample_held = pSample;
426         LeaveCriticalSection(&This->csFilter);
427         WaitForSingleObject(This->blocked, INFINITE);
428         EnterCriticalSection(&This->csFilter);
429         This->sample_held = NULL;
430         if (This->state == State_Paused)
431         {
432             /* Flushing */
433             LeaveCriticalSection(&This->csFilter);
434             return S_OK;
435         }
436         if (This->state == State_Stopped)
437         {
438             LeaveCriticalSection(&This->csFilter);
439             return VFW_E_WRONG_STATE;
440         }
441     }
442
443     if (This->pClock && This->state == State_Running)
444     {
445         REFERENCE_TIME time, trefstart, trefstop;
446         LONG delta;
447
448         /* Perhaps I <SHOULD> use the reference clock AdviseTime function here
449          * I'm not going to! When I tried, it seemed to generate lag and
450          * it caused instability.
451          */
452         IReferenceClock_GetTime(This->pClock, &time);
453
454         trefstart = This->rtStreamStart;
455         trefstop = (REFERENCE_TIME)((double)(tStop - tStart) / This->pInputPin->dRate) + This->rtStreamStart;
456         delta = (LONG)((trefstart-time)/10000);
457         This->rtStreamStart = trefstop;
458         This->rtLastStop = tStop;
459
460         if (delta > 0)
461         {
462             TRACE("Sleeping for %u ms\n", delta);
463             Sleep(delta);
464         }
465         else if (time > trefstop)
466         {
467             TRACE("Dropping sample: Time: %u.%03u ms trefstop: %u.%03u ms!\n",
468                   (DWORD)(time / 10000000), (DWORD)((time / 10000)%1000),
469                   (DWORD)(trefstop / 10000000), (DWORD)((trefstop / 10000)%1000) );
470             This->rtLastStop = tStop;
471             LeaveCriticalSection(&This->csFilter);
472             return S_OK;
473         }
474     }
475     This->rtLastStop = tStop;
476
477     VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
478
479     LeaveCriticalSection(&This->csFilter);
480     return S_OK;
481 }
482
483 static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
484 {
485     if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
486         return S_FALSE;
487
488     if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
489         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
490         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
491         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
492     {
493         VideoRendererImpl* This = (VideoRendererImpl*) iface;
494
495         if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
496         {
497             VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
498             This->SourceRect.left = 0;
499             This->SourceRect.top = 0;
500             This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
501             This->SourceRect.bottom = This->VideoHeight = format->bmiHeader.biHeight;
502         }
503         else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
504         {
505             VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
506
507             This->SourceRect.left = 0;
508             This->SourceRect.top = 0;
509             This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
510             This->SourceRect.bottom = This->VideoHeight = format2->bmiHeader.biHeight;
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 = (LPVOID)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 = (LPVOID)&(This->IInner_vtbl);
665     else if (IsEqualIID(riid, &IID_IPersist))
666         *ppv = (LPVOID)This;
667     else if (IsEqualIID(riid, &IID_IMediaFilter))
668         *ppv = (LPVOID)This;
669     else if (IsEqualIID(riid, &IID_IBaseFilter))
670         *ppv = (LPVOID)This;
671     else if (IsEqualIID(riid, &IID_IBasicVideo))
672         *ppv = (LPVOID)&(This->IBasicVideo_vtbl);
673     else if (IsEqualIID(riid, &IID_IVideoWindow))
674         *ppv = (LPVOID)&(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     TRACE("(%p/%p)->(%p,%p)\n", This, iface, debugstr_w(Id), ppPin);
965
966     FIXME("VideoRenderer::FindPin(...)\n");
967
968     /* FIXME: critical section */
969
970     return E_NOTIMPL;
971 }
972
973 static HRESULT WINAPI VideoRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
974 {
975     VideoRendererImpl *This = (VideoRendererImpl *)iface;
976
977     TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
978
979     strcpyW(pInfo->achName, This->filterInfo.achName);
980     pInfo->pGraph = This->filterInfo.pGraph;
981
982     if (pInfo->pGraph)
983         IFilterGraph_AddRef(pInfo->pGraph);
984     
985     return S_OK;
986 }
987
988 static HRESULT WINAPI VideoRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
989 {
990     VideoRendererImpl *This = (VideoRendererImpl *)iface;
991
992     TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
993
994     EnterCriticalSection(&This->csFilter);
995     {
996         if (pName)
997             strcpyW(This->filterInfo.achName, pName);
998         else
999             *This->filterInfo.achName = '\0';
1000         This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
1001     }
1002     LeaveCriticalSection(&This->csFilter);
1003
1004     return S_OK;
1005 }
1006
1007 static HRESULT WINAPI VideoRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
1008 {
1009     VideoRendererImpl *This = (VideoRendererImpl *)iface;
1010     TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
1011     return E_NOTIMPL;
1012 }
1013
1014 static const IBaseFilterVtbl VideoRenderer_Vtbl =
1015 {
1016     VideoRenderer_QueryInterface,
1017     VideoRenderer_AddRef,
1018     VideoRenderer_Release,
1019     VideoRenderer_GetClassID,
1020     VideoRenderer_Stop,
1021     VideoRenderer_Pause,
1022     VideoRenderer_Run,
1023     VideoRenderer_GetState,
1024     VideoRenderer_SetSyncSource,
1025     VideoRenderer_GetSyncSource,
1026     VideoRenderer_EnumPins,
1027     VideoRenderer_FindPin,
1028     VideoRenderer_QueryFilterInfo,
1029     VideoRenderer_JoinFilterGraph,
1030     VideoRenderer_QueryVendorInfo
1031 };
1032
1033 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
1034 {
1035     InputPin* This = (InputPin*)iface;
1036     IMediaEventSink* pEventSink;
1037     HRESULT hr;
1038
1039     TRACE("(%p/%p)->()\n", This, iface);
1040
1041     hr = IFilterGraph_QueryInterface(((VideoRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
1042     if (SUCCEEDED(hr))
1043     {
1044         hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
1045         IMediaEventSink_Release(pEventSink);
1046     }
1047
1048     return hr;
1049 }
1050
1051 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
1052 {
1053     InputPin* This = (InputPin*)iface;
1054     VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1055     HRESULT hr;
1056
1057     TRACE("(%p/%p)->()\n", This, iface);
1058
1059     EnterCriticalSection(This->pin.pCritSec);
1060     if (pVideoRenderer->state == State_Paused)
1061         SetEvent(pVideoRenderer->blocked);
1062
1063     hr = InputPin_BeginFlush(iface);
1064     LeaveCriticalSection(This->pin.pCritSec);
1065
1066     return hr;
1067 }
1068
1069 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
1070 {
1071     InputPin* This = (InputPin*)iface;
1072     VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1073     HRESULT hr;
1074
1075     TRACE("(%p/%p)->()\n", This, iface);
1076
1077     EnterCriticalSection(This->pin.pCritSec);
1078     if (pVideoRenderer->state == State_Paused)
1079         ResetEvent(pVideoRenderer->blocked);
1080
1081     hr = InputPin_EndFlush(iface);
1082     LeaveCriticalSection(This->pin.pCritSec);
1083
1084     return hr;
1085 }
1086
1087 static const IPinVtbl VideoRenderer_InputPin_Vtbl = 
1088 {
1089     InputPin_QueryInterface,
1090     IPinImpl_AddRef,
1091     InputPin_Release,
1092     InputPin_Connect,
1093     InputPin_ReceiveConnection,
1094     IPinImpl_Disconnect,
1095     IPinImpl_ConnectedTo,
1096     IPinImpl_ConnectionMediaType,
1097     IPinImpl_QueryPinInfo,
1098     IPinImpl_QueryDirection,
1099     IPinImpl_QueryId,
1100     IPinImpl_QueryAccept,
1101     IPinImpl_EnumMediaTypes,
1102     IPinImpl_QueryInternalConnections,
1103     VideoRenderer_InputPin_EndOfStream,
1104     VideoRenderer_InputPin_BeginFlush,
1105     VideoRenderer_InputPin_EndFlush,
1106     InputPin_NewSegment
1107 };
1108
1109 /*** IUnknown methods ***/
1110 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
1111                                                 REFIID riid,
1112                                                 LPVOID*ppvObj) {
1113     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1114
1115     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1116
1117     return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1118 }
1119
1120 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1121     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1122
1123     TRACE("(%p/%p)->()\n", This, iface);
1124
1125     return VideoRenderer_AddRef((IBaseFilter*)This);
1126 }
1127
1128 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1129     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1130
1131     TRACE("(%p/%p)->()\n", This, iface);
1132
1133     return VideoRenderer_Release((IBaseFilter*)This);
1134 }
1135
1136 /*** IDispatch methods ***/
1137 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1138                                                   UINT*pctinfo) {
1139     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1140
1141     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1142
1143     return S_OK;
1144 }
1145
1146 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1147                                              UINT iTInfo,
1148                                              LCID lcid,
1149                                              ITypeInfo**ppTInfo) {
1150     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1151
1152     FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1153
1154     return S_OK;
1155 }
1156
1157 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1158                                                REFIID riid,
1159                                                LPOLESTR*rgszNames,
1160                                                UINT cNames,
1161                                                LCID lcid,
1162                                                DISPID*rgDispId) {
1163     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1164
1165     FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1166
1167     return S_OK;
1168 }
1169
1170 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1171                                         DISPID dispIdMember,
1172                                         REFIID riid,
1173                                         LCID lcid,
1174                                         WORD wFlags,
1175                                         DISPPARAMS*pDispParams,
1176                                         VARIANT*pVarResult,
1177                                         EXCEPINFO*pExepInfo,
1178                                         UINT*puArgErr) {
1179     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1180
1181     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);
1182
1183     return S_OK;
1184 }
1185
1186 /*** IBasicVideo methods ***/
1187 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1188                                                      REFTIME *pAvgTimePerFrame) {
1189     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1190
1191     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pAvgTimePerFrame);
1192
1193     return S_OK;
1194 }
1195
1196 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1197                                              long *pBitRate) {
1198     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1199
1200     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1201
1202     return S_OK;
1203 }
1204
1205 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1206                                                   long *pBitErrorRate) {
1207     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1208
1209     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1210
1211     return S_OK;
1212 }
1213
1214 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1215                                                 long *pVideoWidth) {
1216     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1217
1218     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1219
1220     *pVideoWidth = This->VideoWidth;
1221
1222     return S_OK;
1223 }
1224
1225 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1226                                                  long *pVideoHeight) {
1227     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1228
1229     TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1230
1231     *pVideoHeight = This->VideoHeight;
1232
1233     return S_OK;
1234 }
1235
1236 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1237                                                 long SourceLeft) {
1238     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1239
1240     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceLeft);
1241
1242     This->SourceRect.left = SourceLeft;
1243
1244     return S_OK;
1245 }
1246
1247 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1248                                                 long *pSourceLeft) {
1249     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1250
1251     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1252
1253     *pSourceLeft = This->SourceRect.left;
1254
1255     return S_OK;
1256 }
1257
1258 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1259                                                  long SourceWidth) {
1260     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1261
1262     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceWidth);
1263
1264     This->SourceRect.right = This->SourceRect.left + SourceWidth;
1265
1266     return S_OK;
1267 }
1268
1269 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1270                                                  long *pSourceWidth) {
1271     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1272
1273     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1274
1275     *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1276     
1277     return S_OK;
1278 }
1279
1280 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1281                                                long SourceTop) {
1282     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1283
1284     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceTop);
1285
1286     This->SourceRect.top = SourceTop;
1287
1288     return S_OK;
1289 }
1290
1291 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1292                                                long *pSourceTop) {
1293     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1294
1295     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1296
1297     *pSourceTop = This->SourceRect.top;
1298
1299     return S_OK;
1300 }
1301
1302 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1303                                                   long SourceHeight) {
1304     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1305
1306     TRACE("(%p/%p)->(%ld)\n", This, iface, SourceHeight);
1307
1308     This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1309
1310     return S_OK;
1311 }
1312
1313 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1314                                                   long *pSourceHeight) {
1315     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1316
1317     TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1318
1319     *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1320
1321     return S_OK;
1322 }
1323
1324 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1325                                                      long DestinationLeft) {
1326     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1327
1328     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationLeft);
1329
1330     This->DestRect.left = DestinationLeft;
1331
1332     return S_OK;
1333 }
1334
1335 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1336                                                      long *pDestinationLeft) {
1337     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1338
1339     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1340
1341     *pDestinationLeft = This->DestRect.left;
1342
1343     return S_OK;
1344 }
1345
1346 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1347                                                       long DestinationWidth) {
1348     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1349
1350     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationWidth);
1351
1352     This->DestRect.right = This->DestRect.left + DestinationWidth;
1353
1354     return S_OK;
1355 }
1356
1357 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1358                                                       long *pDestinationWidth) {
1359     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1360
1361     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1362
1363     *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1364
1365     return S_OK;
1366 }
1367
1368 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1369                                                     long DestinationTop) {
1370     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1371
1372     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationTop);
1373
1374     This->DestRect.top = DestinationTop;
1375     
1376     return S_OK;
1377 }
1378
1379 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1380                                                     long *pDestinationTop) {
1381     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1382
1383     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1384
1385     *pDestinationTop = This->DestRect.top;
1386
1387     return S_OK;
1388 }
1389
1390 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1391                                                        long DestinationHeight) {
1392     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1393
1394     TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationHeight);
1395
1396     This->DestRect.right = This->DestRect.left + DestinationHeight;
1397
1398     return S_OK;
1399 }
1400
1401 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1402                                                        long *pDestinationHeight) {
1403     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1404
1405     TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1406
1407     *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1408
1409     return S_OK;
1410 }
1411
1412 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1413                                                    long Left,
1414                                                    long Top,
1415                                                    long Width,
1416                                                    long Height) {
1417     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1418
1419     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
1420
1421     This->SourceRect.left = Left;
1422     This->SourceRect.top = Top;
1423     This->SourceRect.right = Left + Width;
1424     This->SourceRect.bottom = Top + Height;
1425     
1426     return S_OK;
1427 }
1428
1429 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1430                                                    long *pLeft,
1431                                                    long *pTop,
1432                                                    long *pWidth,
1433                                                    long *pHeight) {
1434     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1435
1436     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1437
1438     *pLeft = This->SourceRect.left;
1439     *pTop = This->SourceRect.top;
1440     *pWidth = This->SourceRect.right - This->SourceRect.left;
1441     *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1442     
1443     return S_OK;
1444 }
1445
1446 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1447     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1448
1449     TRACE("(%p/%p)->()\n", This, iface);
1450
1451     This->SourceRect.left = 0;
1452     This->SourceRect.top = 0;
1453     This->SourceRect.right = This->VideoWidth;
1454     This->SourceRect.bottom = This->VideoHeight;
1455
1456     return S_OK;
1457 }
1458
1459 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1460                                                         long Left,
1461                                                         long Top,
1462                                                         long Width,
1463                                                         long Height) {
1464     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1465
1466     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
1467
1468     This->DestRect.left = Left;
1469     This->DestRect.top = Top;
1470     This->DestRect.right = Left + Width;
1471     This->DestRect.bottom = Top + Height;
1472
1473     return S_OK;
1474 }
1475
1476 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1477                                                         long *pLeft,
1478                                                         long *pTop,
1479                                                         long *pWidth,
1480                                                         long *pHeight) {
1481     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1482
1483     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1484
1485     *pLeft = This->DestRect.left;
1486     *pTop = This->DestRect.top;
1487     *pWidth = This->DestRect.right - This->DestRect.left;
1488     *pHeight = This->DestRect.bottom - This->DestRect.top;
1489
1490     return S_OK;
1491 }
1492
1493 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1494     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1495     RECT rect;
1496
1497     TRACE("(%p/%p)->()\n", This, iface);
1498
1499     if (!GetClientRect(This->hWnd, &rect))
1500         return E_FAIL;
1501     
1502     This->SourceRect.left = 0;
1503     This->SourceRect.top = 0;
1504     This->SourceRect.right = rect.right;
1505     This->SourceRect.bottom = rect.bottom;
1506     
1507     return S_OK;
1508 }
1509
1510 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1511                                               long *pWidth,
1512                                               long *pHeight) {
1513     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1514
1515     TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1516
1517     *pWidth = This->VideoWidth;
1518     *pHeight = This->VideoHeight;
1519     
1520     return S_OK;
1521 }
1522
1523 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1524                                                         long StartIndex,
1525                                                         long Entries,
1526                                                         long *pRetrieved,
1527                                                         long *pPalette) {
1528     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1529
1530     FIXME("(%p/%p)->(%ld, %ld, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1531
1532     return S_OK;
1533 }
1534
1535 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1536                                                  long *pBufferSize,
1537                                                  long *pDIBImage) {
1538     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1539     BITMAPINFOHEADER *bmiHeader;
1540     LONG needed_size;
1541     AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1542     char *ptr;
1543
1544     EnterCriticalSection(&This->csFilter);
1545
1546     if (!This->sample_held)
1547     {
1548          LeaveCriticalSection(&This->csFilter);
1549          return (This->state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1550     }
1551
1552     FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1553
1554     if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1555     {
1556         bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1557     }
1558     else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1559     {
1560         bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1561     }
1562     else
1563     {
1564         FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1565         LeaveCriticalSection(&This->csFilter);
1566         return VFW_E_RUNTIME_ERROR;
1567     }
1568
1569     needed_size = bmiHeader->biSize;
1570     needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1571
1572     if (!pDIBImage)
1573     {
1574         *pBufferSize = needed_size;
1575         LeaveCriticalSection(&This->csFilter);
1576         return S_OK;
1577     }
1578
1579     if (needed_size < *pBufferSize)
1580     {
1581         ERR("Buffer too small %u/%lu\n", needed_size, *pBufferSize);
1582         LeaveCriticalSection(&This->csFilter);
1583         return E_FAIL;
1584     }
1585     *pBufferSize = needed_size;
1586
1587     memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1588     IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1589     memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1590
1591     LeaveCriticalSection(&This->csFilter);
1592
1593     return S_OK;
1594 }
1595
1596 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1597     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1598
1599     FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1600
1601     return S_OK;
1602 }
1603
1604 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1605     ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1606
1607     FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1608
1609     return S_OK;
1610 }
1611
1612
1613 static const IBasicVideoVtbl IBasicVideo_VTable =
1614 {
1615     Basicvideo_QueryInterface,
1616     Basicvideo_AddRef,
1617     Basicvideo_Release,
1618     Basicvideo_GetTypeInfoCount,
1619     Basicvideo_GetTypeInfo,
1620     Basicvideo_GetIDsOfNames,
1621     Basicvideo_Invoke,
1622     Basicvideo_get_AvgTimePerFrame,
1623     Basicvideo_get_BitRate,
1624     Basicvideo_get_BitErrorRate,
1625     Basicvideo_get_VideoWidth,
1626     Basicvideo_get_VideoHeight,
1627     Basicvideo_put_SourceLeft,
1628     Basicvideo_get_SourceLeft,
1629     Basicvideo_put_SourceWidth,
1630     Basicvideo_get_SourceWidth,
1631     Basicvideo_put_SourceTop,
1632     Basicvideo_get_SourceTop,
1633     Basicvideo_put_SourceHeight,
1634     Basicvideo_get_SourceHeight,
1635     Basicvideo_put_DestinationLeft,
1636     Basicvideo_get_DestinationLeft,
1637     Basicvideo_put_DestinationWidth,
1638     Basicvideo_get_DestinationWidth,
1639     Basicvideo_put_DestinationTop,
1640     Basicvideo_get_DestinationTop,
1641     Basicvideo_put_DestinationHeight,
1642     Basicvideo_get_DestinationHeight,
1643     Basicvideo_SetSourcePosition,
1644     Basicvideo_GetSourcePosition,
1645     Basicvideo_SetDefaultSourcePosition,
1646     Basicvideo_SetDestinationPosition,
1647     Basicvideo_GetDestinationPosition,
1648     Basicvideo_SetDefaultDestinationPosition,
1649     Basicvideo_GetVideoSize,
1650     Basicvideo_GetVideoPaletteEntries,
1651     Basicvideo_GetCurrentImage,
1652     Basicvideo_IsUsingDefaultSource,
1653     Basicvideo_IsUsingDefaultDestination
1654 };
1655
1656
1657 /*** IUnknown methods ***/
1658 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1659                                                  REFIID riid,
1660                                                  LPVOID*ppvObj) {
1661     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1662
1663     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1664
1665     return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1666 }
1667
1668 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1669     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1670
1671     TRACE("(%p/%p)->()\n", This, iface);
1672
1673     return VideoRenderer_AddRef((IBaseFilter*)This);
1674 }
1675
1676 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1677     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1678
1679     TRACE("(%p/%p)->()\n", This, iface);
1680
1681     return VideoRenderer_Release((IBaseFilter*)This);
1682 }
1683
1684 /*** IDispatch methods ***/
1685 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1686                                                    UINT*pctinfo) {
1687     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1688
1689     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1690
1691     return S_OK;
1692 }
1693
1694 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1695                                               UINT iTInfo,
1696                                               LCID lcid,
1697                                               ITypeInfo**ppTInfo) {
1698     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1699
1700     FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1701
1702     return S_OK;
1703 }
1704
1705 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1706                                                 REFIID riid,
1707                                                 LPOLESTR*rgszNames,
1708                                                 UINT cNames,
1709                                                 LCID lcid,
1710                                                 DISPID*rgDispId) {
1711     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1712
1713     FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1714
1715     return S_OK;
1716 }
1717
1718 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1719                                          DISPID dispIdMember,
1720                                          REFIID riid,
1721                                          LCID lcid,
1722                                          WORD wFlags,
1723                                          DISPPARAMS*pDispParams,
1724                                          VARIANT*pVarResult,
1725                                          EXCEPINFO*pExepInfo,
1726                                          UINT*puArgErr) {
1727     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1728
1729     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);
1730
1731     return S_OK;
1732 }
1733
1734 /*** IVideoWindow methods ***/
1735 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1736                                               BSTR strCaption) {
1737     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1738
1739     TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1740
1741     if (!SetWindowTextW(This->hWnd, strCaption))
1742         return E_FAIL;
1743
1744     return S_OK;
1745 }
1746
1747 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1748                                               BSTR *strCaption) {
1749     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1750
1751     TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1752
1753     GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1754
1755     return S_OK;
1756 }
1757
1758 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1759                                                   long WindowStyle) {
1760     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1761     LONG old;
1762
1763     old = GetWindowLongA(This->hWnd, GWL_STYLE);
1764     
1765     TRACE("(%p/%p)->(%x -> %lx)\n", This, iface, old, WindowStyle);
1766
1767     if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1768         return E_INVALIDARG;
1769     
1770     SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1771
1772     return S_OK;
1773 }
1774
1775 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1776                                                   long *WindowStyle) {
1777     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1778
1779     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1780
1781     *WindowStyle = GetWindowLongA(This->hWnd, GWL_STYLE);
1782
1783     return S_OK;
1784 }
1785
1786 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1787                                                     long WindowStyleEx) {
1788     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1789
1790     TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyleEx);
1791
1792     if (WindowStyleEx & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1793         return E_INVALIDARG;
1794
1795     if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1796         return E_FAIL;
1797
1798     return S_OK;
1799 }
1800
1801 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1802                                                     long *WindowStyleEx) {
1803     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1804
1805     TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1806
1807     *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1808
1809     return S_OK;
1810 }
1811
1812 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1813                                                long AutoShow) {
1814     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1815
1816     TRACE("(%p/%p)->(%ld)\n", This, iface, AutoShow);
1817
1818     This->AutoShow = 1; /* FXIME: Should be AutoShow */;
1819
1820     return S_OK;
1821 }
1822
1823 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1824                                                long *AutoShow) {
1825     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1826
1827     TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1828
1829     *AutoShow = This->AutoShow;
1830
1831     return S_OK;
1832 }
1833
1834 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1835                                                   long WindowState) {
1836     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1837
1838     FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, WindowState);
1839
1840     return S_OK;
1841 }
1842
1843 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1844                                                   long *WindowState) {
1845     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1846
1847     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, WindowState);
1848
1849     return S_OK;
1850 }
1851
1852 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1853                                                         long BackgroundPalette) {
1854     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1855
1856     FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, BackgroundPalette);
1857
1858     return S_OK;
1859 }
1860
1861 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1862                                                         long *pBackgroundPalette) {
1863     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1864
1865     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1866
1867     return S_OK;
1868 }
1869
1870 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1871                                               long Visible) {
1872     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1873
1874     TRACE("(%p/%p)->(%ld)\n", This, iface, Visible);
1875
1876     ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1877
1878     return S_OK;
1879 }
1880
1881 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1882                                               long *pVisible) {
1883     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1884
1885     TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1886
1887     *pVisible = IsWindowVisible(This->hWnd);
1888
1889     return S_OK;
1890 }
1891
1892 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1893                                            long Left) {
1894     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1895
1896     TRACE("(%p/%p)->(%ld)\n", This, iface, Left);
1897
1898     if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1899         return E_FAIL;
1900
1901     This->WindowPos.left = Left;
1902
1903     return S_OK;
1904 }
1905
1906 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1907                                            long *pLeft) {
1908     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1909
1910     TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1911
1912     *pLeft = This->WindowPos.left;
1913
1914     return S_OK;
1915 }
1916
1917 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1918                                             long Width) {
1919     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1920
1921     TRACE("(%p/%p)->(%ld)\n", This, iface, Width);
1922
1923     if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1924         return E_FAIL;
1925
1926     This->WindowPos.right = This->WindowPos.left + Width;
1927
1928     return S_OK;
1929 }
1930
1931 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1932                                             long *pWidth) {
1933     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1934
1935     TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1936
1937     *pWidth = This->WindowPos.right - This->WindowPos.left;
1938
1939     return S_OK;
1940 }
1941
1942 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1943                                           long Top) {
1944     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1945
1946     TRACE("(%p/%p)->(%ld)\n", This, iface, Top);
1947
1948     if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1949         return E_FAIL;
1950
1951     This->WindowPos.top = Top;
1952
1953     return S_OK;
1954 }
1955
1956 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1957                                           long *pTop) {
1958     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1959
1960     TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1961
1962     *pTop = This->WindowPos.top;
1963
1964     return S_OK;
1965 }
1966
1967 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1968                                              long Height) {
1969     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1970
1971     TRACE("(%p/%p)->(%ld)\n", This, iface, Height);
1972
1973     if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1974         return E_FAIL;
1975
1976     This->WindowPos.bottom = This->WindowPos.top + Height;
1977
1978     return S_OK;
1979 }
1980
1981 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1982                                              long *pHeight) {
1983     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1984
1985     TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1986
1987     *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1988
1989     return S_OK;
1990 }
1991
1992 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1993                                             OAHWND Owner) {
1994     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1995
1996     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1997
1998     SetParent(This->hWnd, (HWND)Owner);
1999
2000     return S_OK;
2001 }
2002
2003 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
2004                                             OAHWND *Owner) {
2005     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2006
2007     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
2008
2009     *(HWND*)Owner = GetParent(This->hWnd);
2010
2011     return S_OK;
2012 }
2013
2014 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
2015                                                    OAHWND Drain) {
2016     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2017
2018     TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
2019
2020     This->hWndMsgDrain = (HWND)Drain;
2021
2022     return S_OK;
2023 }
2024
2025 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
2026                                                    OAHWND *Drain) {
2027     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2028
2029     TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
2030
2031     *Drain = (OAHWND)This->hWndMsgDrain;
2032
2033     return S_OK;
2034 }
2035
2036 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
2037                                                   long *Color) {
2038     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2039
2040     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
2041
2042     return S_OK;
2043 }
2044
2045 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
2046                                                   long Color) {
2047     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2048
2049     FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, Color);
2050
2051     return S_OK;
2052 }
2053
2054 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
2055                                                      long *FullScreenMode) {
2056     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2057
2058     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
2059
2060     return S_OK;
2061 }
2062
2063 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
2064                                                      long FullScreenMode) {
2065     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2066
2067     FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, FullScreenMode);
2068
2069     return S_OK;
2070 }
2071
2072 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2073                                                       long Focus) {
2074     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2075     BOOL ret;
2076     IPin* pPin;
2077     HRESULT hr;
2078
2079     TRACE("(%p/%p)->(%ld)\n", This, iface, Focus);
2080
2081     if ((Focus != FALSE) && (Focus != TRUE))
2082         return E_INVALIDARG;
2083
2084     hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2085     if ((hr != S_OK) || !pPin)
2086         return VFW_E_NOT_CONNECTED;
2087
2088     if (Focus)
2089         ret = SetForegroundWindow(This->hWnd);
2090     else
2091         ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2092
2093     if (!ret)
2094         return E_FAIL;
2095
2096     return S_OK;
2097 }
2098
2099 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2100                                                      OAHWND hwnd,
2101                                                      long uMsg,
2102                                                      LONG_PTR wParam,
2103                                                      LONG_PTR lParam) {
2104     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2105
2106     TRACE("(%p/%p)->(%08x, %ld, %08lx, %08lx)\n", This, iface, (DWORD) hwnd, uMsg, wParam, lParam);
2107
2108     if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
2109         return E_FAIL;
2110     
2111     return S_OK;
2112 }
2113
2114 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2115                                                     long Left,
2116                                                     long Top,
2117                                                     long Width,
2118                                                     long Height) {
2119     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2120     
2121     TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
2122
2123     if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2124         return E_FAIL;
2125
2126     This->WindowPos.left = Left;
2127     This->WindowPos.top = Top;
2128     This->WindowPos.right = Left + Width;
2129     This->WindowPos.bottom = Top + Height;
2130     
2131     return S_OK;
2132 }
2133
2134 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2135                                                     long *pLeft,
2136                                                     long *pTop,
2137                                                     long *pWidth,
2138                                                     long *pHeight) {
2139     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2140
2141     TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2142
2143     *pLeft = This->WindowPos.left;
2144     *pTop = This->WindowPos.top;
2145     *pWidth = This->WindowPos.right - This->WindowPos.left;
2146     *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2147
2148     return S_OK;
2149 }
2150
2151 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2152                                                        long *pWidth,
2153                                                        long *pHeight) {
2154     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2155
2156     FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2157
2158     *pWidth = This->VideoWidth;
2159     *pHeight = This->VideoHeight;
2160
2161     return S_OK;
2162 }
2163
2164 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2165                                                        long *pWidth,
2166                                                        long *pHeight) {
2167     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2168
2169     FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2170
2171     *pWidth = This->VideoWidth;
2172     *pHeight = This->VideoHeight;
2173
2174     return S_OK;
2175 }
2176
2177 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2178                                                      long *pLeft,
2179                                                      long *pTop,
2180                                                      long *pWidth,
2181                                                      long *pHeight) {
2182     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2183
2184     FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2185
2186     return S_OK;
2187 }
2188
2189 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2190                                              long HideCursor) {
2191     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2192
2193     FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, HideCursor);
2194
2195     return S_OK;
2196 }
2197
2198 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2199                                                  long *CursorHidden) {
2200     ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2201
2202     FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2203
2204     return S_OK;
2205 }
2206
2207 static const IVideoWindowVtbl IVideoWindow_VTable =
2208 {
2209     Videowindow_QueryInterface,
2210     Videowindow_AddRef,
2211     Videowindow_Release,
2212     Videowindow_GetTypeInfoCount,
2213     Videowindow_GetTypeInfo,
2214     Videowindow_GetIDsOfNames,
2215     Videowindow_Invoke,
2216     Videowindow_put_Caption,
2217     Videowindow_get_Caption,
2218     Videowindow_put_WindowStyle,
2219     Videowindow_get_WindowStyle,
2220     Videowindow_put_WindowStyleEx,
2221     Videowindow_get_WindowStyleEx,
2222     Videowindow_put_AutoShow,
2223     Videowindow_get_AutoShow,
2224     Videowindow_put_WindowState,
2225     Videowindow_get_WindowState,
2226     Videowindow_put_BackgroundPalette,
2227     Videowindow_get_BackgroundPalette,
2228     Videowindow_put_Visible,
2229     Videowindow_get_Visible,
2230     Videowindow_put_Left,
2231     Videowindow_get_Left,
2232     Videowindow_put_Width,
2233     Videowindow_get_Width,
2234     Videowindow_put_Top,
2235     Videowindow_get_Top,
2236     Videowindow_put_Height,
2237     Videowindow_get_Height,
2238     Videowindow_put_Owner,
2239     Videowindow_get_Owner,
2240     Videowindow_put_MessageDrain,
2241     Videowindow_get_MessageDrain,
2242     Videowindow_get_BorderColor,
2243     Videowindow_put_BorderColor,
2244     Videowindow_get_FullScreenMode,
2245     Videowindow_put_FullScreenMode,
2246     Videowindow_SetWindowForeground,
2247     Videowindow_NotifyOwnerMessage,
2248     Videowindow_SetWindowPosition,
2249     Videowindow_GetWindowPosition,
2250     Videowindow_GetMinIdealImageSize,
2251     Videowindow_GetMaxIdealImageSize,
2252     Videowindow_GetRestorePosition,
2253     Videowindow_HideCursor,
2254     Videowindow_IsCursorHidden
2255 };