Synchronize with trunk.
[reactos.git] / dll / directx / quartz / videorenderer.c
index 17042a7..c29fbd3 100644 (file)
@@ -23,7 +23,6 @@
 #define NONAMELESSSTRUCT
 #define NONAMELESSUNION
 #include "quartz_private.h"
-#include "control_private.h"
 #include "pin.h"
 
 //#include "uuids.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
 
-static BOOL wnd_class_registered = FALSE;
-
-static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
-
-static const IBaseFilterVtbl VideoRenderer_Vtbl;
-static const IUnknownVtbl IInner_VTable;
-static const IBasicVideoVtbl IBasicVideo_VTable;
-static const IVideoWindowVtbl IVideoWindow_VTable;
-static const IPinVtbl VideoRenderer_InputPin_Vtbl;
-
 typedef struct VideoRendererImpl
 {
-    const IBaseFilterVtbl * lpVtbl;
-    const IBasicVideoVtbl * IBasicVideo_vtbl;
-    const IVideoWindowVtbl * IVideoWindow_vtbl;
-    const IUnknownVtbl * IInner_vtbl;
-
-    LONG refCount;
-    CRITICAL_SECTION csFilter;
-    FILTER_STATE state;
-    REFERENCE_TIME rtStreamStart;
-    IReferenceClock * pClock;
-    FILTER_INFO filterInfo;
+    BaseRenderer renderer;
+    BaseControlWindow baseControlWindow;
+    BaseControlVideo baseControlVideo;
 
-    InputPin *pInputPin;
+    IUnknown IUnknown_inner;
+    IAMFilterMiscFlags IAMFilterMiscFlags_iface;
+    IUnknown *outer_unk;
 
     BOOL init;
     HANDLE hThread;
-    HANDLE blocked;
 
     DWORD ThreadID;
     HANDLE hEvent;
+/* hEvent == evComplete? */
     BOOL ThreadResult;
-    HWND hWnd;
-    HWND hWndMsgDrain;
-    BOOL AutoShow;
     RECT SourceRect;
     RECT DestRect;
     RECT WindowPos;
     LONG VideoWidth;
     LONG VideoHeight;
-    IUnknown * pUnkOuter;
-    BOOL bUnkOuterValid;
-    BOOL bAggregatable;
-    REFERENCE_TIME rtLastStop;
-    MediaSeekingImpl mediaSeeking;
-
-    /* During pause we can hold a single sample, for use in GetCurrentImage */
-    IMediaSample *sample_held;
 } VideoRendererImpl;
 
