videorenderer.c 67.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Video Renderer (Fullscreen and Windowed using Direct Draw)
 *
 * Copyright 2004 Christian Costa
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 */

#include "config.h"

#define NONAMELESSSTRUCT
#define NONAMELESSUNION
#include "quartz_private.h"
#include "control_private.h"
#include "pin.h"

#include "uuids.h"
#include "vfwmsgs.h"
#include "amvideo.h"
#include "windef.h"
#include "winbase.h"
#include "dshow.h"
35
#include "evcode.h"
36 37
#include "strmif.h"
#include "ddraw.h"
38
#include "dvdmedia.h"
39

40
#include <assert.h>
41 42 43 44 45
#include "wine/unicode.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(quartz);

46 47
static BOOL wnd_class_registered = FALSE;

48 49 50
static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};

static const IBaseFilterVtbl VideoRenderer_Vtbl;
51
static const IUnknownVtbl IInner_VTable;
52 53
static const IBasicVideoVtbl IBasicVideo_VTable;
static const IVideoWindowVtbl IVideoWindow_VTable;
54 55 56 57 58
static const IPinVtbl VideoRenderer_InputPin_Vtbl;

typedef struct VideoRendererImpl
{
    const IBaseFilterVtbl * lpVtbl;
59 60
    const IBasicVideoVtbl * IBasicVideo_vtbl;
    const IVideoWindowVtbl * IVideoWindow_vtbl;
61
    const IUnknownVtbl * IInner_vtbl;
62

63
    LONG refCount;
64 65 66 67 68 69
    CRITICAL_SECTION csFilter;
    FILTER_STATE state;
    REFERENCE_TIME rtStreamStart;
    IReferenceClock * pClock;
    FILTER_INFO filterInfo;

70
    InputPin *pInputPin;
71

72 73
    BOOL init;
    HANDLE hThread;
74 75
    HANDLE blocked;

76 77 78 79 80 81 82 83 84 85 86
    DWORD ThreadID;
    HANDLE hEvent;
    BOOL ThreadResult;
    HWND hWnd;
    HWND hWndMsgDrain;
    BOOL AutoShow;
    RECT SourceRect;
    RECT DestRect;
    RECT WindowPos;
    long VideoWidth;
    long VideoHeight;
87 88 89
    IUnknown * pUnkOuter;
    BOOL bUnkOuterValid;
    BOOL bAggregatable;
90
    REFERENCE_TIME rtLastStop;
91
    MediaSeekingImpl mediaSeeking;
92 93 94

    /* During pause we can hold a single sample, for use in GetCurrentImage */
    IMediaSample *sample_held;
95 96
} VideoRendererImpl;

97 98
static LRESULT CALLBACK VideoWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
99
    VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongPtrW(hwnd, 0);
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    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:
139
            /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
140 141
            SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
            GetClientRect(hwnd, &pVideoRenderer->DestRect);
142 143 144 145 146 147 148 149 150 151 152 153 154 155
            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);
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
            return TRUE;
        default:
            return DefWindowProcA(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

static BOOL CreateRenderingWindow(VideoRendererImpl* This)
{
    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;
176
    winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
177 178 179 180 181 182 183
    winclass.lpszMenuName = NULL;
    winclass.lpszClassName = "Wine ActiveMovie Class";

    if (!wnd_class_registered)
    {
        if (!RegisterClassA(&winclass))
        {
184
            ERR("Unable to register window %u\n", GetLastError());
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
            return FALSE;
        }
        wnd_class_registered = TRUE;
    }

    This->hWnd = CreateWindowExA(0, "Wine ActiveMovie Class", "Wine ActiveMovie Window", WS_SIZEBOX,
                                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
                                 NULL, NULL, NULL);

    if (!This->hWnd)
    {
        ERR("Unable to create window\n");
        return FALSE;
    }

200
    SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
201 202 203 204 205 206

    return TRUE;
}

static DWORD WINAPI MessageLoop(LPVOID lpParameter)
{
207
    VideoRendererImpl* This = lpParameter;
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
    MSG msg; 
    BOOL fGotMessage;

    TRACE("Starting message loop\n");

    if (!CreateRenderingWindow(This))
    {
        This->ThreadResult = FALSE;
        SetEvent(This->hEvent);
        return 0;
    }

    This->ThreadResult = TRUE;
    SetEvent(This->hEvent);

223
    while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1) 
224 225 226 227 228 229 230 231 232 233 234 235
    {
        TranslateMessage(&msg); 
        DispatchMessageA(&msg); 
    }

    TRACE("End of message loop\n");

    return msg.wParam;
}

static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
{
236
    This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
237 238 239
    if (!This->hEvent)
        return FALSE;

240
    This->hThread = CreateThread(NULL, 0, MessageLoop, This, 0, &This->ThreadID);
241 242 243 244 245 246 247 248 249 250
    if (!This->hThread)
    {
        CloseHandle(This->hEvent);
        return FALSE;
    }

    WaitForSingleObject(This->hEvent, INFINITE);

    if (!This->ThreadResult)
    {
251
        CloseHandle(This->hEvent);
252 253 254 255 256 257 258
        CloseHandle(This->hThread);
        return FALSE;
    }

    return TRUE;
}

