strmbase: Move BasePin implementation to strmbase.
[wine/multimedia.git] / dlls / quartz / videorenderer.c
blob0cfef54d8df219dff0b3dcac7589f9b5356d0b33
1 /*
2 * Video Renderer (Fullscreen and Windowed using Direct Draw)
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
25 #include "quartz_private.h"
26 #include "control_private.h"
27 #include "pin.h"
29 #include "uuids.h"
30 #include "vfwmsgs.h"
31 #include "amvideo.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "dshow.h"
35 #include "evcode.h"
36 #include "strmif.h"
37 #include "ddraw.h"
38 #include "dvdmedia.h"
40 #include <assert.h>
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
46 static BOOL wnd_class_registered = FALSE;
48 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
50 static const IBaseFilterVtbl VideoRenderer_Vtbl;
51 static const IUnknownVtbl IInner_VTable;
52 static const IBasicVideoVtbl IBasicVideo_VTable;
53 static const IVideoWindowVtbl IVideoWindow_VTable;
54 static const IPinVtbl VideoRenderer_InputPin_Vtbl;
56 typedef struct VideoRendererImpl
58 const IBaseFilterVtbl * lpVtbl;
59 const IBasicVideoVtbl * IBasicVideo_vtbl;
60 const IVideoWindowVtbl * IVideoWindow_vtbl;
61 const IUnknownVtbl * IInner_vtbl;
62 IUnknown *seekthru_unk;
64 LONG refCount;
65 CRITICAL_SECTION csFilter;
66 FILTER_STATE state;
67 REFERENCE_TIME rtStreamStart;
68 IReferenceClock * pClock;
69 FILTER_INFO filterInfo;
71 InputPin *pInputPin;
73 BOOL init;
74 HANDLE hThread;
75 HANDLE blocked;
77 DWORD ThreadID;
78 HANDLE hEvent;
79 BOOL ThreadResult;
80 HWND hWnd;
81 HWND hWndMsgDrain;
82 BOOL AutoShow;
83 RECT SourceRect;
84 RECT DestRect;
85 RECT WindowPos;
86 LONG VideoWidth;
87 LONG VideoHeight;
88 IUnknown * pUnkOuter;
89 BOOL bUnkOuterValid;
90 BOOL bAggregatable;
91 REFERENCE_TIME rtLastStop;
92 MediaSeekingImpl mediaSeeking;
93 LONG WindowStyle;
95 /* During pause we can hold a single sample, for use in GetCurrentImage */
96 IMediaSample *sample_held;
97 } VideoRendererImpl;
99 static LRESULT CALLBACK VideoWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
101 VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongPtrW(hwnd, 0);
102 LPRECT lprect = (LPRECT)lParam;
104 if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
106 switch(uMsg)
108 case WM_KEYDOWN:
109 case WM_KEYUP:
110 case WM_LBUTTONDBLCLK:
111 case WM_LBUTTONDOWN:
112 case WM_LBUTTONUP:
113 case WM_MBUTTONDBLCLK:
114 case WM_MBUTTONDOWN:
115 case WM_MBUTTONUP:
116 case WM_MOUSEACTIVATE:
117 case WM_MOUSEMOVE:
118 case WM_NCLBUTTONDBLCLK:
119 case WM_NCLBUTTONDOWN:
120 case WM_NCLBUTTONUP:
121 case WM_NCMBUTTONDBLCLK:
122 case WM_NCMBUTTONDOWN:
123 case WM_NCMBUTTONUP:
124 case WM_NCMOUSEMOVE:
125 case WM_NCRBUTTONDBLCLK:
126 case WM_NCRBUTTONDOWN:
127 case WM_NCRBUTTONUP:
128 case WM_RBUTTONDBLCLK:
129 case WM_RBUTTONDOWN:
130 case WM_RBUTTONUP:
131 PostMessageA(pVideoRenderer->hWndMsgDrain, uMsg, wParam, lParam);
132 break;
133 default:
134 break;
138 switch(uMsg)
140 case WM_SIZING:
141 /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
142 SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
143 GetClientRect(hwnd, &pVideoRenderer->DestRect);
144 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
145 pVideoRenderer->DestRect.left,
146 pVideoRenderer->DestRect.top,
147 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
148 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
149 return TRUE;
150 case WM_SIZE:
151 TRACE("WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
152 GetClientRect(hwnd, &pVideoRenderer->DestRect);
153 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
154 pVideoRenderer->DestRect.left,
155 pVideoRenderer->DestRect.top,
156 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
157 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
158 return TRUE;
159 default:
160 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
162 return 0;
165 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
167 WNDCLASSA winclass;
169 TRACE("(%p)->()\n", This);
171 winclass.style = 0;
172 winclass.lpfnWndProc = VideoWndProcA;
173 winclass.cbClsExtra = 0;
174 winclass.cbWndExtra = sizeof(VideoRendererImpl*);
175 winclass.hInstance = NULL;
176 winclass.hIcon = NULL;
177 winclass.hCursor = NULL;
178 winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
179 winclass.lpszMenuName = NULL;
180 winclass.lpszClassName = "Wine ActiveMovie Class";
182 if (!wnd_class_registered)
184 if (!RegisterClassA(&winclass))
186 ERR("Unable to register window %u\n", GetLastError());
187 return FALSE;
189 wnd_class_registered = TRUE;
192 This->hWnd = CreateWindowExA(0, "Wine ActiveMovie Class", "Wine ActiveMovie Window", WS_SIZEBOX,
193 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
194 NULL, NULL, NULL);
196 if (!This->hWnd)
198 ERR("Unable to create window\n");
199 return FALSE;
202 SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
204 return TRUE;
207 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
209 VideoRendererImpl* This = lpParameter;
210 MSG msg;
211 BOOL fGotMessage;
213 TRACE("Starting message loop\n");
215 if (!CreateRenderingWindow(This))
217 This->ThreadResult = FALSE;
218 SetEvent(This->hEvent);
219 return 0;
222 This->ThreadResult = TRUE;
223 SetEvent(This->hEvent);
225 while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
227 TranslateMessage(&msg);
228 DispatchMessageA(&msg);
231 TRACE("End of message loop\n");
233 return msg.wParam;
236 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
238 This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
239 if (!This->hEvent)
240 return FALSE;
242 This->hThread = CreateThread(NULL, 0, MessageLoop, This, 0, &This->ThreadID);
243 if (!This->hThread)
245 CloseHandle(This->hEvent);
246 return FALSE;
249 WaitForSingleObject(This->hEvent, INFINITE);
251 if (!This->ThreadResult)
253 CloseHandle(This->hEvent);
254 CloseHandle(This->hThread);
255 return FALSE;
258 return TRUE;
261 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
263 AM_MEDIA_TYPE amt;
264 HRESULT hr = S_OK;
265 DDSURFACEDESC sdesc;
266 HDC hDC;
267 BITMAPINFOHEADER *bmiHeader;
269 TRACE("(%p)->(%p, %d)\n", This, data, size);
271 sdesc.dwSize = sizeof(sdesc);
272 hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
273 if (FAILED(hr)) {
274 ERR("Unable to retrieve media type\n");
275 return hr;
278 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
280 bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
282 else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
284 bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
286 else
288 FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
289 return VFW_E_RUNTIME_ERROR;
292 TRACE("biSize = %d\n", bmiHeader->biSize);
293 TRACE("biWidth = %d\n", bmiHeader->biWidth);
294 TRACE("biHeight = %d\n", bmiHeader->biHeight);
295 TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
296 TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
297 TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
298 TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
300 if (!This->init)
302 if (!This->WindowPos.right || !This->WindowPos.top)
304 DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
305 DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
307 if (!This->WindowPos.right)
309 This->WindowPos.left = This->SourceRect.left;
310 This->WindowPos.right = This->SourceRect.right;
312 if (!This->WindowPos.bottom)
314 This->WindowPos.top = This->SourceRect.top;
315 This->WindowPos.bottom = This->SourceRect.bottom;
318 AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);
320 TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
321 SetWindowPos(This->hWnd, NULL,
322 This->WindowPos.left,
323 This->WindowPos.top,
324 This->WindowPos.right - This->WindowPos.left,
325 This->WindowPos.bottom - This->WindowPos.top,
326 SWP_NOZORDER|SWP_NOMOVE|SWP_DEFERERASE);
328 GetClientRect(This->hWnd, &This->DestRect);
330 else
331 This->DestRect = This->WindowPos;
332 This->init = TRUE;
335 hDC = GetDC(This->hWnd);
337 if (!hDC) {
338 ERR("Cannot get DC from window!\n");
339 return E_FAIL;
342 TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
343 TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
345 StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
346 This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
347 This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
348 data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
350 ReleaseDC(This->hWnd, hDC);
351 if (This->AutoShow)
352 ShowWindow(This->hWnd, SW_SHOW);
354 return S_OK;
357 static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
359 VideoRendererImpl *This = iface;
360 LPBYTE pbSrcStream = NULL;
361 LONG cbSrcStream = 0;
362 REFERENCE_TIME tStart, tStop;
363 HRESULT hr;
365 TRACE("(%p)->(%p)\n", iface, pSample);
367 EnterCriticalSection(&This->csFilter);
369 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
371 LeaveCriticalSection(&This->csFilter);
372 return S_FALSE;
375 if (This->state == State_Stopped)
377 LeaveCriticalSection(&This->csFilter);
378 return VFW_E_WRONG_STATE;
381 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
382 if (FAILED(hr))
383 ERR("Cannot get sample time (%x)\n", hr);
384 else
385 MediaSeekingPassThru_RegisterMediaTime(This->seekthru_unk, tStart);
387 if (This->rtLastStop != tStart && This->state == State_Running)
389 LONG64 delta;
390 delta = tStart - This->rtLastStop;
391 if ((delta < -100000 || delta > 100000) &&
392 IMediaSample_IsDiscontinuity(pSample) == S_FALSE)
393 ERR("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
394 (DWORD)(This->rtLastStop / 10000000),
395 (DWORD)((This->rtLastStop / 10000)%1000),
396 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
397 This->rtLastStop = tStart;
400 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
401 if (IMediaSample_IsPreroll(pSample) == S_OK)
403 This->rtLastStop = tStop;
404 LeaveCriticalSection(&This->csFilter);
405 return S_OK;
408 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
409 if (FAILED(hr))
411 ERR("Cannot get pointer to sample data (%x)\n", hr);
412 LeaveCriticalSection(&This->csFilter);
413 return hr;
416 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
418 TRACE("val %p %d\n", pbSrcStream, cbSrcStream);
420 #if 0 /* For debugging purpose */
422 int i;
423 for(i = 0; i < cbSrcStream; i++)
425 if ((i!=0) && !(i%16))
426 TRACE("\n");
427 TRACE("%02x ", pbSrcStream[i]);
429 TRACE("\n");
431 #endif
433 SetEvent(This->hEvent);
434 if (This->state == State_Paused)
436 This->sample_held = pSample;
437 LeaveCriticalSection(&This->csFilter);
438 WaitForSingleObject(This->blocked, INFINITE);
439 EnterCriticalSection(&This->csFilter);
440 This->sample_held = NULL;
441 if (This->state == State_Paused)
443 /* Flushing */
444 LeaveCriticalSection(&This->csFilter);
445 return S_OK;
447 if (This->state == State_Stopped)
449 LeaveCriticalSection(&This->csFilter);
450 return VFW_E_WRONG_STATE;
454 if (This->pClock && This->state == State_Running)
456 REFERENCE_TIME time, trefstart, trefstop;
457 LONG delta;
459 /* Perhaps I <SHOULD> use the reference clock AdviseTime function here
460 * I'm not going to! When I tried, it seemed to generate lag and
461 * it caused instability.
463 IReferenceClock_GetTime(This->pClock, &time);
465 trefstart = This->rtStreamStart;
466 trefstop = (REFERENCE_TIME)((double)(tStop - tStart) / This->pInputPin->dRate) + This->rtStreamStart;
467 delta = (LONG)((trefstart-time)/10000);
468 This->rtStreamStart = trefstop;
469 This->rtLastStop = tStop;
471 if (delta > 0)
473 TRACE("Sleeping for %u ms\n", delta);
474 Sleep(delta);
476 else if (time > trefstop)
478 TRACE("Dropping sample: Time: %u.%03u ms trefstop: %u.%03u ms!\n",
479 (DWORD)(time / 10000000), (DWORD)((time / 10000)%1000),
480 (DWORD)(trefstop / 10000000), (DWORD)((trefstop / 10000)%1000) );
481 This->rtLastStop = tStop;
482 LeaveCriticalSection(&This->csFilter);
483 return S_OK;
486 This->rtLastStop = tStop;
488 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
490 LeaveCriticalSection(&This->csFilter);
491 return S_OK;
494 static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
496 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
497 return S_FALSE;
499 if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
500 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
501 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
502 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
504 VideoRendererImpl* This = iface;
505 LONG height;
507 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
509 VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
510 This->SourceRect.left = 0;
511 This->SourceRect.top = 0;
512 This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
513 height = format->bmiHeader.biHeight;
514 if (height < 0)
515 This->SourceRect.bottom = This->VideoHeight = -height;
516 else
517 This->SourceRect.bottom = This->VideoHeight = height;
519 else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
521 VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
523 This->SourceRect.left = 0;
524 This->SourceRect.top = 0;
525 This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
526 height = format2->bmiHeader.biHeight;
527 if (height < 0)
528 This->SourceRect.bottom = This->VideoHeight = -height;
529 else
530 This->SourceRect.bottom = This->VideoHeight = height;
532 else
534 WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
535 return S_FALSE;
537 return S_OK;
539 return S_FALSE;
542 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
544 HRESULT hr;
545 PIN_INFO piInput;
546 VideoRendererImpl * pVideoRenderer;
547 ISeekingPassThru *passthru;
549 TRACE("(%p, %p)\n", pUnkOuter, ppv);
551 *ppv = NULL;
553 pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
554 pVideoRenderer->pUnkOuter = pUnkOuter;
555 pVideoRenderer->bUnkOuterValid = FALSE;
556 pVideoRenderer->bAggregatable = FALSE;
557 pVideoRenderer->IInner_vtbl = &IInner_VTable;
559 pVideoRenderer->lpVtbl = &VideoRenderer_Vtbl;
560 pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
561 pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
563 pVideoRenderer->refCount = 1;
564 InitializeCriticalSection(&pVideoRenderer->csFilter);
565 pVideoRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter");
566 pVideoRenderer->state = State_Stopped;
567 pVideoRenderer->pClock = NULL;
568 pVideoRenderer->init = 0;
569 pVideoRenderer->AutoShow = 1;
570 pVideoRenderer->rtLastStop = -1;
571 ZeroMemory(&pVideoRenderer->filterInfo, sizeof(FILTER_INFO));
572 ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
573 ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
574 ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
575 pVideoRenderer->hWndMsgDrain = NULL;
576 pVideoRenderer->WindowStyle = WS_OVERLAPPED;
578 /* construct input pin */
579 piInput.dir = PINDIR_INPUT;
580 piInput.pFilter = (IBaseFilter *)pVideoRenderer;
581 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
583 hr = InputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, VideoRenderer_Sample, (LPVOID)pVideoRenderer, VideoRenderer_QueryAccept, NULL, &pVideoRenderer->csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
585 if (SUCCEEDED(hr))
587 hr = CoCreateInstance(&CLSID_SeekingPassThru, pUnkOuter ? pUnkOuter : (IUnknown*)&pVideoRenderer->IInner_vtbl, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&pVideoRenderer->seekthru_unk);
588 if (FAILED(hr)) {
589 IPin_Release((IPin*)pVideoRenderer->pInputPin);
590 goto fail;
592 IUnknown_QueryInterface(pVideoRenderer->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
593 ISeekingPassThru_Init(passthru, TRUE, (IPin*)pVideoRenderer->pInputPin);
594 ISeekingPassThru_Release(passthru);
595 pVideoRenderer->sample_held = NULL;
596 *ppv = pVideoRenderer;
598 if (FAILED(hr))
599 goto fail;
601 if (!CreateRenderingSubsystem(pVideoRenderer))
602 return E_FAIL;
604 pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
605 if (!pVideoRenderer->blocked)
607 hr = HRESULT_FROM_WIN32(GetLastError());
608 IUnknown_Release((IUnknown *)pVideoRenderer);
611 return hr;
612 fail:
613 pVideoRenderer->csFilter.DebugInfo->Spare[0] = 0;
614 DeleteCriticalSection(&pVideoRenderer->csFilter);
615 CoTaskMemFree(pVideoRenderer);
616 return hr;
619 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
621 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
622 return VideoRenderer_create(pUnkOuter, ppv);
625 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
627 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
628 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
630 if (This->bAggregatable)
631 This->bUnkOuterValid = TRUE;
633 *ppv = NULL;
635 if (IsEqualIID(riid, &IID_IUnknown))
636 *ppv = &This->IInner_vtbl;
637 else if (IsEqualIID(riid, &IID_IPersist))
638 *ppv = This;
639 else if (IsEqualIID(riid, &IID_IMediaFilter))
640 *ppv = This;
641 else if (IsEqualIID(riid, &IID_IBaseFilter))
642 *ppv = This;
643 else if (IsEqualIID(riid, &IID_IBasicVideo))
644 *ppv = &This->IBasicVideo_vtbl;
645 else if (IsEqualIID(riid, &IID_IVideoWindow))
646 *ppv = &This->IVideoWindow_vtbl;
647 else if (IsEqualIID(riid, &IID_IMediaSeeking))
648 return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
650 if (*ppv)
652 IUnknown_AddRef((IUnknown *)(*ppv));
653 return S_OK;
656 if (!IsEqualIID(riid, &IID_IPin))
657 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
659 return E_NOINTERFACE;
662 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
664 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
665 ULONG refCount = InterlockedIncrement(&This->refCount);
667 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
669 return refCount;
672 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
674 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
675 ULONG refCount = InterlockedDecrement(&This->refCount);
677 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
679 if (!refCount)
681 IPin *pConnectedTo;
683 DestroyWindow(This->hWnd);
684 PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
685 WaitForSingleObject(This->hThread, INFINITE);
686 CloseHandle(This->hThread);
687 CloseHandle(This->hEvent);
689 if (This->pClock)
690 IReferenceClock_Release(This->pClock);
692 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
694 IPin_Disconnect(pConnectedTo);
695 IPin_Release(pConnectedTo);
697 IPin_Disconnect((IPin *)This->pInputPin);
699 IPin_Release((IPin *)This->pInputPin);
701 This->lpVtbl = NULL;
702 IUnknown_Release(This->seekthru_unk);
703 This->csFilter.DebugInfo->Spare[0] = 0;
704 DeleteCriticalSection(&This->csFilter);
706 TRACE("Destroying Video Renderer\n");
707 CoTaskMemFree(This);
709 return 0;
711 else
712 return refCount;
715 static const IUnknownVtbl IInner_VTable =
717 VideoRendererInner_QueryInterface,
718 VideoRendererInner_AddRef,
719 VideoRendererInner_Release
722 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
724 VideoRendererImpl *This = (VideoRendererImpl *)iface;
726 if (This->bAggregatable)
727 This->bUnkOuterValid = TRUE;
729 if (This->pUnkOuter)
731 if (This->bAggregatable)
732 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
734 if (IsEqualIID(riid, &IID_IUnknown))
736 HRESULT hr;
738 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
739 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
740 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
741 This->bAggregatable = TRUE;
742 return hr;
745 *ppv = NULL;
746 return E_NOINTERFACE;
749 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
752 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
754 VideoRendererImpl *This = (VideoRendererImpl *)iface;
756 if (This->pUnkOuter && This->bUnkOuterValid)
757 return IUnknown_AddRef(This->pUnkOuter);
758 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
761 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
763 VideoRendererImpl *This = (VideoRendererImpl *)iface;
765 if (This->pUnkOuter && This->bUnkOuterValid)
766 return IUnknown_Release(This->pUnkOuter);
767 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
770 /** IPersist methods **/
772 static HRESULT WINAPI VideoRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
774 VideoRendererImpl *This = (VideoRendererImpl *)iface;
776 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
778 *pClsid = CLSID_VideoRenderer;
780 return S_OK;
783 /** IMediaFilter methods **/
785 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
787 VideoRendererImpl *This = (VideoRendererImpl *)iface;
789 TRACE("(%p/%p)->()\n", This, iface);
791 EnterCriticalSection(&This->csFilter);
793 This->state = State_Stopped;
794 SetEvent(This->hEvent);
795 SetEvent(This->blocked);
796 MediaSeekingPassThru_ResetMediaTime(This->seekthru_unk);
798 LeaveCriticalSection(&This->csFilter);
800 return S_OK;
803 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
805 VideoRendererImpl *This = (VideoRendererImpl *)iface;
807 TRACE("(%p/%p)->()\n", This, iface);
809 EnterCriticalSection(&This->csFilter);
810 if (This->state != State_Paused)
812 if (This->state == State_Stopped)
814 This->pInputPin->end_of_stream = 0;
815 ResetEvent(This->hEvent);
818 This->state = State_Paused;
819 ResetEvent(This->blocked);
821 LeaveCriticalSection(&This->csFilter);
823 return S_OK;
826 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
828 VideoRendererImpl *This = (VideoRendererImpl *)iface;
830 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
832 EnterCriticalSection(&This->csFilter);
833 if (This->state != State_Running)
835 if (This->state == State_Stopped)
837 This->pInputPin->end_of_stream = 0;
838 ResetEvent(This->hEvent);
840 SetEvent(This->blocked);
842 This->rtStreamStart = tStart;
843 This->state = State_Running;
845 LeaveCriticalSection(&This->csFilter);
847 return S_OK;
850 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
852 VideoRendererImpl *This = (VideoRendererImpl *)iface;
853 HRESULT hr;
855 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
857 if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
858 hr = VFW_S_STATE_INTERMEDIATE;
859 else
860 hr = S_OK;
862 EnterCriticalSection(&This->csFilter);
864 *pState = This->state;
866 LeaveCriticalSection(&This->csFilter);
868 return hr;
871 static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
873 VideoRendererImpl *This = (VideoRendererImpl *)iface;
875 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
877 EnterCriticalSection(&This->csFilter);
879 if (This->pClock)
880 IReferenceClock_Release(This->pClock);
881 This->pClock = pClock;
882 if (This->pClock)
883 IReferenceClock_AddRef(This->pClock);
885 LeaveCriticalSection(&This->csFilter);
887 return S_OK;
890 static HRESULT WINAPI VideoRenderer_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
892 VideoRendererImpl *This = (VideoRendererImpl *)iface;
894 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
896 EnterCriticalSection(&This->csFilter);
898 *ppClock = This->pClock;
899 if (This->pClock)
900 IReferenceClock_AddRef(This->pClock);
902 LeaveCriticalSection(&This->csFilter);
904 return S_OK;
907 /** IBaseFilter implementation **/
909 static IPin* WINAPI VideoRenderer_GetPin(IBaseFilter *iface, int pos)
911 VideoRendererImpl *This = (VideoRendererImpl *)iface;
913 if (pos >= 1 || pos < 0)
914 return NULL;
916 IPin_AddRef((IPin *)This->pInputPin);
917 return (IPin *)This->pInputPin;
920 static LONG WINAPI VideoRenderer_GetPinCount(IBaseFilter *iface)
922 return 1;
925 static LONG WINAPI VideoRenderer_GetPinVersion(IBaseFilter *iface)
927 /* Our pins are static, not changing so setting static tick count is ok */
928 return 0;
931 static HRESULT WINAPI VideoRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
933 VideoRendererImpl *This = (VideoRendererImpl *)iface;
935 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
937 return EnumPins_Construct(iface, VideoRenderer_GetPin, VideoRenderer_GetPinCount, VideoRenderer_GetPinVersion, ppEnum);
940 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
942 VideoRendererImpl *This = (VideoRendererImpl *)iface;
944 FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
946 /* FIXME: critical section */
948 return E_NOTIMPL;
951 static HRESULT WINAPI VideoRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
953 VideoRendererImpl *This = (VideoRendererImpl *)iface;
955 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
957 strcpyW(pInfo->achName, This->filterInfo.achName);
958 pInfo->pGraph = This->filterInfo.pGraph;
960 if (pInfo->pGraph)
961 IFilterGraph_AddRef(pInfo->pGraph);
963 return S_OK;
966 static HRESULT WINAPI VideoRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
968 VideoRendererImpl *This = (VideoRendererImpl *)iface;
970 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
972 EnterCriticalSection(&This->csFilter);
974 if (pName)
975 strcpyW(This->filterInfo.achName, pName);
976 else
977 *This->filterInfo.achName = '\0';
978 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
980 LeaveCriticalSection(&This->csFilter);
982 return S_OK;
985 static HRESULT WINAPI VideoRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
987 VideoRendererImpl *This = (VideoRendererImpl *)iface;
988 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
989 return E_NOTIMPL;
992 static const IBaseFilterVtbl VideoRenderer_Vtbl =
994 VideoRenderer_QueryInterface,
995 VideoRenderer_AddRef,
996 VideoRenderer_Release,
997 VideoRenderer_GetClassID,
998 VideoRenderer_Stop,
999 VideoRenderer_Pause,
1000 VideoRenderer_Run,
1001 VideoRenderer_GetState,
1002 VideoRenderer_SetSyncSource,
1003 VideoRenderer_GetSyncSource,
1004 VideoRenderer_EnumPins,
1005 VideoRenderer_FindPin,
1006 VideoRenderer_QueryFilterInfo,
1007 VideoRenderer_JoinFilterGraph,
1008 VideoRenderer_QueryVendorInfo
1011 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
1013 InputPin* This = (InputPin*)iface;
1014 VideoRendererImpl *pFilter;
1015 IMediaEventSink* pEventSink;
1016 HRESULT hr;
1018 TRACE("(%p/%p)->()\n", This, iface);
1020 pFilter = (VideoRendererImpl*)This->pin.pinInfo.pFilter;
1021 hr = IFilterGraph_QueryInterface(pFilter->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
1022 if (SUCCEEDED(hr))
1024 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
1025 IMediaEventSink_Release(pEventSink);
1027 MediaSeekingPassThru_EOS(pFilter->seekthru_unk);
1029 return hr;
1032 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
1034 InputPin* This = (InputPin*)iface;
1035 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1036 HRESULT hr;
1038 TRACE("(%p/%p)->()\n", This, iface);
1040 EnterCriticalSection(This->pin.pCritSec);
1041 if (pVideoRenderer->state == State_Paused)
1042 SetEvent(pVideoRenderer->blocked);
1044 hr = InputPin_BeginFlush(iface);
1045 LeaveCriticalSection(This->pin.pCritSec);
1047 return hr;
1050 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
1052 InputPin* This = (InputPin*)iface;
1053 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1054 HRESULT hr;
1056 TRACE("(%p/%p)->()\n", This, iface);
1058 EnterCriticalSection(This->pin.pCritSec);
1059 if (pVideoRenderer->state == State_Paused)
1060 ResetEvent(pVideoRenderer->blocked);
1062 hr = InputPin_EndFlush(iface);
1063 LeaveCriticalSection(This->pin.pCritSec);
1064 MediaSeekingPassThru_ResetMediaTime(pVideoRenderer->seekthru_unk);
1066 return hr;
1069 static const IPinVtbl VideoRenderer_InputPin_Vtbl =
1071 InputPin_QueryInterface,
1072 BasePinImpl_AddRef,
1073 InputPin_Release,
1074 InputPin_Connect,
1075 InputPin_ReceiveConnection,
1076 BasePinImpl_Disconnect,
1077 BasePinImpl_ConnectedTo,
1078 BasePinImpl_ConnectionMediaType,
1079 BasePinImpl_QueryPinInfo,
1080 BasePinImpl_QueryDirection,
1081 BasePinImpl_QueryId,
1082 InputPin_QueryAccept,
1083 BasePinImpl_EnumMediaTypes,
1084 BasePinImpl_QueryInternalConnections,
1085 VideoRenderer_InputPin_EndOfStream,
1086 VideoRenderer_InputPin_BeginFlush,
1087 VideoRenderer_InputPin_EndFlush,
1088 InputPin_NewSegment
1091 /*** IUnknown methods ***/
1092 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
1093 REFIID riid,
1094 LPVOID*ppvObj) {
1095 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1097 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1099 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1102 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1103 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1105 TRACE("(%p/%p)->()\n", This, iface);
1107 return VideoRenderer_AddRef((IBaseFilter*)This);
1110 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1111 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1113 TRACE("(%p/%p)->()\n", This, iface);
1115 return VideoRenderer_Release((IBaseFilter*)This);
1118 /*** IDispatch methods ***/
1119 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1120 UINT*pctinfo) {
1121 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1123 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1125 return S_OK;
1128 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1129 UINT iTInfo,
1130 LCID lcid,
1131 ITypeInfo**ppTInfo) {
1132 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1134 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1136 return S_OK;
1139 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1140 REFIID riid,
1141 LPOLESTR*rgszNames,
1142 UINT cNames,
1143 LCID lcid,
1144 DISPID*rgDispId) {
1145 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1147 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1149 return S_OK;
1152 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1153 DISPID dispIdMember,
1154 REFIID riid,
1155 LCID lcid,
1156 WORD wFlags,
1157 DISPPARAMS*pDispParams,
1158 VARIANT*pVarResult,
1159 EXCEPINFO*pExepInfo,
1160 UINT*puArgErr) {
1161 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1163 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);
1165 return S_OK;
1168 /*** IBasicVideo methods ***/
1169 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1170 REFTIME *pAvgTimePerFrame) {
1171 AM_MEDIA_TYPE *pmt;
1172 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1174 if (!This->pInputPin->pin.pConnectedTo)
1175 return VFW_E_NOT_CONNECTED;
1177 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
1179 pmt = &This->pInputPin->pin.mtCurrent;
1180 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
1181 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)pmt->pbFormat;
1182 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1183 } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
1184 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)pmt->pbFormat;
1185 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1186 } else {
1187 ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
1188 *pAvgTimePerFrame = 0;
1190 return S_OK;
1193 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1194 LONG *pBitRate) {
1195 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1197 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1199 return S_OK;
1202 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1203 LONG *pBitErrorRate) {
1204 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1206 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1208 return S_OK;
1211 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1212 LONG *pVideoWidth) {
1213 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1215 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1217 *pVideoWidth = This->VideoWidth;
1219 return S_OK;
1222 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1223 LONG *pVideoHeight) {
1224 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1226 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1228 *pVideoHeight = This->VideoHeight;
1230 return S_OK;
1233 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1234 LONG SourceLeft) {
1235 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1237 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
1239 This->SourceRect.left = SourceLeft;
1241 return S_OK;
1244 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1245 LONG *pSourceLeft) {
1246 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1248 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1250 *pSourceLeft = This->SourceRect.left;
1252 return S_OK;
1255 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1256 LONG SourceWidth) {
1257 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1259 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
1261 This->SourceRect.right = This->SourceRect.left + SourceWidth;
1263 return S_OK;
1266 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1267 LONG *pSourceWidth) {
1268 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1270 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1272 *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1274 return S_OK;
1277 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1278 LONG SourceTop) {
1279 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1281 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
1283 This->SourceRect.top = SourceTop;
1285 return S_OK;
1288 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1289 LONG *pSourceTop) {
1290 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1292 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1294 *pSourceTop = This->SourceRect.top;
1296 return S_OK;
1299 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1300 LONG SourceHeight) {
1301 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1303 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
1305 This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1307 return S_OK;
1310 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1311 LONG *pSourceHeight) {
1312 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1314 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1316 *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1318 return S_OK;
1321 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1322 LONG DestinationLeft) {
1323 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1325 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
1327 This->DestRect.left = DestinationLeft;
1329 return S_OK;
1332 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1333 LONG *pDestinationLeft) {
1334 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1336 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1338 *pDestinationLeft = This->DestRect.left;
1340 return S_OK;
1343 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1344 LONG DestinationWidth) {
1345 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1347 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
1349 This->DestRect.right = This->DestRect.left + DestinationWidth;
1351 return S_OK;
1354 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1355 LONG *pDestinationWidth) {
1356 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1358 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1360 *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1362 return S_OK;
1365 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1366 LONG DestinationTop) {
1367 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1369 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
1371 This->DestRect.top = DestinationTop;
1373 return S_OK;
1376 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1377 LONG *pDestinationTop) {
1378 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1380 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1382 *pDestinationTop = This->DestRect.top;
1384 return S_OK;
1387 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1388 LONG DestinationHeight) {
1389 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1391 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
1393 This->DestRect.right = This->DestRect.left + DestinationHeight;
1395 return S_OK;
1398 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1399 LONG *pDestinationHeight) {
1400 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1402 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1404 *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1406 return S_OK;
1409 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1410 LONG Left,
1411 LONG Top,
1412 LONG Width,
1413 LONG Height) {
1414 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1416 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1418 This->SourceRect.left = Left;
1419 This->SourceRect.top = Top;
1420 This->SourceRect.right = Left + Width;
1421 This->SourceRect.bottom = Top + Height;
1423 return S_OK;
1426 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1427 LONG *pLeft,
1428 LONG *pTop,
1429 LONG *pWidth,
1430 LONG *pHeight) {
1431 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1433 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1435 *pLeft = This->SourceRect.left;
1436 *pTop = This->SourceRect.top;
1437 *pWidth = This->SourceRect.right - This->SourceRect.left;
1438 *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1440 return S_OK;
1443 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1444 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1446 TRACE("(%p/%p)->()\n", This, iface);
1448 This->SourceRect.left = 0;
1449 This->SourceRect.top = 0;
1450 This->SourceRect.right = This->VideoWidth;
1451 This->SourceRect.bottom = This->VideoHeight;
1453 return S_OK;
1456 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1457 LONG Left,
1458 LONG Top,
1459 LONG Width,
1460 LONG Height) {
1461 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1463 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1465 This->DestRect.left = Left;
1466 This->DestRect.top = Top;
1467 This->DestRect.right = Left + Width;
1468 This->DestRect.bottom = Top + Height;
1470 return S_OK;
1473 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1474 LONG *pLeft,
1475 LONG *pTop,
1476 LONG *pWidth,
1477 LONG *pHeight) {
1478 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1480 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1482 *pLeft = This->DestRect.left;
1483 *pTop = This->DestRect.top;
1484 *pWidth = This->DestRect.right - This->DestRect.left;
1485 *pHeight = This->DestRect.bottom - This->DestRect.top;
1487 return S_OK;
1490 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1491 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1492 RECT rect;
1494 TRACE("(%p/%p)->()\n", This, iface);
1496 if (!GetClientRect(This->hWnd, &rect))
1497 return E_FAIL;
1499 This->SourceRect.left = 0;
1500 This->SourceRect.top = 0;
1501 This->SourceRect.right = rect.right;
1502 This->SourceRect.bottom = rect.bottom;
1504 return S_OK;
1507 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1508 LONG *pWidth,
1509 LONG *pHeight) {
1510 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1512 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1514 *pWidth = This->VideoWidth;
1515 *pHeight = This->VideoHeight;
1517 return S_OK;
1520 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1521 LONG StartIndex,
1522 LONG Entries,
1523 LONG *pRetrieved,
1524 LONG *pPalette) {
1525 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1527 FIXME("(%p/%p)->(%d, %d, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1529 return S_OK;
1532 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1533 LONG *pBufferSize,
1534 LONG *pDIBImage) {
1535 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1536 BITMAPINFOHEADER *bmiHeader;
1537 LONG needed_size;
1538 AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1539 char *ptr;
1541 FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1543 EnterCriticalSection(&This->csFilter);
1545 if (!This->sample_held)
1547 LeaveCriticalSection(&This->csFilter);
1548 return (This->state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1551 if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1553 bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1555 else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1557 bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1559 else
1561 FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1562 LeaveCriticalSection(&This->csFilter);
1563 return VFW_E_RUNTIME_ERROR;
1566 needed_size = bmiHeader->biSize;
1567 needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1569 if (!pDIBImage)
1571 *pBufferSize = needed_size;
1572 LeaveCriticalSection(&This->csFilter);
1573 return S_OK;
1576 if (needed_size < *pBufferSize)
1578 ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
1579 LeaveCriticalSection(&This->csFilter);
1580 return E_FAIL;
1582 *pBufferSize = needed_size;
1584 memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1585 IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1586 memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1588 LeaveCriticalSection(&This->csFilter);
1590 return S_OK;
1593 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1594 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1596 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1598 return S_OK;
1601 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1602 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1604 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1606 return S_OK;
1610 static const IBasicVideoVtbl IBasicVideo_VTable =
1612 Basicvideo_QueryInterface,
1613 Basicvideo_AddRef,
1614 Basicvideo_Release,
1615 Basicvideo_GetTypeInfoCount,
1616 Basicvideo_GetTypeInfo,
1617 Basicvideo_GetIDsOfNames,
1618 Basicvideo_Invoke,
1619 Basicvideo_get_AvgTimePerFrame,
1620 Basicvideo_get_BitRate,
1621 Basicvideo_get_BitErrorRate,
1622 Basicvideo_get_VideoWidth,
1623 Basicvideo_get_VideoHeight,
1624 Basicvideo_put_SourceLeft,
1625 Basicvideo_get_SourceLeft,
1626 Basicvideo_put_SourceWidth,
1627 Basicvideo_get_SourceWidth,
1628 Basicvideo_put_SourceTop,
1629 Basicvideo_get_SourceTop,
1630 Basicvideo_put_SourceHeight,
1631 Basicvideo_get_SourceHeight,
1632 Basicvideo_put_DestinationLeft,
1633 Basicvideo_get_DestinationLeft,
1634 Basicvideo_put_DestinationWidth,
1635 Basicvideo_get_DestinationWidth,
1636 Basicvideo_put_DestinationTop,
1637 Basicvideo_get_DestinationTop,
1638 Basicvideo_put_DestinationHeight,
1639 Basicvideo_get_DestinationHeight,
1640 Basicvideo_SetSourcePosition,
1641 Basicvideo_GetSourcePosition,
1642 Basicvideo_SetDefaultSourcePosition,
1643 Basicvideo_SetDestinationPosition,
1644 Basicvideo_GetDestinationPosition,
1645 Basicvideo_SetDefaultDestinationPosition,
1646 Basicvideo_GetVideoSize,
1647 Basicvideo_GetVideoPaletteEntries,
1648 Basicvideo_GetCurrentImage,
1649 Basicvideo_IsUsingDefaultSource,
1650 Basicvideo_IsUsingDefaultDestination
1654 /*** IUnknown methods ***/
1655 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1656 REFIID riid,
1657 LPVOID*ppvObj) {
1658 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1660 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1662 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1665 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1666 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1668 TRACE("(%p/%p)->()\n", This, iface);
1670 return VideoRenderer_AddRef((IBaseFilter*)This);
1673 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1674 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1676 TRACE("(%p/%p)->()\n", This, iface);
1678 return VideoRenderer_Release((IBaseFilter*)This);
1681 /*** IDispatch methods ***/
1682 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1683 UINT*pctinfo) {
1684 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1686 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1688 return S_OK;
1691 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1692 UINT iTInfo,
1693 LCID lcid,
1694 ITypeInfo**ppTInfo) {
1695 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1697 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1699 return S_OK;
1702 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1703 REFIID riid,
1704 LPOLESTR*rgszNames,
1705 UINT cNames,
1706 LCID lcid,
1707 DISPID*rgDispId) {
1708 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1710 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1712 return S_OK;
1715 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1716 DISPID dispIdMember,
1717 REFIID riid,
1718 LCID lcid,
1719 WORD wFlags,
1720 DISPPARAMS*pDispParams,
1721 VARIANT*pVarResult,
1722 EXCEPINFO*pExepInfo,
1723 UINT*puArgErr) {
1724 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1726 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);
1728 return S_OK;
1731 /*** IVideoWindow methods ***/
1732 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1733 BSTR strCaption) {
1734 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1736 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1738 if (!SetWindowTextW(This->hWnd, strCaption))
1739 return E_FAIL;
1741 return S_OK;
1744 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1745 BSTR *strCaption) {
1746 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1748 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1750 GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1752 return S_OK;
1755 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1756 LONG WindowStyle) {
1757 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1758 LONG old;
1760 old = GetWindowLongA(This->hWnd, GWL_STYLE);
1762 TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
1764 if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1765 return E_INVALIDARG;
1767 SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1768 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1769 This->WindowStyle = WindowStyle;
1771 return S_OK;
1774 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1775 LONG *WindowStyle) {
1776 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1778 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1780 *WindowStyle = This->WindowStyle;
1782 return S_OK;
1785 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1786 LONG WindowStyleEx) {
1787 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1789 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
1791 if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1792 return E_FAIL;
1794 return S_OK;
1797 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1798 LONG *WindowStyleEx) {
1799 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1801 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1803 *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1805 return S_OK;
1808 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1809 LONG AutoShow) {
1810 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1812 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
1814 This->AutoShow = AutoShow;
1816 return S_OK;
1819 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1820 LONG *AutoShow) {
1821 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1823 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1825 *AutoShow = This->AutoShow;
1827 return S_OK;
1830 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1831 LONG WindowState) {
1832 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1834 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
1835 ShowWindow(This->hWnd, WindowState);
1836 return S_OK;
1839 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1840 LONG *WindowState) {
1841 WINDOWPLACEMENT place;
1842 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1844 place.length = sizeof(place);
1845 GetWindowPlacement(This->hWnd, &place);
1846 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
1847 *WindowState = place.showCmd;
1849 return S_OK;
1852 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1853 LONG BackgroundPalette) {
1854 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1856 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
1858 return S_OK;
1861 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1862 LONG *pBackgroundPalette) {
1863 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1865 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1867 return S_OK;
1870 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1871 LONG Visible) {
1872 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1874 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
1876 ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1878 return S_OK;
1881 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1882 LONG *pVisible) {
1883 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1885 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1887 *pVisible = IsWindowVisible(This->hWnd);
1889 return S_OK;
1892 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1893 LONG Left) {
1894 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1896 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
1898 if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1899 return E_FAIL;
1901 This->WindowPos.left = Left;
1903 return S_OK;
1906 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1907 LONG *pLeft) {
1908 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1910 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1912 *pLeft = This->WindowPos.left;
1914 return S_OK;
1917 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1918 LONG Width) {
1919 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1921 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
1923 if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1924 return E_FAIL;
1926 This->WindowPos.right = This->WindowPos.left + Width;
1928 return S_OK;
1931 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1932 LONG *pWidth) {
1933 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1935 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1937 *pWidth = This->WindowPos.right - This->WindowPos.left;
1939 return S_OK;
1942 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1943 LONG Top) {
1944 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1946 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
1948 if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1949 return E_FAIL;
1951 This->WindowPos.top = Top;
1953 return S_OK;
1956 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1957 LONG *pTop) {
1958 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1960 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1962 *pTop = This->WindowPos.top;
1964 return S_OK;
1967 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1968 LONG Height) {
1969 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1971 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
1973 if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1974 return E_FAIL;
1976 This->WindowPos.bottom = This->WindowPos.top + Height;
1978 return S_OK;
1981 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1982 LONG *pHeight) {
1983 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1985 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1987 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1989 return S_OK;
1992 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1993 OAHWND Owner) {
1994 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1996 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1998 SetParent(This->hWnd, (HWND)Owner);
1999 if (This->WindowStyle & WS_CHILD)
2001 LONG old = GetWindowLongA(This->hWnd, GWL_STYLE);
2002 if (old != This->WindowStyle)
2004 SetWindowLongA(This->hWnd, GWL_STYLE, This->WindowStyle);
2005 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
2009 return S_OK;
2012 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
2013 OAHWND *Owner) {
2014 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2016 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
2018 *(HWND*)Owner = GetParent(This->hWnd);
2020 return S_OK;
2023 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
2024 OAHWND Drain) {
2025 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2027 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
2029 This->hWndMsgDrain = (HWND)Drain;
2031 return S_OK;
2034 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
2035 OAHWND *Drain) {
2036 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2038 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
2040 *Drain = (OAHWND)This->hWndMsgDrain;
2042 return S_OK;
2045 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
2046 LONG *Color) {
2047 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2049 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
2051 return S_OK;
2054 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
2055 LONG Color) {
2056 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2058 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
2060 return S_OK;
2063 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
2064 LONG *FullScreenMode) {
2065 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2067 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
2069 return S_OK;
2072 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
2073 LONG FullScreenMode) {
2074 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2076 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
2078 return S_OK;
2081 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2082 LONG Focus) {
2083 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2084 BOOL ret;
2085 IPin* pPin;
2086 HRESULT hr;
2088 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
2090 if ((Focus != FALSE) && (Focus != TRUE))
2091 return E_INVALIDARG;
2093 hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2094 if ((hr != S_OK) || !pPin)
2095 return VFW_E_NOT_CONNECTED;
2097 if (Focus)
2098 ret = SetForegroundWindow(This->hWnd);
2099 else
2100 ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2102 if (!ret)
2103 return E_FAIL;
2105 return S_OK;
2108 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2109 OAHWND hwnd,
2110 LONG uMsg,
2111 LONG_PTR wParam,
2112 LONG_PTR lParam) {
2113 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2115 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
2117 if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
2118 return E_FAIL;
2120 return S_OK;
2123 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2124 LONG Left,
2125 LONG Top,
2126 LONG Width,
2127 LONG Height) {
2128 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2130 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
2132 if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2133 return E_FAIL;
2135 This->WindowPos.left = Left;
2136 This->WindowPos.top = Top;
2137 This->WindowPos.right = Left + Width;
2138 This->WindowPos.bottom = Top + Height;
2140 return S_OK;
2143 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2144 LONG *pLeft,
2145 LONG *pTop,
2146 LONG *pWidth,
2147 LONG *pHeight) {
2148 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2150 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2152 *pLeft = This->WindowPos.left;
2153 *pTop = This->WindowPos.top;
2154 *pWidth = This->WindowPos.right - This->WindowPos.left;
2155 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2157 return S_OK;
2160 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2161 LONG *pWidth,
2162 LONG *pHeight) {
2163 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2165 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2167 *pWidth = This->VideoWidth;
2168 *pHeight = This->VideoHeight;
2170 return S_OK;
2173 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2174 LONG *pWidth,
2175 LONG *pHeight) {
2176 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2178 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2180 *pWidth = This->VideoWidth;
2181 *pHeight = This->VideoHeight;
2183 return S_OK;
2186 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2187 LONG *pLeft,
2188 LONG *pTop,
2189 LONG *pWidth,
2190 LONG *pHeight) {
2191 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2193 FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2195 return S_OK;
2198 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2199 LONG HideCursor) {
2200 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2202 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
2204 return S_OK;
2207 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2208 LONG *CursorHidden) {
2209 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2211 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2213 return S_OK;
2216 static const IVideoWindowVtbl IVideoWindow_VTable =
2218 Videowindow_QueryInterface,
2219 Videowindow_AddRef,
2220 Videowindow_Release,
2221 Videowindow_GetTypeInfoCount,
2222 Videowindow_GetTypeInfo,
2223 Videowindow_GetIDsOfNames,
2224 Videowindow_Invoke,
2225 Videowindow_put_Caption,
2226 Videowindow_get_Caption,
2227 Videowindow_put_WindowStyle,
2228 Videowindow_get_WindowStyle,
2229 Videowindow_put_WindowStyleEx,
2230 Videowindow_get_WindowStyleEx,
2231 Videowindow_put_AutoShow,
2232 Videowindow_get_AutoShow,
2233 Videowindow_put_WindowState,
2234 Videowindow_get_WindowState,
2235 Videowindow_put_BackgroundPalette,
2236 Videowindow_get_BackgroundPalette,
2237 Videowindow_put_Visible,
2238 Videowindow_get_Visible,
2239 Videowindow_put_Left,
2240 Videowindow_get_Left,
2241 Videowindow_put_Width,
2242 Videowindow_get_Width,
2243 Videowindow_put_Top,
2244 Videowindow_get_Top,
2245 Videowindow_put_Height,
2246 Videowindow_get_Height,
2247 Videowindow_put_Owner,
2248 Videowindow_get_Owner,
2249 Videowindow_put_MessageDrain,
2250 Videowindow_get_MessageDrain,
2251 Videowindow_get_BorderColor,
2252 Videowindow_put_BorderColor,
2253 Videowindow_get_FullScreenMode,
2254 Videowindow_put_FullScreenMode,
2255 Videowindow_SetWindowForeground,
2256 Videowindow_NotifyOwnerMessage,
2257 Videowindow_SetWindowPosition,
2258 Videowindow_GetWindowPosition,
2259 Videowindow_GetMinIdealImageSize,
2260 Videowindow_GetMaxIdealImageSize,
2261 Videowindow_GetRestorePosition,
2262 Videowindow_HideCursor,
2263 Videowindow_IsCursorHidden