-static LRESULT CALLBACK VideoWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+static inline VideoRendererImpl *impl_from_BaseWindow(BaseWindow *iface)
 {
-    VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongPtrW(hwnd, 0);
-    LPRECT lprect = (LPRECT)lParam;
-
-    if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
-    {
-        switch(uMsg)
-        {
-            case WM_KEYDOWN:
-            case WM_KEYUP:
-            case WM_LBUTTONDBLCLK:
-            case WM_LBUTTONDOWN:
-            case WM_LBUTTONUP:
-            case WM_MBUTTONDBLCLK:
-            case WM_MBUTTONDOWN:
-            case WM_MBUTTONUP:
-            case WM_MOUSEACTIVATE:
-            case WM_MOUSEMOVE:
-            case WM_NCLBUTTONDBLCLK:
-            case WM_NCLBUTTONDOWN:
-            case WM_NCLBUTTONUP:
-            case WM_NCMBUTTONDBLCLK:
-            case WM_NCMBUTTONDOWN:
-            case WM_NCMBUTTONUP:
-            case WM_NCMOUSEMOVE:
-            case WM_NCRBUTTONDBLCLK:
-            case WM_NCRBUTTONDOWN:
-            case WM_NCRBUTTONUP:
-            case WM_RBUTTONDBLCLK:
-            case WM_RBUTTONDOWN:
-            case WM_RBUTTONUP:
-                PostMessageA(pVideoRenderer->hWndMsgDrain, uMsg, wParam, lParam);
-                break;
-            default:
-                break;
-        }
-    }
-
-    switch(uMsg)
-    {
-        case WM_SIZING:
-            /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
-            SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
-            GetClientRect(hwnd, &pVideoRenderer->DestRect);
-            TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
-                pVideoRenderer->DestRect.left,
-                pVideoRenderer->DestRect.top,
-                pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
-                pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
-            return TRUE;
-        case WM_SIZE:
-            TRACE("WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
-            GetClientRect(hwnd, &pVideoRenderer->DestRect);
-            TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
-                pVideoRenderer->DestRect.left,
-                pVideoRenderer->DestRect.top,
-                pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
-                pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
-            return TRUE;
-        default:
-            return DefWindowProcA(hwnd, uMsg, wParam, lParam);
-    }
-    return 0;
+    return CONTAINING_RECORD(iface, VideoRendererImpl, baseControlWindow.baseWindow);
 }
 
-static BOOL CreateRenderingWindow(VideoRendererImpl* This)
+static inline VideoRendererImpl *impl_from_BaseRenderer(BaseRenderer *iface)
 {
-    WNDCLASSA winclass;
-
-    TRACE("(%p)->()\n", This);
-    
-    winclass.style = 0;
-    winclass.lpfnWndProc = VideoWndProcA;
-    winclass.cbClsExtra = 0;
-    winclass.cbWndExtra = sizeof(VideoRendererImpl*);
-    winclass.hInstance = NULL;
-    winclass.hIcon = NULL;
-    winclass.hCursor = NULL;
-    winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
-    winclass.lpszMenuName = NULL;
-    winclass.lpszClassName = "Wine ActiveMovie Class";
-
-    if (!wnd_class_registered)
-    {
-        if (!RegisterClassA(&winclass))
-        {
-            ERR("Unable to register window %u\n", GetLastError());
-            return FALSE;
-        }
-        wnd_class_registered = TRUE;
-    }
+    return CONTAINING_RECORD(iface, VideoRendererImpl, renderer);
+}
 
-    This->hWnd = CreateWindowExA(0, "Wine ActiveMovie Class", "Wine ActiveMovie Window", WS_SIZEBOX,
-                                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
-                                 NULL, NULL, NULL);
+static inline VideoRendererImpl *impl_from_IBaseFilter(IBaseFilter *iface)
+{
+    return CONTAINING_RECORD(iface, VideoRendererImpl, renderer.filter.IBaseFilter_iface);
+}
 
-    if (!This->hWnd)
-    {
-        ERR("Unable to create window\n");
-        return FALSE;
-    }
+static inline VideoRendererImpl *impl_from_IVideoWindow(IVideoWindow *iface)
+{
+    return CONTAINING_RECORD(iface, VideoRendererImpl, baseControlWindow.IVideoWindow_iface);
+}
 
-    SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
+static inline VideoRendererImpl *impl_from_BaseControlVideo(BaseControlVideo *iface)
+{
+    return CONTAINING_RECORD(iface, VideoRendererImpl, baseControlVideo);
+}
 
-    return TRUE;
+static inline VideoRendererImpl *impl_from_IBasicVideo(IBasicVideo *iface)
+{
+    return CONTAINING_RECORD(iface, VideoRendererImpl, baseControlVideo.IBasicVideo_iface);
 }
 
 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
@@ -210,7 +104,7 @@ static DWORD WINAPI MessageLoop(LPVOID lpParameter)
 
     TRACE("Starting message loop\n");
 
-    if (!CreateRenderingWindow(This))
+    if (FAILED(BaseWindowImpl_PrepareWindow(&This->baseControlWindow.baseWindow)))
     {
         This->ThreadResult = FALSE;
         SetEvent(This->hEvent);
@@ -220,10 +114,10 @@ static DWORD WINAPI MessageLoop(LPVOID lpParameter)
     This->ThreadResult = TRUE;
     SetEvent(This->hEvent);
 
-    while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1) 
+    while ((fGotMessage = GetMessageW(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
     {
         TranslateMessage(&msg); 
-        DispatchMessageA(&msg); 
+        DispatchMessageW(&msg);
     }
 
     TRACE("End of message loop\n");
@@ -256,18 +150,68 @@ static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
     return TRUE;
 }
 
+static void VideoRenderer_AutoShowWindow(VideoRendererImpl *This)
+{
+    if (!This->init && (!This->WindowPos.right || !This->WindowPos.top))
+    {
+        DWORD style = GetWindowLongW(This->baseControlWindow.baseWindow.hWnd, GWL_STYLE);
+        DWORD style_ex = GetWindowLongW(This->baseControlWindow.baseWindow.hWnd, GWL_EXSTYLE);
+
+        if (!This->WindowPos.right)
+        {
+            if (This->DestRect.right)
+            {
+                This->WindowPos.left = This->DestRect.left;
+                This->WindowPos.right = This->DestRect.right;
+            }
+            else
+            {
+                This->WindowPos.left = This->SourceRect.left;
+                This->WindowPos.right = This->SourceRect.right;
+            }
+        }
+        if (!This->WindowPos.bottom)
+        {
+            if (This->DestRect.bottom)
+            {
+                This->WindowPos.top = This->DestRect.top;
+                This->WindowPos.bottom = This->DestRect.bottom;
+            }
+            else
+            {
+                This->WindowPos.top = This->SourceRect.top;
+                This->WindowPos.bottom = This->SourceRect.bottom;
+            }
+        }
+
+        AdjustWindowRectEx(&This->WindowPos, style, FALSE, style_ex);
+
+        TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
+        SetWindowPos(This->baseControlWindow.baseWindow.hWnd, NULL,
+            This->WindowPos.left,
+            This->WindowPos.top,
+            This->WindowPos.right - This->WindowPos.left,
+            This->WindowPos.bottom - This->WindowPos.top,
+            SWP_NOZORDER|SWP_NOMOVE|SWP_DEFERERASE);
+
+        GetClientRect(This->baseControlWindow.baseWindow.hWnd, &This->DestRect);
+    }
+    else if (!This->init)
+        This->DestRect = This->WindowPos;
+    This->init = TRUE;
+    if (This->baseControlWindow.AutoShow)
+        ShowWindow(This->baseControlWindow.baseWindow.hWnd, SW_SHOW);
+}
+
 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
 {
     AM_MEDIA_TYPE amt;
     HRESULT hr = S_OK;
-    DDSURFACEDESC sdesc;
-    HDC hDC;
     BITMAPINFOHEADER *bmiHeader;
 
     TRACE("(%p)->(%p, %d)\n", This, data, size);
 
-    sdesc.dwSize = sizeof(sdesc);
-    hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
+    hr = IPin_ConnectionMediaType(&This->renderer.pInputPin->pin.IPin_iface, &amt);
     if (FAILED(hr)) {
         ERR("Unable to retrieve media type\n");
         return hr;
@@ -295,31 +239,7 @@ static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data,
     TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
     TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
 
-    if (!This->init)
-    {
-        DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
-        DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
-
-        if (!This->WindowPos.right || !This->WindowPos.bottom)
-            This->WindowPos = This->SourceRect;
-
-        AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);
-
-        TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
-        SetWindowPos(This->hWnd, NULL,
-            This->WindowPos.left,
-            This->WindowPos.top,
-            This->WindowPos.right - This->WindowPos.left,
-            This->WindowPos.bottom - This->WindowPos.top,
-            SWP_NOZORDER|SWP_NOMOVE);
-
-        GetClientRect(This->hWnd, &This->DestRect);
-        This->init = TRUE;
-    }
-
-    hDC = GetDC(This->hWnd);
-
-    if (!hDC) {
+    if (!This->baseControlWindow.baseWindow.hDC) {
         ERR("Cannot get DC from window!\n");
         return E_FAIL;
     }
@@ -327,69 +247,35 @@ static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data,
     TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
     TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
 
-    StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
+    StretchDIBits(This->baseControlWindow.baseWindow.hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
                   This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
                   This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
                   data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
 
-    ReleaseDC(This->hWnd, hDC);
-    if (This->AutoShow)
-        ShowWindow(This->hWnd, SW_SHOW);
-
     return S_OK;
 }
 
-static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
+static HRESULT WINAPI VideoRenderer_ShouldDrawSampleNow(BaseRenderer *This, IMediaSample *pSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime)
 {
-    VideoRendererImpl *This = iface;
+    /* Preroll means the sample isn't shown, this is used for key frames and things like that */
+    if (IMediaSample_IsPreroll(pSample) == S_OK)
+        return E_FAIL;
+    return S_FALSE;
+}
+
+static HRESULT WINAPI VideoRenderer_DoRenderSample(BaseRenderer* iface, IMediaSample * pSample)
+{
+    VideoRendererImpl *This = impl_from_BaseRenderer(iface);
     LPBYTE pbSrcStream = NULL;
     LONG cbSrcStream = 0;
-    REFERENCE_TIME tStart, tStop;
     HRESULT hr;
 
-    TRACE("(%p)->(%p)\n", iface, pSample);
-
-    EnterCriticalSection(&This->csFilter);
-
-    if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
-    {
-        LeaveCriticalSection(&This->csFilter);
-        return S_FALSE;
-    }
-
-    if (This->state == State_Stopped)
-    {
-        LeaveCriticalSection(&This->csFilter);
-        return VFW_E_WRONG_STATE;
-    }
-
-    hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
-    if (FAILED(hr))
-        ERR("Cannot get sample time (%x)\n", hr);
-
-    if (This->rtLastStop != tStart)
-    {
-        if (IMediaSample_IsDiscontinuity(pSample) == S_FALSE)
-            ERR("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
-                (DWORD)(This->rtLastStop / 10000000),
-                (DWORD)((This->rtLastStop / 10000)%1000),
-                (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
-        This->rtLastStop = tStart;
-    }
-
-    /* Preroll means the sample isn't shown, this is used for key frames and things like that */
-    if (IMediaSample_IsPreroll(pSample) == S_OK)
-    {
-        This->rtLastStop = tStop;
-        LeaveCriticalSection(&This->csFilter);
-        return S_OK;
-    }
+    TRACE("(%p)->(%p)\n", This, pSample);
 
     hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
     if (FAILED(hr))
     {
         ERR("Cannot get pointer to sample data (%x)\n", hr);
-        LeaveCriticalSection(&This->csFilter);
         return hr;
     }
 
@@ -411,68 +297,29 @@ static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
 #endif
 
     SetEvent(This->hEvent);
-    if (This->state == State_Paused)
+    if (This->renderer.filter.state == State_Paused)
     {
-        This->sample_held = pSample;
-        LeaveCriticalSection(&This->csFilter);
-        WaitForSingleObject(This->blocked, INFINITE);
-        EnterCriticalSection(&This->csFilter);
-        This->sample_held = NULL;
-        if (This->state == State_Paused)
+        VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
+        SetEvent(This->hEvent);
+        if (This->renderer.filter.state == State_Paused)
         {
             /* Flushing */
-            LeaveCriticalSection(&This->csFilter);
             return S_OK;
         }
-        if (This->state == State_Stopped)
+        if (This->renderer.filter.state == State_Stopped)
         {
-            LeaveCriticalSection(&This->csFilter);
             return VFW_E_WRONG_STATE;
         }
+    } else {
+        VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
     }
-
-    if (This->pClock && This->state == State_Running)
-    {
-        REFERENCE_TIME time, trefstart, trefstop;
-        LONG delta;
-
-        /* Perhaps I <SHOULD> use the reference clock AdviseTime function here
-         * I'm not going to! When I tried, it seemed to generate lag and
-         * it caused instability.
-         */
-        IReferenceClock_GetTime(This->pClock, &time);
-
-        trefstart = This->rtStreamStart;
-        trefstop = (REFERENCE_TIME)((double)(tStop - tStart) / This->pInputPin->dRate) + This->rtStreamStart;
-        delta = (LONG)((trefstart-time)/10000);
-        This->rtStreamStart = trefstop;
-        This->rtLastStop = tStop;
-
-        if (delta > 0)
-        {
-            TRACE("Sleeping for %u ms\n", delta);
-            Sleep(delta);
-        }
-        else if (time > trefstop)
-        {
-            TRACE("Dropping sample: Time: %u.%03u ms trefstop: %u.%03u ms!\n",
-                  (DWORD)(time / 10000000), (DWORD)((time / 10000)%1000),
-                  (DWORD)(trefstop / 10000000), (DWORD)((trefstop / 10000)%1000) );
-            This->rtLastStop = tStop;
-            LeaveCriticalSection(&This->csFilter);
-            return S_OK;
-        }
-    }
-    This->rtLastStop = tStop;
-
-    VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
-
-    LeaveCriticalSection(&This->csFilter);
     return S_OK;
 }
 
-static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
+static HRESULT WINAPI VideoRenderer_CheckMediaType(BaseRenderer *iface, const AM_MEDIA_TYPE * pmt)
 {
+    VideoRendererImpl *This = impl_from_BaseRenderer(iface);
+
     if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
         return S_FALSE;
 
@@ -481,7 +328,6 @@ static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt
         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
         IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
     {
-        VideoRendererImpl* This = iface;
         LONG height;
 
         if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
@@ -519,165 +365,322 @@ static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt
     return S_FALSE;
 }
 
-static inline VideoRendererImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
+static HRESULT WINAPI VideoRenderer_EndFlush(BaseRenderer* iface)
 {
-    return (VideoRendererImpl *)((char*)iface - FIELD_OFFSET(VideoRendererImpl, mediaSeeking.lpVtbl));
+    VideoRendererImpl *This = impl_from_BaseRenderer(iface);
+
+    TRACE("(%p)->()\n", iface);
+
+    if (This->renderer.pMediaSample) {
+        ResetEvent(This->hEvent);
+        LeaveCriticalSection(iface->pInputPin->pin.pCritSec);
+        LeaveCriticalSection(&iface->csRenderLock);
+        LeaveCriticalSection(&iface->filter.csFilter);
+        WaitForSingleObject(This->hEvent, INFINITE);
+        EnterCriticalSection(&iface->filter.csFilter);
+        EnterCriticalSection(&iface->csRenderLock);
+        EnterCriticalSection(iface->pInputPin->pin.pCritSec);
+    }
+    if (This->renderer.filter.state == State_Paused) {
+        ResetEvent(This->hEvent);
+    }
+
+    return BaseRendererImpl_EndFlush(iface);
 }
 
-static HRESULT WINAPI VideoRendererImpl_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
+static VOID WINAPI VideoRenderer_OnStopStreaming(BaseRenderer* iface)
 {
-    VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
+    VideoRendererImpl *This = impl_from_BaseRenderer(iface);
+
+    TRACE("(%p)->()\n", This);
 
-    return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
+    SetEvent(This->hEvent);
+    if (This->baseControlWindow.AutoShow)
+        /* Black it out */
+        RedrawWindow(This->baseControlWindow.baseWindow.hWnd, NULL, NULL, RDW_INVALIDATE|RDW_ERASE);
 }
 
-static ULONG WINAPI VideoRendererImpl_Seeking_AddRef(IMediaSeeking * iface)
+static VOID WINAPI VideoRenderer_OnStartStreaming(BaseRenderer* iface)
 {
-    VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
+    VideoRendererImpl *This = impl_from_BaseRenderer(iface);
 
-    return IUnknown_AddRef((IUnknown *)This);
+    TRACE("(%p)\n", This);
+
+    if (This->renderer.pInputPin->pin.pConnectedTo && (This->renderer.filter.state == State_Stopped || !This->renderer.pInputPin->end_of_stream))
+    {
+        if (This->renderer.filter.state == State_Stopped)
+        {
+            ResetEvent(This->hEvent);
+            VideoRenderer_AutoShowWindow(This);
+        }
+    }
 }
 
-static ULONG WINAPI VideoRendererImpl_Seeking_Release(IMediaSeeking * iface)
+static LPWSTR WINAPI VideoRenderer_GetClassWindowStyles(BaseWindow *This, DWORD *pClassStyles, DWORD *pWindowStyles, DWORD *pWindowStylesEx)
 {
-    VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
+    static const WCHAR classnameW[] = { 'W','i','n','e',' ','A','c','t','i','v','e','M','o','v','i','e',' ','C','l','a','s','s',0 };
 
-    return IUnknown_Release((IUnknown *)This);
+    *pClassStyles = 0;
+    *pWindowStyles = WS_SIZEBOX;
+    *pWindowStylesEx = 0;
+
+    return (LPWSTR)classnameW;
 }
 
-static const IMediaSeekingVtbl VideoRendererImpl_Seeking_Vtbl =
+static RECT WINAPI VideoRenderer_GetDefaultRect(BaseWindow *iface)
 {
-    VideoRendererImpl_Seeking_QueryInterface,
-    VideoRendererImpl_Seeking_AddRef,
-    VideoRendererImpl_Seeking_Release,
-    MediaSeekingImpl_GetCapabilities,
-    MediaSeekingImpl_CheckCapabilities,
-    MediaSeekingImpl_IsFormatSupported,
-    MediaSeekingImpl_QueryPreferredFormat,
-    MediaSeekingImpl_GetTimeFormat,
-    MediaSeekingImpl_IsUsingTimeFormat,
-    MediaSeekingImpl_SetTimeFormat,
-    MediaSeekingImpl_GetDuration,
-    MediaSeekingImpl_GetStopPosition,
-    MediaSeekingImpl_GetCurrentPosition,
-    MediaSeekingImpl_ConvertTimeFormat,
-    MediaSeekingImpl_SetPositions,
-    MediaSeekingImpl_GetPositions,
-    MediaSeekingImpl_GetAvailable,
-    MediaSeekingImpl_SetRate,
-    MediaSeekingImpl_GetRate,
-    MediaSeekingImpl_GetPreroll
-};
+    VideoRendererImpl *This = impl_from_BaseWindow(iface);
+    static RECT defRect;
 
-static HRESULT VideoRendererImpl_Change(IBaseFilter *iface)
-{
-    TRACE("(%p)->()\n", iface);
-    return S_OK;
+    defRect.left = defRect.top = 0;
+    defRect.right = This->VideoWidth;
+    defRect.bottom = This->VideoHeight;
+
+    return defRect;
 }
 
-HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
+static BOOL WINAPI VideoRenderer_OnSize(BaseWindow *iface, LONG Width, LONG Height)
 {
-    HRESULT hr;
-    PIN_INFO piInput;
-    VideoRendererImpl * pVideoRenderer;
+    VideoRendererImpl *This = impl_from_BaseWindow(iface);
+
+    TRACE("WM_SIZE %d %d\n", Width, Height);
+    GetClientRect(iface->hWnd, &This->DestRect);
+    TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
+        This->DestRect.left,
+        This->DestRect.top,
+        This->DestRect.right - This->DestRect.left,
+        This->DestRect.bottom - This->DestRect.top);
+    return BaseWindowImpl_OnSize(iface, Width, Height);
+}
+
+static const BaseRendererFuncTable BaseFuncTable = {
+    VideoRenderer_CheckMediaType,
+    VideoRenderer_DoRenderSample,
+    /**/
+    NULL,
+    NULL,
+    NULL,
+    VideoRenderer_OnStartStreaming,
+    VideoRenderer_OnStopStreaming,
+    NULL,
+    NULL,
+    NULL,
+    VideoRenderer_ShouldDrawSampleNow,
+    NULL,
+    /**/
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    VideoRenderer_EndFlush,
+};
 
-    TRACE("(%p, %p)\n", pUnkOuter, ppv);
+static const BaseWindowFuncTable renderer_BaseWindowFuncTable = {
+    VideoRenderer_GetClassWindowStyles,
+    VideoRenderer_GetDefaultRect,
+    NULL,
+    BaseControlWindowImpl_PossiblyEatMessage,
+    VideoRenderer_OnSize
+};
 
-    *ppv = NULL;
+static HRESULT WINAPI VideoRenderer_GetSourceRect(BaseControlVideo* iface, RECT *pSourceRect)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    CopyRect(pSourceRect,&This->SourceRect);
+    return S_OK;
+}
 
-    pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
-    pVideoRenderer->pUnkOuter = pUnkOuter;
-    pVideoRenderer->bUnkOuterValid = FALSE;
-    pVideoRenderer->bAggregatable = FALSE;
-    pVideoRenderer->IInner_vtbl = &IInner_VTable;
-
-    pVideoRenderer->lpVtbl = &VideoRenderer_Vtbl;
-    pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
-    pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
-    
-    pVideoRenderer->refCount = 1;
-    InitializeCriticalSection(&pVideoRenderer->csFilter);
-    pVideoRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter");
-    pVideoRenderer->state = State_Stopped;
-    pVideoRenderer->pClock = NULL;
-    pVideoRenderer->init = 0;
-    pVideoRenderer->AutoShow = 1;
-    pVideoRenderer->rtLastStop = -1;
-    ZeroMemory(&pVideoRenderer->filterInfo, sizeof(FILTER_INFO));
-    ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
-    ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
-    ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
-    pVideoRenderer->hWndMsgDrain = NULL;
+static HRESULT WINAPI VideoRenderer_GetStaticImage(BaseControlVideo* iface, LONG *pBufferSize, LONG *pDIBImage)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    BITMAPINFOHEADER *bmiHeader;
+    LONG needed_size;
+    AM_MEDIA_TYPE *amt = &This->renderer.pInputPin->pin.mtCurrent;
+    char *ptr;
 
-    /* construct input pin */
-    piInput.dir = PINDIR_INPUT;
-    piInput.pFilter = (IBaseFilter *)pVideoRenderer;
-    lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
+    FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
 
-    hr = InputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, VideoRenderer_Sample, (LPVOID)pVideoRenderer, VideoRenderer_QueryAccept, NULL, &pVideoRenderer->csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
+    EnterCriticalSection(&This->renderer.filter.csFilter);
 
-    if (SUCCEEDED(hr))
+    if (!This->renderer.pMediaSample)
     {
-        MediaSeekingImpl_Init((IBaseFilter*)pVideoRenderer, VideoRendererImpl_Change, VideoRendererImpl_Change, VideoRendererImpl_Change, &pVideoRenderer->mediaSeeking, &pVideoRenderer->csFilter);
-        pVideoRenderer->mediaSeeking.lpVtbl = &VideoRendererImpl_Seeking_Vtbl;
+         LeaveCriticalSection(&This->renderer.filter.csFilter);
+         return (This->renderer.filter.state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
+    }
 
-        pVideoRenderer->sample_held = NULL;
-        *ppv = pVideoRenderer;
+    if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
+    {
+        bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
+    }
+    else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
+    {
+        bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
     }
     else
     {
-        pVideoRenderer->csFilter.DebugInfo->Spare[0] = 0;
-        DeleteCriticalSection(&pVideoRenderer->csFilter);
-        CoTaskMemFree(pVideoRenderer);
+        FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
+        LeaveCriticalSection(&This->renderer.filter.csFilter);
+        return VFW_E_RUNTIME_ERROR;
     }
 
-    if (!CreateRenderingSubsystem(pVideoRenderer))
-        return E_FAIL;
+    needed_size = bmiHeader->biSize;
+    needed_size += IMediaSample_GetActualDataLength(This->renderer.pMediaSample);
 
-    pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
-    if (!pVideoRenderer->blocked)
+    if (!pDIBImage)
     {
-        hr = HRESULT_FROM_WIN32(GetLastError());
-        IUnknown_Release((IUnknown *)pVideoRenderer);
+        *pBufferSize = needed_size;
+        LeaveCriticalSection(&This->renderer.filter.csFilter);
+        return S_OK;
     }
 
-    return hr;
+    if (needed_size < *pBufferSize)
+    {
+        ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
+        LeaveCriticalSection(&This->renderer.filter.csFilter);
+        return E_FAIL;
+    }
+    *pBufferSize = needed_size;
+
+    memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
+    IMediaSample_GetPointer(This->renderer.pMediaSample, (BYTE **)&ptr);
+    memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->renderer.pMediaSample));
+
+    LeaveCriticalSection(&This->renderer.filter.csFilter);
+    return S_OK;
 }
 
-HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
+static HRESULT WINAPI VideoRenderer_GetTargetRect(BaseControlVideo* iface, RECT *pTargetRect)
 {
-    /* TODO: Attempt to use the VMR-7 renderer instead when possible */
-    return VideoRenderer_create(pUnkOuter, ppv);
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    CopyRect(pTargetRect,&This->DestRect);
+    return S_OK;
 }
 
-static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
+static VIDEOINFOHEADER* WINAPI VideoRenderer_GetVideoFormat(BaseControlVideo* iface)
 {
-    ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
-    TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    AM_MEDIA_TYPE *pmt;
+
+    TRACE("(%p/%p)\n", This, iface);
+
+    pmt = &This->renderer.pInputPin->pin.mtCurrent;
+    if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
+        return (VIDEOINFOHEADER*)pmt->pbFormat;
+    } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
+        static VIDEOINFOHEADER vih;
+        VIDEOINFOHEADER2 *vih2 = (VIDEOINFOHEADER2*)pmt->pbFormat;
+        memcpy(&vih,vih2,sizeof(VIDEOINFOHEADER));
+        memcpy(&vih.bmiHeader, &vih2->bmiHeader, sizeof(BITMAPINFOHEADER));
+        return &vih;
+    } else {
+        ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
+        return NULL;
+    }
+}
+
+static HRESULT WINAPI VideoRenderer_IsDefaultSourceRect(BaseControlVideo* iface)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    FIXME("(%p/%p)->(): stub !!!\n", This, iface);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI VideoRenderer_IsDefaultTargetRect(BaseControlVideo* iface)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    FIXME("(%p/%p)->(): stub !!!\n", This, iface);
 
-    if (This->bAggregatable)
-        This->bUnkOuterValid = TRUE;
+    return S_OK;
+}
+
+static HRESULT WINAPI VideoRenderer_SetDefaultSourceRect(BaseControlVideo* iface)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+
+    This->SourceRect.left = 0;
+    This->SourceRect.top = 0;
+    This->SourceRect.right = This->VideoWidth;
+    This->SourceRect.bottom = This->VideoHeight;
+
+    return S_OK;
+}
+
+static HRESULT WINAPI VideoRenderer_SetDefaultTargetRect(BaseControlVideo* iface)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    RECT rect;
+
+    if (!GetClientRect(This->baseControlWindow.baseWindow.hWnd, &rect))
+        return E_FAIL;
+
+    This->DestRect.left = 0;
+    This->DestRect.top = 0;
+    This->DestRect.right = rect.right;
+    This->DestRect.bottom = rect.bottom;
+
+    return S_OK;
+}
+
+static HRESULT WINAPI VideoRenderer_SetSourceRect(BaseControlVideo* iface, RECT *pSourceRect)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    CopyRect(&This->SourceRect,pSourceRect);
+    return S_OK;
+}
+
+static HRESULT WINAPI VideoRenderer_SetTargetRect(BaseControlVideo* iface, RECT *pTargetRect)
+{
+    VideoRendererImpl *This = impl_from_BaseControlVideo(iface);
+    CopyRect(&This->DestRect,pTargetRect);
+    return S_OK;
+}
+
+static const BaseControlVideoFuncTable renderer_BaseControlVideoFuncTable = {
+    VideoRenderer_GetSourceRect,
+    VideoRenderer_GetStaticImage,
+    VideoRenderer_GetTargetRect,
+    VideoRenderer_GetVideoFormat,
+    VideoRenderer_IsDefaultSourceRect,
+    VideoRenderer_IsDefaultTargetRect,
+    VideoRenderer_SetDefaultSourceRect,
+    VideoRenderer_SetDefaultTargetRect,
+    VideoRenderer_SetSourceRect,
+    VideoRenderer_SetTargetRect
+};
+
+static inline VideoRendererImpl *impl_from_IUnknown(IUnknown *iface)
+{
+    return CONTAINING_RECORD(iface, VideoRendererImpl, IUnknown_inner);
+}
+
+static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
+{
+    VideoRendererImpl *This = impl_from_IUnknown(iface);
+
+    TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
 
     *ppv = NULL;
 
     if (IsEqualIID(riid, &IID_IUnknown))
-        *ppv = &This->IInner_vtbl;
-    else if (IsEqualIID(riid, &IID_IPersist))
-        *ppv = This;
-    else if (IsEqualIID(riid, &IID_IMediaFilter))
-        *ppv = This;
-    else if (IsEqualIID(riid, &IID_IBaseFilter))
-        *ppv = This;
+        *ppv = &This->IUnknown_inner;
     else if (IsEqualIID(riid, &IID_IBasicVideo))
-        *ppv = &This->IBasicVideo_vtbl;
+        *ppv = &This->baseControlVideo.IBasicVideo_iface;
     else if (IsEqualIID(riid, &IID_IVideoWindow))
-        *ppv = &This->IVideoWindow_vtbl;
-    else if (IsEqualIID(riid, &IID_IMediaSeeking))
-        *ppv = &This->mediaSeeking;
+        *ppv = &This->baseControlWindow.IVideoWindow_iface;
+    else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
+        *ppv = &This->IAMFilterMiscFlags_iface;
+    else
+    {
+        HRESULT hr;
+        hr = BaseRendererImpl_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppv);
+        if (SUCCEEDED(hr))
+            return hr;
+    }
 
     if (*ppv)
     {
-        IUnknown_AddRef((IUnknown *)(*ppv));
+        IUnknown_AddRef((IUnknown *)*ppv);
         return S_OK;
     }
 