259 260 261 262
static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
{
    AM_MEDIA_TYPE amt;
    HRESULT hr = S_OK;
263
    DDSURFACEDESC sdesc;
264
    HDC hDC;
265
    BITMAPINFOHEADER *bmiHeader;
266

267
    TRACE("(%p)->(%p, %d)\n", This, data, size);
268

269 270
    sdesc.dwSize = sizeof(sdesc);
    hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
271
    if (FAILED(hr)) {
272 273
        ERR("Unable to retrieve media type\n");
        return hr;
274
    }
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

    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));
        return VFW_E_RUNTIME_ERROR;
    }


    TRACE("biSize = %d\n", bmiHeader->biSize);
    TRACE("biWidth = %d\n", bmiHeader->biWidth);
    TRACE("biHeight = %d\n", bmiHeader->biHeight);
    TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
    TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
    TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
    TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);

299 300
    if (!This->init)
    {
301 302 303
        DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
        DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);

304 305 306
        if (!This->WindowPos.right || !This->WindowPos.bottom)
            This->WindowPos = This->SourceRect;

307 308
        AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);

309 310 311 312 313 314 315
        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);
316

317
        GetClientRect(This->hWnd, &This->DestRect);
318
        This->init = TRUE;
319 320
    }

321
    hDC = GetDC(This->hWnd);
322

323 324 325
    if (!hDC) {
        ERR("Cannot get DC from window!\n");
        return E_FAIL;
326 327
    }

328 329
    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);
330

331 332 333
    StretchDIBits(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,
334
                  data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
335 336 337 338 339

    ReleaseDC(This->hWnd, hDC);
    if (This->AutoShow)
        ShowWindow(This->hWnd, SW_SHOW);

340 341 342 343 344
    return S_OK;
}

static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
{
345
    VideoRendererImpl *This = iface;
346 347 348 349
    LPBYTE pbSrcStream = NULL;
    long cbSrcStream = 0;
    REFERENCE_TIME tStart, tStop;
    HRESULT hr;
350

351 352
    TRACE("(%p)->(%p)\n", iface, pSample);

353
    EnterCriticalSection(&This->csFilter);
354

355
    if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
356 357 358 359
    {
        LeaveCriticalSection(&This->csFilter);
        return S_FALSE;
    }
360

361
    if (This->state == State_Stopped)
362 363
    {
        LeaveCriticalSection(&This->csFilter);
364
        return VFW_E_WRONG_STATE;
365
    }
366

367 368 369 370 371 372 373 374 375 376 377 378 379 380
    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;
    }

381 382
    /* Preroll means the sample isn't shown, this is used for key frames and things like that */
    if (IMediaSample_IsPreroll(pSample) == S_OK)
383 384
    {
        This->rtLastStop = tStop;
385
        LeaveCriticalSection(&This->csFilter);
386
        return S_OK;
387
    }
388

389 390 391
    hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
    if (FAILED(hr))
    {
392
        ERR("Cannot get pointer to sample data (%x)\n", hr);
393
        LeaveCriticalSection(&This->csFilter);
394
        return hr;
395 396 397 398 399 400 401 402 403 404 405
    }

    cbSrcStream = IMediaSample_GetActualDataLength(pSample);

    TRACE("val %p %ld\n", pbSrcStream, cbSrcStream);

#if 0 /* For debugging purpose */
    {
        int i;
        for(i = 0; i < cbSrcStream; i++)
        {
406
            if ((i!=0) && !(i%16))
407 408
                TRACE("\n");
                TRACE("%02x ", pbSrcStream[i]);
409
        }
410
        TRACE("\n");
411 412
    }
#endif
413

414
    SetEvent(This->hEvent);
415 416 417
    if (This->state == State_Paused)
    {
        This->sample_held = pSample;
418 419 420 421 422
        LeaveCriticalSection(&This->csFilter);
        WaitForSingleObject(This->blocked, INFINITE);
        EnterCriticalSection(&This->csFilter);
        This->sample_held = NULL;
        if (This->state == State_Paused)
423
        {
424
            /* Flushing */
425
            LeaveCriticalSection(&This->csFilter);
426
            return S_OK;
427
        }
428
        if (This->state == State_Stopped)
429 430
        {
            LeaveCriticalSection(&This->csFilter);
431
            return VFW_E_WRONG_STATE;
432
        }
433 434
    }

435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    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)
        {
459 460 461
            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) );
462
            This->rtLastStop = tStop;
463
            LeaveCriticalSection(&This->csFilter);
464 465 466 467 468
            return S_OK;
        }
    }
    This->rtLastStop = tStop;

469 470
    VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);

471
    LeaveCriticalSection(&This->csFilter);
472 473 474 475 476
    return S_OK;
}

static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
{
477 478 479 480 481 482 483
    if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
        return S_FALSE;

    if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
        IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
        IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
        IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
484
    {
485
        VideoRendererImpl* This = iface;
486

487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
        if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
        {
            VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
            This->SourceRect.left = 0;
            This->SourceRect.top = 0;
            This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
            This->SourceRect.bottom = This->VideoHeight = format->bmiHeader.biHeight;
        }
        else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
        {
            VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;

            This->SourceRect.left = 0;
            This->SourceRect.top = 0;
            This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
            This->SourceRect.bottom = This->VideoHeight = format2->bmiHeader.biHeight;
        }
        else
505 506 507 508
        {
            WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
            return S_FALSE;
        }
509
        return S_OK;
510
    }
511 512 513
    return S_FALSE;
}

514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
static inline VideoRendererImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
{
    return (VideoRendererImpl *)((char*)iface - FIELD_OFFSET(VideoRendererImpl, mediaSeeking.lpVtbl));
}

static HRESULT WINAPI VideoRendererImpl_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
{
    VideoRendererImpl *This = impl_from_IMediaSeeking(iface);

    return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
}

static ULONG WINAPI VideoRendererImpl_Seeking_AddRef(IMediaSeeking * iface)
{
    VideoRendererImpl *This = impl_from_IMediaSeeking(iface);

    return IUnknown_AddRef((IUnknown *)This);
}

static ULONG WINAPI VideoRendererImpl_Seeking_Release(IMediaSeeking * iface)
{
    VideoRendererImpl *This = impl_from_IMediaSeeking(iface);

    return IUnknown_Release((IUnknown *)This);
}

static const IMediaSeekingVtbl VideoRendererImpl_Seeking_Vtbl =
{
    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
};

static HRESULT VideoRendererImpl_Change(IBaseFilter *iface)
{
566
    TRACE("(%p)->()\n", iface);
567 568 569
    return S_OK;
}

570 571 572 573 574 575 576 577 578 579 580
HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
{
    HRESULT hr;
    PIN_INFO piInput;
    VideoRendererImpl * pVideoRenderer;

    TRACE("(%p, %p)\n", pUnkOuter, ppv);

    *ppv = NULL;

    pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
581 582 583 584
    pVideoRenderer->pUnkOuter = pUnkOuter;
    pVideoRenderer->bUnkOuterValid = FALSE;
    pVideoRenderer->bAggregatable = FALSE;
    pVideoRenderer->IInner_vtbl = &IInner_VTable;
585 586 587 588 589 590 591

    pVideoRenderer->lpVtbl = &VideoRenderer_Vtbl;
    pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
    pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
    
    pVideoRenderer->refCount = 1;
    InitializeCriticalSection(&pVideoRenderer->csFilter);
592
    pVideoRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter");
593 594 595
    pVideoRenderer->state = State_Stopped;
    pVideoRenderer->pClock = NULL;
    pVideoRenderer->init = 0;
596
    pVideoRenderer->AutoShow = 1;
597
    pVideoRenderer->rtLastStop = -1;
598
    ZeroMemory(&pVideoRenderer->filterInfo, sizeof(FILTER_INFO));
599 600 601 602
    ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
    ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
    ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
    pVideoRenderer->hWndMsgDrain = NULL;
603 604 605 606

    /* construct input pin */
    piInput.dir = PINDIR_INPUT;
    piInput.pFilter = (IBaseFilter *)pVideoRenderer;
607
    lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
608

609
    hr = InputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, VideoRenderer_Sample, (LPVOID)pVideoRenderer, VideoRenderer_QueryAccept, NULL, &pVideoRenderer->csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
610 611 612

    if (SUCCEEDED(hr))
    {
613 614 615
        MediaSeekingImpl_Init((IBaseFilter*)pVideoRenderer, VideoRendererImpl_Change, VideoRendererImpl_Change, VideoRendererImpl_Change, &pVideoRenderer->mediaSeeking, &pVideoRenderer->csFilter);
        pVideoRenderer->mediaSeeking.lpVtbl = &VideoRendererImpl_Seeking_Vtbl;

616
        pVideoRenderer->sample_held = NULL;
617
        *ppv = pVideoRenderer;
618 619 620
    }
    else
    {
621
        pVideoRenderer->csFilter.DebugInfo->Spare[0] = 0;
622 623 624 625
        DeleteCriticalSection(&pVideoRenderer->csFilter);
        CoTaskMemFree(pVideoRenderer);
    }

626 627
    if (!CreateRenderingSubsystem(pVideoRenderer))
        return E_FAIL;
628 629 630 631 632 633 634 635

    pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
    if (!pVideoRenderer->blocked)
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        IUnknown_Release((IUnknown *)pVideoRenderer);
    }

636 637 638
    return hr;
}