@@ -687,53 +690,35 @@ static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
+static ULONG WINAPI VideoRendererInner_AddRef(IUnknown *iface)
 {
-    ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
-    ULONG refCount = InterlockedIncrement(&This->refCount);
+    VideoRendererImpl *This = impl_from_IUnknown(iface);
+    ULONG refCount = BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
 
-    TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
+    TRACE("(%p)->(): new ref = %d\n", This, refCount);
 
     return refCount;
 }
 
-static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
+static ULONG WINAPI VideoRendererInner_Release(IUnknown *iface)
 {
-    ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
-    ULONG refCount = InterlockedDecrement(&This->refCount);
+    VideoRendererImpl *This = impl_from_IUnknown(iface);
+    ULONG refCount = BaseRendererImpl_Release(&This->renderer.filter.IBaseFilter_iface);
 
-    TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
+    TRACE("(%p)->(): new ref = %d\n", This, refCount);
 
     if (!refCount)
     {
-        IPin *pConnectedTo;
-
-        DestroyWindow(This->hWnd);
-        PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
+        BaseControlWindow_Destroy(&This->baseControlWindow);
+        BaseControlVideo_Destroy(&This->baseControlVideo);
+        PostThreadMessageW(This->ThreadID, WM_QUIT, 0, 0);
         WaitForSingleObject(This->hThread, INFINITE);
         CloseHandle(This->hThread);
         CloseHandle(This->hEvent);
 
-        if (This->pClock)
-            IReferenceClock_Release(This->pClock);
-        
-        if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
-        {
-            IPin_Disconnect(pConnectedTo);
-            IPin_Release(pConnectedTo);
-        }
-        IPin_Disconnect((IPin *)This->pInputPin);
-
-        IPin_Release((IPin *)This->pInputPin);
-
-        This->lpVtbl = NULL;
-        
-        This->csFilter.DebugInfo->Spare[0] = 0;
-        DeleteCriticalSection(&This->csFilter);
-
         TRACE("Destroying Video Renderer\n");
         CoTaskMemFree(This);
-        
+
         return 0;
     }
     else
@@ -749,1521 +734,348 @@ static const IUnknownVtbl IInner_VTable =
 
 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
 {
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    if (This->bAggregatable)
-        This->bUnkOuterValid = TRUE;
-
-    if (This->pUnkOuter)
-    {
-        if (This->bAggregatable)
-            return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
-
-        if (IsEqualIID(riid, &IID_IUnknown))
-        {
-            HRESULT hr;
-
-            IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
-            hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
-            IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
-            This->bAggregatable = TRUE;
-            return hr;
-        }
-
-        *ppv = NULL;
-        return E_NOINTERFACE;
-    }
-
-    return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
+    VideoRendererImpl *This = impl_from_IBaseFilter(iface);
+    return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
 }
 
 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
 {
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    if (This->pUnkOuter && This->bUnkOuterValid)
-        return IUnknown_AddRef(This->pUnkOuter);
-    return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
+    VideoRendererImpl *This = impl_from_IBaseFilter(iface);
+    return IUnknown_AddRef(This->outer_unk);
 }
 
 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
 {
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    if (This->pUnkOuter && This->bUnkOuterValid)
-        return IUnknown_Release(This->pUnkOuter);
-    return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
+    VideoRendererImpl *This = impl_from_IBaseFilter(iface);
+    return IUnknown_Release(This->outer_unk);
 }
 
-/** IPersist methods **/
+/** IMediaFilter methods **/
 
-static HRESULT WINAPI VideoRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
+static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
 {
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
+    VideoRendererImpl *This = impl_from_IBaseFilter(iface);
 
-    *pClsid = CLSID_VideoRenderer;
+    TRACE("(%p/%p)->()\n", This, iface);
 
-    return S_OK;
-}
-
-/** IMediaFilter methods **/
-
-static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->()\n", This, iface);
-
-    EnterCriticalSection(&This->csFilter);
-    {
-        This->state = State_Stopped;
-        SetEvent(This->hEvent);
-        SetEvent(This->blocked);
-    }
-    LeaveCriticalSection(&This->csFilter);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-    
-    TRACE("(%p/%p)->()\n", This, iface);
-
-    EnterCriticalSection(&This->csFilter);
-    if (This->state != State_Paused)
-    {
-        if (This->state == State_Stopped)
-        {
-            This->pInputPin->end_of_stream = 0;
-            ResetEvent(This->hEvent);
-        }
-
-        This->state = State_Paused;
-        ResetEvent(This->blocked);
-    }
-    LeaveCriticalSection(&This->csFilter);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
-
-    EnterCriticalSection(&This->csFilter);
-    if (This->state != State_Running)
+    EnterCriticalSection(&This->renderer.csRenderLock);
+    if (This->renderer.filter.state != State_Paused)
     {
-        if (This->state == State_Stopped)
+        if (This->renderer.filter.state == State_Stopped)
         {
-            This->pInputPin->end_of_stream = 0;
+            This->renderer.pInputPin->end_of_stream = 0;
             ResetEvent(This->hEvent);
+            VideoRenderer_AutoShowWindow(This);
         }
-        SetEvent(This->blocked);
-
-        This->rtStreamStart = tStart;
-        This->state = State_Running;
-    }
-    LeaveCriticalSection(&This->csFilter);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-    HRESULT hr;
-
-    TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
-
-    if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
-        hr = VFW_S_STATE_INTERMEDIATE;
-    else
-        hr = S_OK;
-
-    EnterCriticalSection(&This->csFilter);
-    {
-        *pState = This->state;
-    }
-    LeaveCriticalSection(&This->csFilter);
-
-    return hr;
-}
-
-static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
-
-    EnterCriticalSection(&This->csFilter);
-    {
-        if (This->pClock)
-            IReferenceClock_Release(This->pClock);
-        This->pClock = pClock;
-        if (This->pClock)
-            IReferenceClock_AddRef(This->pClock);
-    }
-    LeaveCriticalSection(&This->csFilter);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI VideoRenderer_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
-
-    EnterCriticalSection(&This->csFilter);
-    {
-        *ppClock = This->pClock;
-        if (This->pClock)
-            IReferenceClock_AddRef(This->pClock);
-    }
-    LeaveCriticalSection(&This->csFilter);
-    
-    return S_OK;
-}
-
-/** IBaseFilter implementation **/
-
-static HRESULT VideoRenderer_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    /* Our pins are static, not changing so setting static tick count is ok */
-    *lastsynctick = 0;
-
-    if (pos >= 1)
-        return S_FALSE;
-
-    *pin = (IPin *)This->pInputPin;
-    IPin_AddRef(*pin);
-    return S_OK;
-}
-
-static HRESULT WINAPI VideoRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
-
-    return IEnumPinsImpl_Construct(ppEnum, VideoRenderer_GetPin, iface);
-}
-
-static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
-
-    /* FIXME: critical section */
-
-    return E_NOTIMPL;
-}
-
-static HRESULT WINAPI VideoRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
-
-    strcpyW(pInfo->achName, This->filterInfo.achName);
-    pInfo->pGraph = This->filterInfo.pGraph;
-
-    if (pInfo->pGraph)
-        IFilterGraph_AddRef(pInfo->pGraph);
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI VideoRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-
-    TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
 
-    EnterCriticalSection(&This->csFilter);
-    {
-        if (pName)
-            strcpyW(This->filterInfo.achName, pName);
-        else
-            *This->filterInfo.achName = '\0';
-        This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
+        ResetEvent(This->renderer.RenderEvent);
+        This->renderer.filter.state = State_Paused;
     }
-    LeaveCriticalSection(&This->csFilter);
+    LeaveCriticalSection(&This->renderer.csRenderLock);
 
     return S_OK;
 }
 
-static HRESULT WINAPI VideoRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
-{
-    VideoRendererImpl *This = (VideoRendererImpl *)iface;
-    TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
-    return E_NOTIMPL;
-}
-
 static const IBaseFilterVtbl VideoRenderer_Vtbl =
 {
     VideoRenderer_QueryInterface,
     VideoRenderer_AddRef,
     VideoRenderer_Release,
-    VideoRenderer_GetClassID,
-    VideoRenderer_Stop,
+    BaseFilterImpl_GetClassID,
+    BaseRendererImpl_Stop,
     VideoRenderer_Pause,
-    VideoRenderer_Run,
-    VideoRenderer_GetState,
-    VideoRenderer_SetSyncSource,
-    VideoRenderer_GetSyncSource,
-    VideoRenderer_EnumPins,
-    VideoRenderer_FindPin,
-    VideoRenderer_QueryFilterInfo,
-    VideoRenderer_JoinFilterGraph,
-    VideoRenderer_QueryVendorInfo
+    BaseRendererImpl_Run,
+    BaseRendererImpl_GetState,
+    BaseRendererImpl_SetSyncSource,
+    BaseFilterImpl_GetSyncSource,
+    BaseFilterImpl_EnumPins,
+    BaseRendererImpl_FindPin,
+    BaseFilterImpl_QueryFilterInfo,
+    BaseFilterImpl_JoinFilterGraph,
+    BaseFilterImpl_QueryVendorInfo
 };
 