639 640
HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
{
Austin English's avatar
Austin English committed
641
    /* TODO: Attempt to use the VMR-7 renderer instead when possible */
642 643 644
    return VideoRenderer_create(pUnkOuter, ppv);
}

645
static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
646
{
647
    ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
648 649
    TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);

650 651 652
    if (This->bAggregatable)
        This->bUnkOuterValid = TRUE;

653 654 655
    *ppv = NULL;

    if (IsEqualIID(riid, &IID_IUnknown))
656
        *ppv = &This->IInner_vtbl;
657
    else if (IsEqualIID(riid, &IID_IPersist))
658
        *ppv = This;
659
    else if (IsEqualIID(riid, &IID_IMediaFilter))
660
        *ppv = This;
661
    else if (IsEqualIID(riid, &IID_IBaseFilter))
662
        *ppv = This;
663
    else if (IsEqualIID(riid, &IID_IBasicVideo))
664
        *ppv = &This->IBasicVideo_vtbl;
665
    else if (IsEqualIID(riid, &IID_IVideoWindow))
666
        *ppv = &This->IVideoWindow_vtbl;
667 668
    else if (IsEqualIID(riid, &IID_IMediaSeeking))
        *ppv = &This->mediaSeeking;
669 670 671 672 673 674 675

    if (*ppv)
    {
        IUnknown_AddRef((IUnknown *)(*ppv));
        return S_OK;
    }

676 677
    if (!IsEqualIID(riid, &IID_IPin))
        FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
678 679 680 681

    return E_NOINTERFACE;
}

682
static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
683
{
684
    ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
685
    ULONG refCount = InterlockedIncrement(&This->refCount);
686

687
    TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
688

689
    return refCount;
690 691
}

692
static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
693
{
694
    ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
695
    ULONG refCount = InterlockedDecrement(&This->refCount);
696

697
    TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
698

699
    if (!refCount)
700
    {
701 702
        IPin *pConnectedTo;

703 704 705 706
        DestroyWindow(This->hWnd);
        PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
        WaitForSingleObject(This->hThread, INFINITE);
        CloseHandle(This->hThread);
707
        CloseHandle(This->hEvent);
708

709 710
        if (This->pClock)
            IReferenceClock_Release(This->pClock);
711
        
712
        if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
713 714 715 716
        {
            IPin_Disconnect(pConnectedTo);
            IPin_Release(pConnectedTo);
        }
717 718 719
        IPin_Disconnect((IPin *)This->pInputPin);

        IPin_Release((IPin *)This->pInputPin);
720

721 722
        This->lpVtbl = NULL;
        
723 724 725
        This->csFilter.DebugInfo->Spare[0] = 0;
        DeleteCriticalSection(&This->csFilter);

726 727 728 729 730 731
        TRACE("Destroying Video Renderer\n");
        CoTaskMemFree(This);
        
        return 0;
    }
    else
732
        return refCount;
733 734
}

735 736
static const IUnknownVtbl IInner_VTable =
{
737 738 739
    VideoRendererInner_QueryInterface,
    VideoRendererInner_AddRef,
    VideoRendererInner_Release
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
};

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);
}

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));
}

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));
}

790 791 792 793
/** IPersist methods **/

static HRESULT WINAPI VideoRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
{
794
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
795 796 797 798 799 800 801 802 803 804 805 806

    TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);

    *pClsid = CLSID_VideoRenderer;

    return S_OK;
}

/** IMediaFilter methods **/

static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
{
807
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
808 809 810 811 812 813

    TRACE("(%p/%p)->()\n", This, iface);

    EnterCriticalSection(&This->csFilter);
    {
        This->state = State_Stopped;
814 815
        SetEvent(This->hEvent);
        SetEvent(This->blocked);
816 817
    }
    LeaveCriticalSection(&This->csFilter);
818

819 820 821 822 823
    return S_OK;
}

static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
{
824
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
825 826 827 828
    
    TRACE("(%p/%p)->()\n", This, iface);

    EnterCriticalSection(&This->csFilter);
829
    if (This->state != State_Paused)
830
    {
831
        if (This->state == State_Stopped)
832
        {
833
            This->pInputPin->end_of_stream = 0;
834 835
            ResetEvent(This->hEvent);
        }
836

837
        This->state = State_Paused;
838
        ResetEvent(This->blocked);
839 840 841 842 843 844 845 846
    }
    LeaveCriticalSection(&This->csFilter);

    return S_OK;
}

static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
{
847
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
848 849 850 851

    TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));

    EnterCriticalSection(&This->csFilter);
852
    if (This->state != State_Running)