-static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
+/*** IUnknown methods ***/
+static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo *iface, REFIID riid, LPVOID *ppvObj)
 {
-    InputPin* This = (InputPin*)iface;
-    IMediaEventSink* pEventSink;
-    HRESULT hr;
-
-    TRACE("(%p/%p)->()\n", This, iface);
+    VideoRendererImpl *This = impl_from_IBasicVideo(iface);
 
-    hr = IFilterGraph_QueryInterface(((VideoRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
-    if (SUCCEEDED(hr))
-    {
-        hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
-        IMediaEventSink_Release(pEventSink);
-    }
+    TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
 
-    return hr;
+    return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
 }
 
-static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
+static ULONG WINAPI BasicVideo_AddRef(IBasicVideo *iface)
 {
-    InputPin* This = (InputPin*)iface;
-    VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
-    HRESULT hr;
+    VideoRendererImpl *This = impl_from_IBasicVideo(iface);
 
     TRACE("(%p/%p)->()\n", This, iface);
 
-    EnterCriticalSection(This->pin.pCritSec);
-    if (pVideoRenderer->state == State_Paused)
-        SetEvent(pVideoRenderer->blocked);
-
-    hr = InputPin_BeginFlush(iface);
-    LeaveCriticalSection(This->pin.pCritSec);
-
-    return hr;
+    return IUnknown_AddRef(This->outer_unk);
 }
 
-static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
+static ULONG WINAPI BasicVideo_Release(IBasicVideo *iface)
 {
-    InputPin* This = (InputPin*)iface;
-    VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
-    HRESULT hr;
+    VideoRendererImpl *This = impl_from_IBasicVideo(iface);
 
     TRACE("(%p/%p)->()\n", This, iface);
 
-    EnterCriticalSection(This->pin.pCritSec);
-    if (pVideoRenderer->state == State_Paused)
-        ResetEvent(pVideoRenderer->blocked);
-
-    hr = InputPin_EndFlush(iface);
-    LeaveCriticalSection(This->pin.pCritSec);
-
-    return hr;
+    return IUnknown_Release(This->outer_unk);
 }
 
-static const IPinVtbl VideoRenderer_InputPin_Vtbl = 
+static const IBasicVideoVtbl IBasicVideo_VTable =
 {
-    InputPin_QueryInterface,
-    IPinImpl_AddRef,
-    InputPin_Release,
-    InputPin_Connect,
-    InputPin_ReceiveConnection,
-    IPinImpl_Disconnect,
-    IPinImpl_ConnectedTo,
-    IPinImpl_ConnectionMediaType,
-    IPinImpl_QueryPinInfo,
-    IPinImpl_QueryDirection,
-    IPinImpl_QueryId,
-    IPinImpl_QueryAccept,
-    IPinImpl_EnumMediaTypes,
-    IPinImpl_QueryInternalConnections,
-    VideoRenderer_InputPin_EndOfStream,
-    VideoRenderer_InputPin_BeginFlush,
-    VideoRenderer_InputPin_EndFlush,
-    InputPin_NewSegment
+    BasicVideo_QueryInterface,
+    BasicVideo_AddRef,
+    BasicVideo_Release,
+    BaseControlVideoImpl_GetTypeInfoCount,
+    BaseControlVideoImpl_GetTypeInfo,
+    BaseControlVideoImpl_GetIDsOfNames,
+    BaseControlVideoImpl_Invoke,
+    BaseControlVideoImpl_get_AvgTimePerFrame,
+    BaseControlVideoImpl_get_BitRate,
+    BaseControlVideoImpl_get_BitErrorRate,
+    BaseControlVideoImpl_get_VideoWidth,
+    BaseControlVideoImpl_get_VideoHeight,
+    BaseControlVideoImpl_put_SourceLeft,
+    BaseControlVideoImpl_get_SourceLeft,
+    BaseControlVideoImpl_put_SourceWidth,
+    BaseControlVideoImpl_get_SourceWidth,
+    BaseControlVideoImpl_put_SourceTop,
+    BaseControlVideoImpl_get_SourceTop,
+    BaseControlVideoImpl_put_SourceHeight,
+    BaseControlVideoImpl_get_SourceHeight,
+    BaseControlVideoImpl_put_DestinationLeft,
+    BaseControlVideoImpl_get_DestinationLeft,
+    BaseControlVideoImpl_put_DestinationWidth,
+    BaseControlVideoImpl_get_DestinationWidth,
+    BaseControlVideoImpl_put_DestinationTop,
+    BaseControlVideoImpl_get_DestinationTop,
+    BaseControlVideoImpl_put_DestinationHeight,
+    BaseControlVideoImpl_get_DestinationHeight,
+    BaseControlVideoImpl_SetSourcePosition,
+    BaseControlVideoImpl_GetSourcePosition,
+    BaseControlVideoImpl_SetDefaultSourcePosition,
+    BaseControlVideoImpl_SetDestinationPosition,
+    BaseControlVideoImpl_GetDestinationPosition,
+    BaseControlVideoImpl_SetDefaultDestinationPosition,
+    BaseControlVideoImpl_GetVideoSize,
+    BaseControlVideoImpl_GetVideoPaletteEntries,
+    BaseControlVideoImpl_GetCurrentImage,
+    BaseControlVideoImpl_IsUsingDefaultSource,
+    BaseControlVideoImpl_IsUsingDefaultDestination
 };
 
+
 /*** IUnknown methods ***/
-static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
-                                               REFIID riid,
-                                               LPVOID*ppvObj) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, LPVOID *ppvObj)
+{
+    VideoRendererImpl *This = impl_from_IVideoWindow(iface);
 
     TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
 
-    return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
+    return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
 }
 
-static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
+{
+    VideoRendererImpl *This = impl_from_IVideoWindow(iface);
 
     TRACE("(%p/%p)->()\n", This, iface);
 
-    return VideoRenderer_AddRef((IBaseFilter*)This);
+    return IUnknown_AddRef(This->outer_unk);
 }
 
-static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
+{
+    VideoRendererImpl *This = impl_from_IVideoWindow(iface);
 
     TRACE("(%p/%p)->()\n", This, iface);
 
-    return VideoRenderer_Release((IBaseFilter*)This);
-}
-
-/*** IDispatch methods ***/
-static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
-                                                 UINT*pctinfo) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
-                                            UINT iTInfo,
-                                            LCID lcid,
-                                            ITypeInfo**ppTInfo) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
-                                              REFIID riid,
-                                              LPOLESTR*rgszNames,
-                                              UINT cNames,
-                                              LCID lcid,
-                                              DISPID*rgDispId) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
-
-    return S_OK;
+    return IUnknown_Release(This->outer_unk);
 }
 
-static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
-                                       DISPID dispIdMember,
-                                       REFIID riid,
-                                       LCID lcid,
-                                       WORD wFlags,
-                                       DISPPARAMS*pDispParams,
-                                       VARIANT*pVarResult,
-                                       EXCEPINFO*pExepInfo,
-                                       UINT*puArgErr) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface,
+                                                     LONG *FullScreenMode)
+{
+    VideoRendererImpl *This = impl_from_IVideoWindow(iface);
 
-    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);
+    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
 
     return S_OK;
 }
 
-/*** IBasicVideo methods ***/
-static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
-                                                    REFTIME *pAvgTimePerFrame) {
-    AM_MEDIA_TYPE *pmt;
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    if (!This->pInputPin->pin.pConnectedTo)
-        return VFW_E_NOT_CONNECTED;
+static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface,
+                                                     LONG FullScreenMode)
+{
+    VideoRendererImpl *This = impl_from_IVideoWindow(iface);
 
-    TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
+    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
 
-    pmt = &This->pInputPin->pin.mtCurrent;
-    if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
-        VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)pmt->pbFormat;
-        *pAvgTimePerFrame = vih->AvgTimePerFrame;
-    } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
-        VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)pmt->pbFormat;
-        *pAvgTimePerFrame = vih->AvgTimePerFrame;
+    if (FullScreenMode) {
+        This->baseControlWindow.baseWindow.WindowStyles = GetWindowLongW(This->baseControlWindow.baseWindow.hWnd, GWL_STYLE);
+        ShowWindow(This->baseControlWindow.baseWindow.hWnd, SW_HIDE);
+        SetParent(This->baseControlWindow.baseWindow.hWnd, 0);
+        SetWindowLongW(This->baseControlWindow.baseWindow.hWnd, GWL_STYLE, WS_POPUP);
+        SetWindowPos(This->baseControlWindow.baseWindow.hWnd,HWND_TOP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SWP_SHOWWINDOW);
+        GetWindowRect(This->baseControlWindow.baseWindow.hWnd, &This->DestRect);
+        This->WindowPos = This->DestRect;
     } else {
-        ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
-        *pAvgTimePerFrame = 0;
+        ShowWindow(This->baseControlWindow.baseWindow.hWnd, SW_HIDE);
+        SetParent(This->baseControlWindow.baseWindow.hWnd, This->baseControlWindow.hwndOwner);
+        SetWindowLongW(This->baseControlWindow.baseWindow.hWnd, GWL_STYLE, This->baseControlWindow.baseWindow.WindowStyles);
+        GetClientRect(This->baseControlWindow.baseWindow.hWnd, &This->DestRect);
+        SetWindowPos(This->baseControlWindow.baseWindow.hWnd,0,This->DestRect.left,This->DestRect.top,This->DestRect.right,This->DestRect.bottom,SWP_NOZORDER|SWP_SHOWWINDOW);
+        This->WindowPos = This->DestRect;
     }
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
-                                             LONG *pBitRate) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
-                                                  LONG *pBitErrorRate) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
-                                                LONG *pVideoWidth) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
 
-    *pVideoWidth = This->VideoWidth;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
-                                                 LONG *pVideoHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
-
-    *pVideoHeight = This->VideoHeight;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
-                                                LONG SourceLeft) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
-
-    This->SourceRect.left = SourceLeft;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
-                                                LONG *pSourceLeft) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
-
-    *pSourceLeft = This->SourceRect.left;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
-                                                 LONG SourceWidth) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
-
-    This->SourceRect.right = This->SourceRect.left + SourceWidth;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
-                                                 LONG *pSourceWidth) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
-
-    *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
-    
     return S_OK;
 }
 
-static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
-                                               LONG SourceTop) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
-
-    This->SourceRect.top = SourceTop;
+static const IVideoWindowVtbl IVideoWindow_VTable =
+{
+    VideoWindow_QueryInterface,
+    VideoWindow_AddRef,
+    VideoWindow_Release,
+    BaseControlWindowImpl_GetTypeInfoCount,
+    BaseControlWindowImpl_GetTypeInfo,
+    BaseControlWindowImpl_GetIDsOfNames,
+    BaseControlWindowImpl_Invoke,
+    BaseControlWindowImpl_put_Caption,
+    BaseControlWindowImpl_get_Caption,
+    BaseControlWindowImpl_put_WindowStyle,
+    BaseControlWindowImpl_get_WindowStyle,
+    BaseControlWindowImpl_put_WindowStyleEx,
+    BaseControlWindowImpl_get_WindowStyleEx,
+    BaseControlWindowImpl_put_AutoShow,
+    BaseControlWindowImpl_get_AutoShow,
+    BaseControlWindowImpl_put_WindowState,
+    BaseControlWindowImpl_get_WindowState,
+    BaseControlWindowImpl_put_BackgroundPalette,
+    BaseControlWindowImpl_get_BackgroundPalette,
+    BaseControlWindowImpl_put_Visible,
+    BaseControlWindowImpl_get_Visible,
+    BaseControlWindowImpl_put_Left,
+    BaseControlWindowImpl_get_Left,
+    BaseControlWindowImpl_put_Width,
+    BaseControlWindowImpl_get_Width,
+    BaseControlWindowImpl_put_Top,
+    BaseControlWindowImpl_get_Top,
+    BaseControlWindowImpl_put_Height,
+    BaseControlWindowImpl_get_Height,
+    BaseControlWindowImpl_put_Owner,
+    BaseControlWindowImpl_get_Owner,
+    BaseControlWindowImpl_put_MessageDrain,
+    BaseControlWindowImpl_get_MessageDrain,
+    BaseControlWindowImpl_get_BorderColor,
+    BaseControlWindowImpl_put_BorderColor,
+    VideoWindow_get_FullScreenMode,
+    VideoWindow_put_FullScreenMode,
+    BaseControlWindowImpl_SetWindowForeground,
+    BaseControlWindowImpl_NotifyOwnerMessage,
+    BaseControlWindowImpl_SetWindowPosition,
+    BaseControlWindowImpl_GetWindowPosition,
+    BaseControlWindowImpl_GetMinIdealImageSize,
+    BaseControlWindowImpl_GetMaxIdealImageSize,
+    BaseControlWindowImpl_GetRestorePosition,
+    BaseControlWindowImpl_HideCursor,
+    BaseControlWindowImpl_IsCursorHidden
+};
 
-    return S_OK;
+static VideoRendererImpl *impl_from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface)
+{
+    return CONTAINING_RECORD(iface, VideoRendererImpl, IAMFilterMiscFlags_iface);
 }
 