853
    {
854
        if (This->state == State_Stopped)
855
        {
856
            This->pInputPin->end_of_stream = 0;
857 858 859
            ResetEvent(This->hEvent);
        }
        SetEvent(This->blocked);
860

861 862 863 864 865 866 867 868 869 870
        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)
{
871
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
872
    HRESULT hr;
873

874
    TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
875

876 877 878 879 880
    if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
        hr = VFW_S_STATE_INTERMEDIATE;
    else
        hr = S_OK;

881 882 883 884 885 886
    EnterCriticalSection(&This->csFilter);
    {
        *pState = This->state;
    }
    LeaveCriticalSection(&This->csFilter);

887
    return hr;
888 889 890 891
}

static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
{
892
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910

    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)
{
911
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
912 913 914 915 916 917

    TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);

    EnterCriticalSection(&This->csFilter);
    {
        *ppClock = This->pClock;
918 919
        if (This->pClock)
            IReferenceClock_AddRef(This->pClock);
920 921 922 923 924 925 926 927
    }
    LeaveCriticalSection(&This->csFilter);
    
    return S_OK;
}

/** IBaseFilter implementation **/

928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
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;
}

943 944
static HRESULT WINAPI VideoRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
{
945
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
946 947 948

    TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);

949
    return IEnumPinsImpl_Construct(ppEnum, VideoRenderer_GetPin, iface);
950 951 952 953
}

static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
{
954
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
955

956
    FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
957 958 959 960 961 962 963 964

    /* FIXME: critical section */

    return E_NOTIMPL;
}

static HRESULT WINAPI VideoRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
{
965
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
966 967 968 969 970 971 972 973 974 975 976 977 978 979

    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)
{
980
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998

    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 */
    }
    LeaveCriticalSection(&This->csFilter);

    return S_OK;
}

static HRESULT WINAPI VideoRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
{
999
    VideoRendererImpl *This = (VideoRendererImpl *)iface;
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
    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,
    VideoRenderer_Pause,
    VideoRenderer_Run,
    VideoRenderer_GetState,
    VideoRenderer_SetSyncSource,
    VideoRenderer_GetSyncSource,
    VideoRenderer_EnumPins,
    VideoRenderer_FindPin,
    VideoRenderer_QueryFilterInfo,
    VideoRenderer_JoinFilterGraph,
    VideoRenderer_QueryVendorInfo
};

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
{
    InputPin* This = (InputPin*)iface;
    IMediaEventSink* pEventSink;
    HRESULT hr;

    TRACE("(%p/%p)->()\n", This, 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);
    }

    return hr;
}

1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
{
    InputPin* This = (InputPin*)iface;
    VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
    HRESULT hr;

    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;
}

static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
{
    InputPin* This = (InputPin*)iface;
    VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
    HRESULT hr;

    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;
}

1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
static const IPinVtbl VideoRenderer_InputPin_Vtbl = 
{
    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,
1093
    VideoRenderer_InputPin_EndOfStream,
1094 1095
    VideoRenderer_InputPin_BeginFlush,
    VideoRenderer_InputPin_EndFlush,
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
    InputPin_NewSegment
};

/*** IUnknown methods ***/
static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
						REFIID riid,
						LPVOID*ppvObj) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_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 Basicvideo_AddRef(IBasicVideo *iface) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

    TRACE("(%p/%p)->()\n", This, iface);

    return VideoRenderer_AddRef((IBaseFilter*)This);
}

static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, 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);

1131
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141

    return S_OK;
}

static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
					     UINT iTInfo,
					     LCID lcid,
					     ITypeInfo**ppTInfo) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1142
    FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154

    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);

1155
    FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170

    return S_OK;
}

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);

1171
    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);
1172 1173 1174 1175 1176 1177 1178 1179 1180

    return S_OK;
}

/*** IBasicVideo methods ***/
static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
						     REFTIME *pAvgTimePerFrame) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1181
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pAvgTimePerFrame);
1182 1183 1184 1185 1186

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1187
                                             LONG *pBitRate) {
1188 1189
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1190
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1191 1192 1193 1194 1195

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1196
                                                  LONG *pBitErrorRate) {
1197 1198
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1199
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1200 1201 1202 1203 1204

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1205
                                                LONG *pVideoWidth) {
1206 1207
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1208 1209 1210
    TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);

    *pVideoWidth = This->VideoWidth;
1211 1212 1213 1214 1215

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1216
                                                 LONG *pVideoHeight) {
1217 1218
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1219 1220 1221
    TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);

    *pVideoHeight = This->VideoHeight;
1222 1223 1224 1225 1226

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1227
                                                LONG SourceLeft) {
1228 1229
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1230
    TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
1231 1232

    This->SourceRect.left = SourceLeft;
1233 1234 1235 1236 1237

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1238
                                                LONG *pSourceLeft) {
1239 1240
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1241 1242 1243
    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);

    *pSourceLeft = This->SourceRect.left;