-static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
-                                               LONG *pSourceTop) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
-
-    *pSourceTop = This->SourceRect.top;
-
-    return S_OK;
+static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, REFIID riid,
+        void **ppv)
+{
+    VideoRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
+    return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
 }
 
-static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
-                                                  LONG SourceHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
-
-    This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
-
-    return S_OK;
+static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface)
+{
+    VideoRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
+    return IUnknown_AddRef(This->outer_unk);
 }
 
-static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
-                                                  LONG *pSourceHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
-
-    *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
-
-    return S_OK;
+static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface)
+{
+    VideoRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
+    return IUnknown_Release(This->outer_unk);
 }
 
-static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
-                                                     LONG DestinationLeft) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
-
-    This->DestRect.left = DestinationLeft;
-
-    return S_OK;
+static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface)
+{
+    return AM_FILTER_MISC_FLAGS_IS_RENDERER;
 }
 
-static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
-                                                     LONG *pDestinationLeft) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
-
-    *pDestinationLeft = This->DestRect.left;
+static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
+    AMFilterMiscFlags_QueryInterface,
+    AMFilterMiscFlags_AddRef,
+    AMFilterMiscFlags_Release,
+    AMFilterMiscFlags_GetMiscFlags
+};
 
-    return S_OK;
-}
+HRESULT VideoRenderer_create(IUnknown *pUnkOuter, void **ppv)
+{
+    HRESULT hr;
+    VideoRendererImpl * pVideoRenderer;
 
-static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
-                                                      LONG DestinationWidth) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+    TRACE("(%p, %p)\n", pUnkOuter, ppv);
 
-    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
+    *ppv = NULL;
 
-    This->DestRect.right = This->DestRect.left + DestinationWidth;
+    pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
+    pVideoRenderer->IUnknown_inner.lpVtbl = &IInner_VTable;
+    pVideoRenderer->IAMFilterMiscFlags_iface.lpVtbl = &IAMFilterMiscFlags_Vtbl;
 
-    return S_OK;
-}
+    pVideoRenderer->init = 0;
+    ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
+    ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
+    ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
 
-static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
-                                                      LONG *pDestinationWidth) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+    if (pUnkOuter)
+        pVideoRenderer->outer_unk = pUnkOuter;
+    else
+        pVideoRenderer->outer_unk = &pVideoRenderer->IUnknown_inner;
 
-    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
+    hr = BaseRenderer_Init(&pVideoRenderer->renderer, &VideoRenderer_Vtbl, pUnkOuter,
+            &CLSID_VideoRenderer, (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter"),
+            &BaseFuncTable);
 
-    *pDestinationWidth = This->DestRect.right - This->DestRect.left;
+    if (FAILED(hr))
+        goto fail;
 
-    return S_OK;
-}
+    hr = BaseControlWindow_Init(&pVideoRenderer->baseControlWindow, &IVideoWindow_VTable,
+            &pVideoRenderer->renderer.filter, &pVideoRenderer->renderer.filter.csFilter,
+            &pVideoRenderer->renderer.pInputPin->pin, &renderer_BaseWindowFuncTable);
+    if (FAILED(hr))
+        goto fail;
 
-static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
-                                                    LONG DestinationTop) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
+    hr = BaseControlVideo_Init(&pVideoRenderer->baseControlVideo, &IBasicVideo_VTable,
+            &pVideoRenderer->renderer.filter, &pVideoRenderer->renderer.filter.csFilter,
+            &pVideoRenderer->renderer.pInputPin->pin, &renderer_BaseControlVideoFuncTable);
+    if (FAILED(hr))
+        goto fail;
 
-    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
+    if (!CreateRenderingSubsystem(pVideoRenderer)) {
+        hr = E_FAIL;
+        goto fail;
+    }
 
-    This->DestRect.top = DestinationTop;
-    
+    *ppv = &pVideoRenderer->IUnknown_inner;
     return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
-                                                    LONG *pDestinationTop) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
 
-    *pDestinationTop = This->DestRect.top;
-
-    return S_OK;
+fail:
+    BaseRendererImpl_Release(&pVideoRenderer->renderer.filter.IBaseFilter_iface);
+    CoTaskMemFree(pVideoRenderer);
+    return hr;
 }
 
-static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
-                                                       LONG DestinationHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
-
-    This->DestRect.right = This->DestRect.left + DestinationHeight;
-
-    return S_OK;
+HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
+{
+    /* TODO: Attempt to use the VMR-7 renderer instead when possible */
+    return VideoRenderer_create(pUnkOuter, ppv);
 }