1244 1245 1246 1247 1248

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1249
                                                 LONG SourceWidth) {
1250 1251
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1252
    TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
1253 1254

    This->SourceRect.right = This->SourceRect.left + SourceWidth;
1255 1256 1257 1258 1259

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1260
                                                 LONG *pSourceWidth) {
1261 1262
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1263
    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1264

1265 1266
    *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
    
1267 1268 1269 1270
    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1271
                                               LONG SourceTop) {
1272 1273
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1274
    TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
1275 1276

    This->SourceRect.top = SourceTop;
1277 1278 1279 1280 1281

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1282
                                               LONG *pSourceTop) {
1283 1284
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1285 1286 1287
    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);

    *pSourceTop = This->SourceRect.top;
1288 1289 1290 1291 1292

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1293
                                                  LONG SourceHeight) {
1294 1295
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1296
    TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
1297 1298

    This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1299 1300 1301 1302 1303

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1304
                                                  LONG *pSourceHeight) {
1305 1306
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1307 1308 1309
    TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);

    *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1310 1311 1312 1313 1314

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1315
                                                     LONG DestinationLeft) {
1316 1317
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1318
    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
1319 1320

    This->DestRect.left = DestinationLeft;
1321 1322 1323 1324 1325

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1326
                                                     LONG *pDestinationLeft) {
1327 1328
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1329 1330 1331
    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);

    *pDestinationLeft = This->DestRect.left;
1332 1333 1334 1335 1336

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1337
                                                      LONG DestinationWidth) {
1338 1339
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1340
    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
1341 1342

    This->DestRect.right = This->DestRect.left + DestinationWidth;
1343 1344 1345 1346 1347

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1348
                                                      LONG *pDestinationWidth) {
1349 1350
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1351 1352 1353
    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);

    *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1354 1355 1356 1357 1358

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1359
                                                    LONG DestinationTop) {
1360 1361
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1362
    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
1363

1364 1365
    This->DestRect.top = DestinationTop;
    
1366 1367 1368 1369
    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1370
                                                    LONG *pDestinationTop) {
1371 1372
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1373 1374 1375
    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);

    *pDestinationTop = This->DestRect.top;
1376 1377 1378 1379 1380

    return S_OK;
}

static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1381
                                                       LONG DestinationHeight) {
1382 1383
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1384
    TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
1385 1386

    This->DestRect.right = This->DestRect.left + DestinationHeight;
1387 1388 1389 1390 1391

    return S_OK;
}

static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1392
                                                       LONG *pDestinationHeight) {
1393 1394
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1395 1396 1397
    TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);

    *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1398 1399 1400 1401 1402

    return S_OK;
}

static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1403 1404 1405 1406
                                                   LONG Left,
                                                   LONG Top,
                                                   LONG Width,
                                                   LONG Height) {
1407 1408
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1409
    TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1410

1411 1412 1413 1414 1415
    This->SourceRect.left = Left;
    This->SourceRect.top = Top;
    This->SourceRect.right = Left + Width;
    This->SourceRect.bottom = Top + Height;
    
1416 1417 1418 1419
    return S_OK;
}

static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1420 1421 1422 1423
                                                   LONG *pLeft,
                                                   LONG *pTop,
                                                   LONG *pWidth,
                                                   LONG *pHeight) {
1424 1425
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1426
    TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1427

1428 1429 1430 1431 1432
    *pLeft = This->SourceRect.left;
    *pTop = This->SourceRect.top;
    *pWidth = This->SourceRect.right - This->SourceRect.left;
    *pHeight = This->SourceRect.bottom - This->SourceRect.top;
    
1433 1434 1435 1436 1437 1438
    return S_OK;
}

static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1439 1440 1441 1442 1443 1444
    TRACE("(%p/%p)->()\n", This, iface);

    This->SourceRect.left = 0;
    This->SourceRect.top = 0;
    This->SourceRect.right = This->VideoWidth;
    This->SourceRect.bottom = This->VideoHeight;
1445 1446 1447 1448 1449

    return S_OK;
}

static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1450 1451 1452 1453
                                                        LONG Left,
                                                        LONG Top,
                                                        LONG Width,
                                                        LONG Height) {
1454 1455
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1456
    TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1457 1458 1459 1460 1461

    This->DestRect.left = Left;
    This->DestRect.top = Top;
    This->DestRect.right = Left + Width;
    This->DestRect.bottom = Top + Height;
1462 1463 1464 1465 1466

    return S_OK;
}

static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1467 1468 1469 1470
                                                        LONG *pLeft,
                                                        LONG *pTop,
                                                        LONG *pWidth,
                                                        LONG *pHeight) {
1471 1472
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1473 1474 1475 1476 1477 1478
    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;
1479 1480 1481 1482 1483 1484

    return S_OK;
}

static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1485
    RECT rect;
1486

1487
    TRACE("(%p/%p)->()\n", This, iface);
1488

1489 1490 1491 1492 1493 1494 1495 1496
    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;
    
1497 1498 1499 1500
    return S_OK;
}

static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1501 1502
                                              LONG *pWidth,
                                              LONG *pHeight) {
1503 1504
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1505
    TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1506

1507 1508 1509
    *pWidth = This->VideoWidth;
    *pHeight = This->VideoHeight;
    
1510 1511 1512 1513
    return S_OK;
}

static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1514 1515 1516 1517
                                                        LONG StartIndex,
                                                        LONG Entries,
                                                        LONG *pRetrieved,
                                                        LONG *pPalette) {
1518 1519
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1520
    FIXME("(%p/%p)->(%d, %d, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1521 1522 1523 1524 1525

    return S_OK;
}

static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1526 1527
                                                 LONG *pBufferSize,
                                                 LONG *pDIBImage) {
1528
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1529 1530 1531 1532 1533
    BITMAPINFOHEADER *bmiHeader;
    LONG needed_size;
    AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
    char *ptr;

1534 1535
    FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);

1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570
    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)
    {
1571
        ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
        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);
1582 1583 1584 1585 1586 1587 1588

    return S_OK;
}

static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1589
    FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1590 1591 1592 1593 1594 1595 1596

    return S_OK;
}

static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
    ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);

1597
    FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1598 1599 1600 1601 1602

    return S_OK;
}


1603
static const IBasicVideoVtbl IBasicVideo_VTable =
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
{
    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);

1679
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689

    return S_OK;
}

static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
					      UINT iTInfo,
					      LCID lcid,
					      ITypeInfo**ppTInfo) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1690
    FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702

    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);

1703
    FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718

    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);

1719
    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);
1720 1721 1722 1723 1724 1725 1726 1727 1728

    return S_OK;
}

/*** IVideoWindow methods ***/
static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
					      BSTR strCaption) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1729 1730 1731 1732
    TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);

    if (!SetWindowTextW(This->hWnd, strCaption))
        return E_FAIL;
1733 1734 1735 1736 1737 1738 1739 1740

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
					      BSTR *strCaption) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1741 1742 1743
    TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);

    GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1744 1745 1746 1747 1748

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1749
                                                  LONG WindowStyle) {
1750
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1751
    LONG old;
1752

1753
    old = GetWindowLongA(This->hWnd, GWL_STYLE);
1754 1755

    TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
1756 1757 1758 1759 1760

    if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
        return E_INVALIDARG;
    
    SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1761 1762 1763 1764 1765

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1766
                                                  LONG *WindowStyle) {
1767 1768
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1769 1770 1771
    TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);

    *WindowStyle = GetWindowLongA(This->hWnd, GWL_STYLE);
1772 1773 1774 1775 1776

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1777
                                                    LONG WindowStyleEx) {
1778 1779
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1780
    TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
1781 1782 1783 1784 1785 1786

    if (WindowStyleEx & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
        return E_INVALIDARG;

    if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
        return E_FAIL;
1787 1788 1789 1790 1791

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1792
                                                    LONG *WindowStyleEx) {
1793 1794
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1795 1796 1797
    TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);

    *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1798 1799 1800 1801 1802

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1803
                                               LONG AutoShow) {
1804 1805
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1806
    TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
1807

1808
    This->AutoShow = 1; /* FIXME: Should be AutoShow */;
1809 1810 1811 1812 1813

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1814
                                               LONG *AutoShow) {
1815 1816
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1817 1818 1819
    TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);

    *AutoShow = This->AutoShow;
1820 1821 1822 1823 1824

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1825
                                                  LONG WindowState) {
1826 1827
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1828
    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, WindowState);
1829 1830 1831 1832 1833

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1834
                                                  LONG *WindowState) {
1835 1836
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1837
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, WindowState);
1838 1839 1840 1841 1842

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1843
                                                        LONG BackgroundPalette) {
1844 1845
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1846
    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
1847 1848 1849 1850 1851

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1852
                                                        LONG *pBackgroundPalette) {
1853 1854
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1855
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1856 1857 1858 1859 1860

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1861
                                              LONG Visible) {
1862 1863
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1864
    TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
1865 1866

    ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1867 1868 1869 1870 1871

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1872
                                              LONG *pVisible) {
1873 1874
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1875 1876 1877
    TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);

    *pVisible = IsWindowVisible(This->hWnd);
1878 1879 1880 1881 1882

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1883
                                           LONG Left) {
1884 1885
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1886
    TRACE("(%p/%p)->(%d)\n", This, iface, Left);
1887 1888 1889 1890 1891

    if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
        return E_FAIL;

    This->WindowPos.left = Left;
1892 1893 1894 1895 1896

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1897
                                           LONG *pLeft) {
1898 1899
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1900 1901 1902
    TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);

    *pLeft = This->WindowPos.left;
1903 1904 1905 1906 1907

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1908
                                            LONG Width) {
1909 1910
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1911
    TRACE("(%p/%p)->(%d)\n", This, iface, Width);
1912 1913 1914 1915 1916

    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;
1917 1918 1919 1920 1921

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1922
                                            LONG *pWidth) {
1923 1924
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1925 1926 1927
    TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);

    *pWidth = This->WindowPos.right - This->WindowPos.left;