-
-static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
-                                                       LONG *pDestinationHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
-
-    *pDestinationHeight = This->DestRect.right - This->DestRect.left;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
-                                                   LONG Left,
-                                                   LONG Top,
-                                                   LONG Width,
-                                                   LONG Height) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
-
-    This->SourceRect.left = Left;
-    This->SourceRect.top = Top;
-    This->SourceRect.right = Left + Width;
-    This->SourceRect.bottom = Top + Height;
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
-                                                   LONG *pLeft,
-                                                   LONG *pTop,
-                                                   LONG *pWidth,
-                                                   LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
-
-    *pLeft = This->SourceRect.left;
-    *pTop = This->SourceRect.top;
-    *pWidth = This->SourceRect.right - This->SourceRect.left;
-    *pHeight = This->SourceRect.bottom - This->SourceRect.top;
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->()\n", This, iface);
-
-    This->SourceRect.left = 0;
-    This->SourceRect.top = 0;
-    This->SourceRect.right = This->VideoWidth;
-    This->SourceRect.bottom = This->VideoHeight;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
-                                                        LONG Left,
-                                                        LONG Top,
-                                                        LONG Width,
-                                                        LONG Height) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
-
-    This->DestRect.left = Left;
-    This->DestRect.top = Top;
-    This->DestRect.right = Left + Width;
-    This->DestRect.bottom = Top + Height;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
-                                                        LONG *pLeft,
-                                                        LONG *pTop,
-                                                        LONG *pWidth,
-                                                        LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
-
-    *pLeft = This->DestRect.left;
-    *pTop = This->DestRect.top;
-    *pWidth = This->DestRect.right - This->DestRect.left;
-    *pHeight = This->DestRect.bottom - This->DestRect.top;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-    RECT rect;
-
-    TRACE("(%p/%p)->()\n", This, iface);
-
-    if (!GetClientRect(This->hWnd, &rect))
-        return E_FAIL;
-    
-    This->SourceRect.left = 0;
-    This->SourceRect.top = 0;
-    This->SourceRect.right = rect.right;
-    This->SourceRect.bottom = rect.bottom;
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
-                                              LONG *pWidth,
-                                              LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
-
-    *pWidth = This->VideoWidth;
-    *pHeight = This->VideoHeight;
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
-                                                        LONG StartIndex,
-                                                        LONG Entries,
-                                                        LONG *pRetrieved,
-                                                        LONG *pPalette) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d, %d, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
-                                                 LONG *pBufferSize,
-                                                 LONG *pDIBImage) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-    BITMAPINFOHEADER *bmiHeader;
-    LONG needed_size;
-    AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
-    char *ptr;
-
-    FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
-
-    EnterCriticalSection(&This->csFilter);
-
-    if (!This->sample_held)
-    {
-         LeaveCriticalSection(&This->csFilter);
-         return (This->state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
-    }
-
-    if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
-    {
-        bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
-    }
-    else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
-    {
-        bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
-    }
-    else
-    {
-        FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
-        LeaveCriticalSection(&This->csFilter);
-        return VFW_E_RUNTIME_ERROR;
-    }
-
-    needed_size = bmiHeader->biSize;
-    needed_size += IMediaSample_GetActualDataLength(This->sample_held);
-
-    if (!pDIBImage)
-    {
-        *pBufferSize = needed_size;
-        LeaveCriticalSection(&This->csFilter);
-        return S_OK;
-    }
-
-    if (needed_size < *pBufferSize)
-    {
-        ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
-        LeaveCriticalSection(&This->csFilter);
-        return E_FAIL;
-    }
-    *pBufferSize = needed_size;
-
-    memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
-    IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
-    memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
-
-    LeaveCriticalSection(&This->csFilter);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(): stub !!!\n", This, iface);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
-
-    FIXME("(%p/%p)->(): stub !!!\n", This, iface);
-
-    return S_OK;
-}
-
-
-static const IBasicVideoVtbl IBasicVideo_VTable =
-{
-    Basicvideo_QueryInterface,
-    Basicvideo_AddRef,
-    Basicvideo_Release,
-    Basicvideo_GetTypeInfoCount,
-    Basicvideo_GetTypeInfo,
-    Basicvideo_GetIDsOfNames,
-    Basicvideo_Invoke,
-    Basicvideo_get_AvgTimePerFrame,
-    Basicvideo_get_BitRate,
-    Basicvideo_get_BitErrorRate,
-    Basicvideo_get_VideoWidth,
-    Basicvideo_get_VideoHeight,
-    Basicvideo_put_SourceLeft,
-    Basicvideo_get_SourceLeft,
-    Basicvideo_put_SourceWidth,
-    Basicvideo_get_SourceWidth,
-    Basicvideo_put_SourceTop,
-    Basicvideo_get_SourceTop,
-    Basicvideo_put_SourceHeight,
-    Basicvideo_get_SourceHeight,
-    Basicvideo_put_DestinationLeft,
-    Basicvideo_get_DestinationLeft,
-    Basicvideo_put_DestinationWidth,
-    Basicvideo_get_DestinationWidth,
-    Basicvideo_put_DestinationTop,
-    Basicvideo_get_DestinationTop,
-    Basicvideo_put_DestinationHeight,
-    Basicvideo_get_DestinationHeight,
-    Basicvideo_SetSourcePosition,
-    Basicvideo_GetSourcePosition,
-    Basicvideo_SetDefaultSourcePosition,
-    Basicvideo_SetDestinationPosition,
-    Basicvideo_GetDestinationPosition,
-    Basicvideo_SetDefaultDestinationPosition,
-    Basicvideo_GetVideoSize,
-    Basicvideo_GetVideoPaletteEntries,
-    Basicvideo_GetCurrentImage,
-    Basicvideo_IsUsingDefaultSource,
-    Basicvideo_IsUsingDefaultDestination
-};
-
-
-/*** IUnknown methods ***/
-static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
-                                                REFIID riid,
-                                                LPVOID*ppvObj) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
-
-    return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
-}
-
-static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->()\n", This, iface);
-
-    return VideoRenderer_AddRef((IBaseFilter*)This);
-}
-
-static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->()\n", This, iface);
-
-    return VideoRenderer_Release((IBaseFilter*)This);
-}
-
-/*** IDispatch methods ***/
-static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
-                                                  UINT*pctinfo) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
-                                             UINT iTInfo,
-                                             LCID lcid,
-                                             ITypeInfo**ppTInfo) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
-                                               REFIID riid,
-                                               LPOLESTR*rgszNames,
-                                               UINT cNames,
-                                               LCID lcid,
-                                               DISPID*rgDispId) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
-                                        DISPID dispIdMember,
-                                        REFIID riid,
-                                        LCID lcid,
-                                        WORD wFlags,
-                                        DISPPARAMS*pDispParams,
-                                        VARIANT*pVarResult,
-                                        EXCEPINFO*pExepInfo,
-                                        UINT*puArgErr) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    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);
-
-    return S_OK;
-}
-
-/*** IVideoWindow methods ***/
-static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
-                                             BSTR strCaption) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
-
-    if (!SetWindowTextW(This->hWnd, strCaption))
-        return E_FAIL;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
-                                             BSTR *strCaption) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
-
-    GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
-                                                  LONG WindowStyle) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-    LONG old;
-
-    old = GetWindowLongA(This->hWnd, GWL_STYLE);
-
-    TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
-
-    if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
-        return E_INVALIDARG;
-    
-    SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
-                                                  LONG *WindowStyle) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
-
-    *WindowStyle = GetWindowLongA(This->hWnd, GWL_STYLE);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
-                                                    LONG WindowStyleEx) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
-
-    if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
-        return E_FAIL;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
-                                                    LONG *WindowStyleEx) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
-
-    *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
-                                               LONG AutoShow) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
-
-    This->AutoShow = AutoShow;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
-                                               LONG *AutoShow) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
-
-    *AutoShow = This->AutoShow;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
-                                                  LONG WindowState) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
-    ShowWindow(This->hWnd, WindowState);
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
-                                                  LONG *WindowState) {
-    WINDOWPLACEMENT place;
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    place.length = sizeof(place);
-    GetWindowPlacement(This->hWnd, &place);
-    TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
-    *WindowState = place.showCmd;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
-                                                        LONG BackgroundPalette) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
-                                                        LONG *pBackgroundPalette) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
-                                              LONG Visible) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
-
-    ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
-                                              LONG *pVisible) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
-
-    *pVisible = IsWindowVisible(This->hWnd);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
-                                           LONG Left) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, Left);
-
-    if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
-        return E_FAIL;
-
-    This->WindowPos.left = Left;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
-                                           LONG *pLeft) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
-
-    *pLeft = This->WindowPos.left;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
-                                            LONG Width) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, Width);
-
-    if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
-        return E_FAIL;
-
-    This->WindowPos.right = This->WindowPos.left + Width;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
-                                            LONG *pWidth) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
-
-    *pWidth = This->WindowPos.right - This->WindowPos.left;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
-                                          LONG Top) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, Top);
-
-    if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
-        return E_FAIL;
-
-    This->WindowPos.top = Top;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
-                                          LONG *pTop) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
-
-    *pTop = This->WindowPos.top;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
-                                             LONG Height) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, Height);
-
-    if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
-        return E_FAIL;
-
-    This->WindowPos.bottom = This->WindowPos.top + Height;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
-                                             LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
-
-    *pHeight = This->WindowPos.bottom - This->WindowPos.top;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
-                                           OAHWND Owner) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
-
-    SetParent(This->hWnd, (HWND)Owner);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
-                                           OAHWND *Owner) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
-
-    *(HWND*)Owner = GetParent(This->hWnd);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
-                                                  OAHWND Drain) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
-
-    This->hWndMsgDrain = (HWND)Drain;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
-                                                  OAHWND *Drain) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
-
-    *Drain = (OAHWND)This->hWndMsgDrain;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
-                                                  LONG *Color) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
-                                                  LONG Color) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
-                                                     LONG *FullScreenMode) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
-                                                     LONG FullScreenMode) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
-                                                      LONG Focus) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-    BOOL ret;
-    IPin* pPin;
-    HRESULT hr;
-
-    TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
-
-    if ((Focus != FALSE) && (Focus != TRUE))
-        return E_INVALIDARG;
-
-    hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
-    if ((hr != S_OK) || !pPin)
-        return VFW_E_NOT_CONNECTED;
-
-    if (Focus)
-        ret = SetForegroundWindow(This->hWnd);
-    else
-        ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
-
-    if (!ret)
-        return E_FAIL;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
-                                                    OAHWND hwnd,
-                                                     LONG uMsg,
-                                                    LONG_PTR wParam,
-                                                    LONG_PTR lParam) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
-
-    if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
-        return E_FAIL;
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
-                                                    LONG Left,
-                                                    LONG Top,
-                                                    LONG Width,
-                                                    LONG Height) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
-
-    if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
-        return E_FAIL;
-
-    This->WindowPos.left = Left;
-    This->WindowPos.top = Top;
-    This->WindowPos.right = Left + Width;
-    This->WindowPos.bottom = Top + Height;
-    
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
-                                                    LONG *pLeft,
-                                                    LONG *pTop,
-                                                    LONG *pWidth,
-                                                    LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
-
-    *pLeft = This->WindowPos.left;
-    *pTop = This->WindowPos.top;
-    *pWidth = This->WindowPos.right - This->WindowPos.left;
-    *pHeight = This->WindowPos.bottom - This->WindowPos.top;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
-                                                       LONG *pWidth,
-                                                       LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
-
-    *pWidth = This->VideoWidth;
-    *pHeight = This->VideoHeight;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
-                                                       LONG *pWidth,
-                                                       LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
-
-    *pWidth = This->VideoWidth;
-    *pHeight = This->VideoHeight;
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
-                                                     LONG *pLeft,
-                                                     LONG *pTop,
-                                                     LONG *pWidth,
-                                                     LONG *pHeight) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
-                                             LONG HideCursor) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
-
-    return S_OK;
-}
-
-static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
-                                                 LONG *CursorHidden) {
-    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
-
-    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
-
-    return S_OK;
-}
-
-static const IVideoWindowVtbl IVideoWindow_VTable =
-{
-    Videowindow_QueryInterface,
-    Videowindow_AddRef,
-    Videowindow_Release,
-    Videowindow_GetTypeInfoCount,
-    Videowindow_GetTypeInfo,
-    Videowindow_GetIDsOfNames,
-    Videowindow_Invoke,
-    Videowindow_put_Caption,
-    Videowindow_get_Caption,
-    Videowindow_put_WindowStyle,
-    Videowindow_get_WindowStyle,
-    Videowindow_put_WindowStyleEx,
-    Videowindow_get_WindowStyleEx,
-    Videowindow_put_AutoShow,
-    Videowindow_get_AutoShow,
-    Videowindow_put_WindowState,
-    Videowindow_get_WindowState,
-    Videowindow_put_BackgroundPalette,
-    Videowindow_get_BackgroundPalette,
-    Videowindow_put_Visible,
-    Videowindow_get_Visible,
-    Videowindow_put_Left,
-    Videowindow_get_Left,
-    Videowindow_put_Width,
-    Videowindow_get_Width,
-    Videowindow_put_Top,
-    Videowindow_get_Top,
-    Videowindow_put_Height,
-    Videowindow_get_Height,
-    Videowindow_put_Owner,
-    Videowindow_get_Owner,
-    Videowindow_put_MessageDrain,
-    Videowindow_get_MessageDrain,
-    Videowindow_get_BorderColor,
-    Videowindow_put_BorderColor,
-    Videowindow_get_FullScreenMode,
-    Videowindow_put_FullScreenMode,
-    Videowindow_SetWindowForeground,
-    Videowindow_NotifyOwnerMessage,
-    Videowindow_SetWindowPosition,
-    Videowindow_GetWindowPosition,
-    Videowindow_GetMinIdealImageSize,
-    Videowindow_GetMaxIdealImageSize,
-    Videowindow_GetRestorePosition,
-    Videowindow_HideCursor,
-    Videowindow_IsCursorHidden
-};