1928 1929 1930 1931 1932

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1933
                                          LONG Top) {
1934 1935
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1936
    TRACE("(%p/%p)->(%d)\n", This, iface, Top);
1937 1938 1939 1940 1941

    if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
        return E_FAIL;

    This->WindowPos.top = Top;
1942 1943 1944 1945 1946

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1947
                                          LONG *pTop) {
1948 1949
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1950 1951 1952
    TRACE("(%p/%p)->(%p)\n", This, iface, pTop);

    *pTop = This->WindowPos.top;
1953 1954 1955 1956 1957

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1958
                                             LONG Height) {
1959 1960
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1961
    TRACE("(%p/%p)->(%d)\n", This, iface, Height);
1962 1963 1964 1965 1966

    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;
1967 1968 1969 1970 1971

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1972
                                             LONG *pHeight) {
1973 1974
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1975 1976 1977
    TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);

    *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1978 1979 1980 1981 1982 1983 1984 1985

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
					    OAHWND Owner) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1986
    TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1987 1988

    SetParent(This->hWnd, (HWND)Owner);
1989 1990 1991 1992 1993 1994 1995 1996

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
					    OAHWND *Owner) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

1997
    TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
1998 1999

    *(HWND*)Owner = GetParent(This->hWnd);
2000 2001 2002 2003 2004 2005 2006 2007

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
						   OAHWND Drain) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2008
    TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
2009 2010

    This->hWndMsgDrain = (HWND)Drain;
2011 2012 2013 2014 2015 2016 2017 2018

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
						   OAHWND *Drain) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2019 2020 2021
    TRACE("(%p/%p)->(%p)\n", This, iface, Drain);

    *Drain = (OAHWND)This->hWndMsgDrain;
2022 2023 2024 2025 2026

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
2027
                                                  LONG *Color) {
2028 2029
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2030
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
2031 2032 2033 2034 2035

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
2036
                                                  LONG Color) {
2037 2038
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2039
    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
2040 2041 2042 2043 2044

    return S_OK;
}

static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
2045
                                                     LONG *FullScreenMode) {
2046 2047
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2048
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
2049 2050 2051 2052 2053

    return S_OK;
}

static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
2054
                                                     LONG FullScreenMode) {
2055 2056
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2057
    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
2058 2059 2060 2061 2062

    return S_OK;
}

static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2063
                                                      LONG Focus) {
2064
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2065 2066 2067
    BOOL ret;
    IPin* pPin;
    HRESULT hr;
2068

2069
    TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
2070 2071 2072 2073

    if ((Focus != FALSE) && (Focus != TRUE))
        return E_INVALIDARG;

2074
    hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
    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;
2085 2086 2087 2088 2089 2090

    return S_OK;
}

static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
						     OAHWND hwnd,
2091
                                                     LONG uMsg,
2092 2093 2094 2095
						     LONG_PTR wParam,
						     LONG_PTR lParam) {
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2096
    TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
2097

2098 2099 2100
    if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
        return E_FAIL;
    
2101 2102 2103 2104
    return S_OK;
}

static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2105 2106 2107 2108
                                                    LONG Left,
                                                    LONG Top,
                                                    LONG Width,
                                                    LONG Height) {
2109
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2110 2111

    TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
2112

2113 2114 2115 2116 2117 2118 2119 2120
    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;
    
2121 2122 2123 2124
    return S_OK;
}

static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2125 2126 2127 2128
                                                    LONG *pLeft,
                                                    LONG *pTop,
                                                    LONG *pWidth,
                                                    LONG *pHeight) {
2129 2130
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2131 2132 2133 2134 2135 2136
    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;
2137 2138 2139 2140 2141

    return S_OK;
}

static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2142 2143
                                                       LONG *pWidth,
                                                       LONG *pHeight) {
2144 2145
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2146 2147 2148 2149
    FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);

    *pWidth = This->VideoWidth;
    *pHeight = This->VideoHeight;
2150 2151 2152 2153 2154

    return S_OK;
}

static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2155 2156
                                                       LONG *pWidth,
                                                       LONG *pHeight) {
2157 2158
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2159 2160 2161 2162
    FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);

    *pWidth = This->VideoWidth;
    *pHeight = This->VideoHeight;
2163 2164 2165 2166 2167

    return S_OK;
}

static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2168 2169 2170 2171
                                                     LONG *pLeft,
                                                     LONG *pTop,
                                                     LONG *pWidth,
                                                     LONG *pHeight) {
2172 2173
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2174
    FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2175 2176 2177 2178 2179

    return S_OK;
}

static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2180
                                             LONG HideCursor) {
2181 2182
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2183
    FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
2184 2185 2186 2187 2188

    return S_OK;
}

static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2189
                                                 LONG *CursorHidden) {
2190 2191
    ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);

2192
    FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2193 2194 2195 2196

    return S_OK;
}

2197
static const IVideoWindowVtbl IVideoWindow_VTable =
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245
{
    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
};