Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / quartz / videorenderer.c
blob112289afea4bd3d1245d8e3bf464edae81c1a89a
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;
55 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl;
56 static const IQualityControlVtbl VideoRenderer_QualityControl_Vtbl = {
57 QualityControlImpl_QueryInterface,
58 QualityControlImpl_AddRef,
59 QualityControlImpl_Release,
60 QualityControlImpl_Notify,
61 QualityControlImpl_SetSink
64 typedef struct VideoRendererImpl
66 BaseFilter filter;
67 const IBasicVideoVtbl * IBasicVideo_vtbl;
68 const IVideoWindowVtbl * IVideoWindow_vtbl;
69 const IUnknownVtbl * IInner_vtbl;
70 const IAMFilterMiscFlagsVtbl *IAMFilterMiscFlags_vtbl;
71 IUnknown *seekthru_unk;
72 QualityControlImpl qcimpl;
74 BaseInputPin *pInputPin;
76 BOOL init;
77 HANDLE hThread;
78 HANDLE blocked;
80 DWORD ThreadID;
81 HANDLE hEvent;
82 BOOL ThreadResult;
83 HWND hWnd;
84 HWND hWndMsgDrain;
85 BOOL AutoShow;
86 RECT SourceRect;
87 RECT DestRect;
88 RECT WindowPos;
89 LONG VideoWidth;
90 LONG VideoHeight;
91 IUnknown * pUnkOuter;
92 BOOL bUnkOuterValid;
93 BOOL bAggregatable;
94 LONG WindowStyle;
96 /* During pause we can hold a single sample, for use in GetCurrentImage */
97 IMediaSample *sample_held;
98 } VideoRendererImpl;
100 static LRESULT CALLBACK VideoWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
102 VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongPtrW(hwnd, 0);
103 LPRECT lprect = (LPRECT)lParam;
105 if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
107 switch(uMsg)
109 case WM_KEYDOWN:
110 case WM_KEYUP:
111 case WM_LBUTTONDBLCLK:
112 case WM_LBUTTONDOWN:
113 case WM_LBUTTONUP:
114 case WM_MBUTTONDBLCLK:
115 case WM_MBUTTONDOWN:
116 case WM_MBUTTONUP:
117 case WM_MOUSEACTIVATE:
118 case WM_MOUSEMOVE:
119 case WM_NCLBUTTONDBLCLK:
120 case WM_NCLBUTTONDOWN:
121 case WM_NCLBUTTONUP:
122 case WM_NCMBUTTONDBLCLK:
123 case WM_NCMBUTTONDOWN:
124 case WM_NCMBUTTONUP:
125 case WM_NCMOUSEMOVE:
126 case WM_NCRBUTTONDBLCLK:
127 case WM_NCRBUTTONDOWN:
128 case WM_NCRBUTTONUP:
129 case WM_RBUTTONDBLCLK:
130 case WM_RBUTTONDOWN:
131 case WM_RBUTTONUP:
132 PostMessageA(pVideoRenderer->hWndMsgDrain, uMsg, wParam, lParam);
133 break;
134 default:
135 break;
139 switch(uMsg)
141 case WM_SIZING:
142 /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
143 SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
144 GetClientRect(hwnd, &pVideoRenderer->DestRect);
145 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
146 pVideoRenderer->DestRect.left,
147 pVideoRenderer->DestRect.top,
148 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
149 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
150 return TRUE;
151 case WM_SIZE:
152 TRACE("WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
153 GetClientRect(hwnd, &pVideoRenderer->DestRect);
154 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
155 pVideoRenderer->DestRect.left,
156 pVideoRenderer->DestRect.top,
157 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
158 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
159 return TRUE;
160 default:
161 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
163 return 0;
166 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
168 WNDCLASSA winclass;
170 TRACE("(%p)->()\n", This);
172 winclass.style = 0;
173 winclass.lpfnWndProc = VideoWndProcA;
174 winclass.cbClsExtra = 0;
175 winclass.cbWndExtra = sizeof(VideoRendererImpl*);
176 winclass.hInstance = NULL;
177 winclass.hIcon = NULL;
178 winclass.hCursor = NULL;
179 winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
180 winclass.lpszMenuName = NULL;
181 winclass.lpszClassName = "Wine ActiveMovie Class";
183 if (!wnd_class_registered)
185 if (!RegisterClassA(&winclass))
187 ERR("Unable to register window %u\n", GetLastError());
188 return FALSE;
190 wnd_class_registered = TRUE;
193 This->hWnd = CreateWindowExA(0, "Wine ActiveMovie Class", "Wine ActiveMovie Window", WS_SIZEBOX,
194 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
195 NULL, NULL, NULL);
197 if (!This->hWnd)
199 ERR("Unable to create window\n");
200 return FALSE;
203 SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
205 return TRUE;
208 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
210 VideoRendererImpl* This = lpParameter;
211 MSG msg;
212 BOOL fGotMessage;
214 TRACE("Starting message loop\n");
216 if (!CreateRenderingWindow(This))
218 This->ThreadResult = FALSE;
219 SetEvent(This->hEvent);
220 return 0;
223 This->ThreadResult = TRUE;
224 SetEvent(This->hEvent);
226 while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
228 TranslateMessage(&msg);
229 DispatchMessageA(&msg);
232 TRACE("End of message loop\n");
234 return msg.wParam;
237 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
239 This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
240 if (!This->hEvent)
241 return FALSE;
243 This->hThread = CreateThread(NULL, 0, MessageLoop, This, 0, &This->ThreadID);
244 if (!This->hThread)
246 CloseHandle(This->hEvent);
247 return FALSE;
250 WaitForSingleObject(This->hEvent, INFINITE);
252 if (!This->ThreadResult)
254 CloseHandle(This->hEvent);
255 CloseHandle(This->hThread);
256 return FALSE;
259 return TRUE;
262 static void VideoRenderer_AutoShowWindow(VideoRendererImpl *This) {
263 if (!This->init && (!This->WindowPos.right || !This->WindowPos.top))
265 DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
266 DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
268 if (!This->WindowPos.right)
270 This->WindowPos.left = This->SourceRect.left;
271 This->WindowPos.right = This->SourceRect.right;
273 if (!This->WindowPos.bottom)
275 This->WindowPos.top = This->SourceRect.top;
276 This->WindowPos.bottom = This->SourceRect.bottom;
279 AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);
281 TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
282 SetWindowPos(This->hWnd, NULL,
283 This->WindowPos.left,
284 This->WindowPos.top,
285 This->WindowPos.right - This->WindowPos.left,
286 This->WindowPos.bottom - This->WindowPos.top,
287 SWP_NOZORDER|SWP_NOMOVE|SWP_DEFERERASE);
289 GetClientRect(This->hWnd, &This->DestRect);
291 else if (!This->init)
292 This->DestRect = This->WindowPos;
293 This->init = TRUE;
294 if (This->AutoShow)
295 ShowWindow(This->hWnd, SW_SHOW);
298 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
300 AM_MEDIA_TYPE amt;
301 HRESULT hr = S_OK;
302 DDSURFACEDESC sdesc;
303 HDC hDC;
304 BITMAPINFOHEADER *bmiHeader;
306 TRACE("(%p)->(%p, %d)\n", This, data, size);
308 sdesc.dwSize = sizeof(sdesc);
309 hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
310 if (FAILED(hr)) {
311 ERR("Unable to retrieve media type\n");
312 return hr;
315 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
317 bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
319 else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
321 bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
323 else
325 FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
326 return VFW_E_RUNTIME_ERROR;
329 TRACE("biSize = %d\n", bmiHeader->biSize);
330 TRACE("biWidth = %d\n", bmiHeader->biWidth);
331 TRACE("biHeight = %d\n", bmiHeader->biHeight);
332 TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
333 TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
334 TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
335 TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
337 hDC = GetDC(This->hWnd);
339 if (!hDC) {
340 ERR("Cannot get DC from window!\n");
341 return E_FAIL;
344 TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
345 TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
347 StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
348 This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
349 This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
350 data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
352 ReleaseDC(This->hWnd, hDC);
354 return S_OK;
357 static HRESULT WINAPI VideoRenderer_Receive(BaseInputPin* pin, IMediaSample * pSample)
359 VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
360 LPBYTE pbSrcStream = NULL;
361 LONG cbSrcStream = 0;
362 REFERENCE_TIME tStart, tStop;
363 HRESULT hr;
365 TRACE("(%p)->(%p)\n", pin, pSample);
367 EnterCriticalSection(&This->filter.csFilter);
369 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
371 LeaveCriticalSection(&This->filter.csFilter);
372 return S_FALSE;
375 if (This->filter.state == State_Stopped)
377 LeaveCriticalSection(&This->filter.csFilter);
378 return VFW_E_WRONG_STATE;
381 if (IMediaSample_GetMediaTime(pSample, &tStart, &tStop) == S_OK)
382 MediaSeekingPassThru_RegisterMediaTime(This->seekthru_unk, tStart);
384 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
385 if (IMediaSample_IsPreroll(pSample) == S_OK) {
386 LeaveCriticalSection(&This->filter.csFilter);
387 return S_OK;
390 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
391 if (FAILED(hr))
393 ERR("Cannot get pointer to sample data (%x)\n", hr);
394 LeaveCriticalSection(&This->filter.csFilter);
395 return hr;
398 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
400 TRACE("val %p %d\n", pbSrcStream, cbSrcStream);
402 #if 0 /* For debugging purpose */
404 int i;
405 for(i = 0; i < cbSrcStream; i++)
407 if ((i!=0) && !(i%16))
408 TRACE("\n");
409 TRACE("%02x ", pbSrcStream[i]);
411 TRACE("\n");
413 #endif
415 SetEvent(This->hEvent);
416 if (This->filter.state == State_Paused)
418 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
419 This->sample_held = pSample;
420 LeaveCriticalSection(&This->filter.csFilter);
421 WaitForSingleObject(This->blocked, INFINITE);
422 EnterCriticalSection(&This->filter.csFilter);
423 This->sample_held = NULL;
424 if (This->filter.state == State_Paused)
426 /* Flushing */
427 LeaveCriticalSection(&This->filter.csFilter);
428 return S_OK;
430 if (This->filter.state == State_Stopped)
432 LeaveCriticalSection(&This->filter.csFilter);
433 return VFW_E_WRONG_STATE;
435 } else {
436 hr = QualityControlRender_WaitFor(&This->qcimpl, pSample, This->blocked);
437 if (hr == S_OK) {
438 QualityControlRender_BeginRender(&This->qcimpl);
439 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
440 QualityControlRender_EndRender(&This->qcimpl);
442 QualityControlRender_DoQOS(&This->qcimpl);
444 LeaveCriticalSection(&This->filter.csFilter);
445 return S_OK;
448 static HRESULT WINAPI VideoRenderer_CheckMediaType(BasePin *iface, const AM_MEDIA_TYPE * pmt)
450 BaseInputPin* pin = (BaseInputPin*)iface;
451 VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
453 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
454 return S_FALSE;
456 if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
457 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
458 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
459 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
461 LONG height;
463 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
465 VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
466 This->SourceRect.left = 0;
467 This->SourceRect.top = 0;
468 This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
469 height = format->bmiHeader.biHeight;
470 if (height < 0)
471 This->SourceRect.bottom = This->VideoHeight = -height;
472 else
473 This->SourceRect.bottom = This->VideoHeight = height;
475 else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
477 VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
479 This->SourceRect.left = 0;
480 This->SourceRect.top = 0;
481 This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
482 height = format2->bmiHeader.biHeight;
483 if (height < 0)
484 This->SourceRect.bottom = This->VideoHeight = -height;
485 else
486 This->SourceRect.bottom = This->VideoHeight = height;
488 else
490 WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
491 return S_FALSE;
493 return S_OK;
495 return S_FALSE;
498 static IPin* WINAPI VideoRenderer_GetPin(BaseFilter *iface, int pos)
500 VideoRendererImpl *This = (VideoRendererImpl *)iface;
502 if (pos >= 1 || pos < 0)
503 return NULL;
505 IPin_AddRef((IPin *)This->pInputPin);
506 return (IPin *)This->pInputPin;
509 static LONG WINAPI VideoRenderer_GetPinCount(BaseFilter *iface)
511 return 1;
514 static const BaseFilterFuncTable BaseFuncTable = {
515 VideoRenderer_GetPin,
516 VideoRenderer_GetPinCount
519 static const BasePinFuncTable input_BaseFuncTable = {
520 VideoRenderer_CheckMediaType,
521 NULL,
522 BasePinImpl_GetMediaTypeVersion,
523 BasePinImpl_GetMediaType
526 static const BaseInputPinFuncTable input_BaseInputFuncTable = {
527 VideoRenderer_Receive
530 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
532 HRESULT hr;
533 PIN_INFO piInput;
534 VideoRendererImpl * pVideoRenderer;
535 ISeekingPassThru *passthru;
537 TRACE("(%p, %p)\n", pUnkOuter, ppv);
539 *ppv = NULL;
541 pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
542 pVideoRenderer->pUnkOuter = pUnkOuter;
543 pVideoRenderer->bUnkOuterValid = FALSE;
544 pVideoRenderer->bAggregatable = FALSE;
545 pVideoRenderer->IInner_vtbl = &IInner_VTable;
546 pVideoRenderer->IAMFilterMiscFlags_vtbl = &IAMFilterMiscFlags_Vtbl;
548 BaseFilter_Init(&pVideoRenderer->filter, &VideoRenderer_Vtbl, &CLSID_VideoRenderer, (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter"), &BaseFuncTable);
550 pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
551 pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
553 pVideoRenderer->init = 0;
554 pVideoRenderer->AutoShow = 1;
555 ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
556 ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
557 ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
558 pVideoRenderer->hWndMsgDrain = NULL;
559 pVideoRenderer->WindowStyle = WS_OVERLAPPED;
561 /* construct input pin */
562 piInput.dir = PINDIR_INPUT;
563 piInput.pFilter = (IBaseFilter *)pVideoRenderer;
564 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
566 hr = BaseInputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, &input_BaseFuncTable, &input_BaseInputFuncTable, &pVideoRenderer->filter.csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
568 if (SUCCEEDED(hr))
570 hr = CoCreateInstance(&CLSID_SeekingPassThru, pUnkOuter ? pUnkOuter : (IUnknown*)&pVideoRenderer->IInner_vtbl, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&pVideoRenderer->seekthru_unk);
571 if (FAILED(hr)) {
572 IPin_Release((IPin*)pVideoRenderer->pInputPin);
573 goto fail;
575 IUnknown_QueryInterface(pVideoRenderer->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
576 ISeekingPassThru_Init(passthru, TRUE, (IPin*)pVideoRenderer->pInputPin);
577 ISeekingPassThru_Release(passthru);
578 pVideoRenderer->sample_held = NULL;
579 *ppv = pVideoRenderer;
581 if (FAILED(hr))
582 goto fail;
584 QualityControlImpl_init(&pVideoRenderer->qcimpl, (IPin*)pVideoRenderer->pInputPin, (IBaseFilter*)pVideoRenderer);
585 pVideoRenderer->qcimpl.lpVtbl = &VideoRenderer_QualityControl_Vtbl;
587 if (!CreateRenderingSubsystem(pVideoRenderer))
588 return E_FAIL;
590 pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
591 if (!pVideoRenderer->blocked)
593 hr = HRESULT_FROM_WIN32(GetLastError());
594 IUnknown_Release((IUnknown *)pVideoRenderer);
597 return hr;
598 fail:
599 BaseFilterImpl_Release((IBaseFilter*)pVideoRenderer);
600 CoTaskMemFree(pVideoRenderer);
601 return hr;
604 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
606 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
607 return VideoRenderer_create(pUnkOuter, ppv);
610 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
612 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
613 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
615 if (This->bAggregatable)
616 This->bUnkOuterValid = TRUE;
618 *ppv = NULL;
620 if (IsEqualIID(riid, &IID_IUnknown))
621 *ppv = &This->IInner_vtbl;
622 else if (IsEqualIID(riid, &IID_IPersist))
623 *ppv = This;
624 else if (IsEqualIID(riid, &IID_IMediaFilter))
625 *ppv = This;
626 else if (IsEqualIID(riid, &IID_IBaseFilter))
627 *ppv = This;
628 else if (IsEqualIID(riid, &IID_IBasicVideo))
629 *ppv = &This->IBasicVideo_vtbl;
630 else if (IsEqualIID(riid, &IID_IVideoWindow))
631 *ppv = &This->IVideoWindow_vtbl;
632 else if (IsEqualIID(riid, &IID_IMediaSeeking))
633 return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
634 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
635 *ppv = &This->IAMFilterMiscFlags_vtbl;
636 else if (IsEqualIID(riid, &IID_IQualityControl))
637 *ppv = &This->qcimpl;
639 if (*ppv)
641 IUnknown_AddRef((IUnknown *)(*ppv));
642 return S_OK;
645 if (!IsEqualIID(riid, &IID_IPin))
646 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
648 return E_NOINTERFACE;
651 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
653 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
654 ULONG refCount = InterlockedIncrement(&This->filter.refCount);
656 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
658 return refCount;
661 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
663 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
664 ULONG refCount = InterlockedDecrement(&This->filter.refCount);
666 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
668 if (!refCount)
670 IPin *pConnectedTo;
672 DestroyWindow(This->hWnd);
673 PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
674 WaitForSingleObject(This->hThread, INFINITE);
675 CloseHandle(This->hThread);
676 CloseHandle(This->hEvent);
678 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
680 IPin_Disconnect(pConnectedTo);
681 IPin_Release(pConnectedTo);
683 IPin_Disconnect((IPin *)This->pInputPin);
685 IPin_Release((IPin *)This->pInputPin);
687 This->filter.lpVtbl = NULL;
688 IUnknown_Release(This->seekthru_unk);
689 This->filter.csFilter.DebugInfo->Spare[0] = 0;
690 DeleteCriticalSection(&This->filter.csFilter);
692 TRACE("Destroying Video Renderer\n");
693 CoTaskMemFree(This);
695 return 0;
697 else
698 return refCount;
701 static const IUnknownVtbl IInner_VTable =
703 VideoRendererInner_QueryInterface,
704 VideoRendererInner_AddRef,
705 VideoRendererInner_Release
708 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
710 VideoRendererImpl *This = (VideoRendererImpl *)iface;
712 if (This->bAggregatable)
713 This->bUnkOuterValid = TRUE;
715 if (This->pUnkOuter)
717 if (This->bAggregatable)
718 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
720 if (IsEqualIID(riid, &IID_IUnknown))
722 HRESULT hr;
724 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
725 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
726 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
727 This->bAggregatable = TRUE;
728 return hr;
731 *ppv = NULL;
732 return E_NOINTERFACE;
735 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
738 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
740 VideoRendererImpl *This = (VideoRendererImpl *)iface;
742 if (This->pUnkOuter && This->bUnkOuterValid)
743 return IUnknown_AddRef(This->pUnkOuter);
744 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
747 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
749 VideoRendererImpl *This = (VideoRendererImpl *)iface;
751 if (This->pUnkOuter && This->bUnkOuterValid)
752 return IUnknown_Release(This->pUnkOuter);
753 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
756 /** IMediaFilter methods **/
758 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
760 VideoRendererImpl *This = (VideoRendererImpl *)iface;
762 TRACE("(%p/%p)->()\n", This, iface);
764 EnterCriticalSection(&This->filter.csFilter);
766 This->filter.state = State_Stopped;
767 SetEvent(This->hEvent);
768 SetEvent(This->blocked);
769 MediaSeekingPassThru_ResetMediaTime(This->seekthru_unk);
770 if (This->AutoShow)
771 /* Black it out */
772 RedrawWindow(This->hWnd, NULL, NULL, RDW_INVALIDATE|RDW_ERASE);
774 LeaveCriticalSection(&This->filter.csFilter);
776 return S_OK;
779 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
781 VideoRendererImpl *This = (VideoRendererImpl *)iface;
783 TRACE("(%p/%p)->()\n", This, iface);
785 EnterCriticalSection(&This->filter.csFilter);
786 if (This->filter.state != State_Paused)
788 if (This->filter.state == State_Stopped)
790 This->pInputPin->end_of_stream = 0;
791 ResetEvent(This->hEvent);
792 VideoRenderer_AutoShowWindow(This);
795 This->filter.state = State_Paused;
796 ResetEvent(This->blocked);
798 LeaveCriticalSection(&This->filter.csFilter);
800 return S_OK;
803 static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter *iface, IReferenceClock *clock) {
804 VideoRendererImpl *This = (VideoRendererImpl *)iface;
805 HRESULT hr;
807 EnterCriticalSection(&This->filter.csFilter);
808 QualityControlRender_SetClock(&This->qcimpl, clock);
809 hr = BaseFilterImpl_SetSyncSource(iface, clock);
810 LeaveCriticalSection(&This->filter.csFilter);
811 return hr;
814 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
816 HRESULT hr = S_OK;
817 VideoRendererImpl *This = (VideoRendererImpl *)iface;
819 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
821 EnterCriticalSection(&This->filter.csFilter);
822 if (This->filter.state == State_Running)
823 goto out;
824 if (This->pInputPin->pin.pConnectedTo)
826 if (This->filter.state == State_Stopped)
828 This->pInputPin->end_of_stream = 0;
829 ResetEvent(This->hEvent);
830 VideoRenderer_AutoShowWindow(This);
832 SetEvent(This->blocked);
834 This->filter.rtStreamStart = tStart;
835 This->filter.state = State_Running;
836 QualityControlRender_Start(&This->qcimpl, tStart);
837 } else if (This->filter.filterInfo.pGraph) {
838 IMediaEventSink *pEventSink;
839 hr = IFilterGraph_QueryInterface(This->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
840 if (SUCCEEDED(hr))
842 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)This);
843 IMediaEventSink_Release(pEventSink);
845 hr = S_OK;
847 if (SUCCEEDED(hr))
848 This->filter.state = State_Running;
849 out:
850 LeaveCriticalSection(&This->filter.csFilter);
852 return hr;
855 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
857 VideoRendererImpl *This = (VideoRendererImpl *)iface;
858 HRESULT hr;
860 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
862 if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
863 hr = VFW_S_STATE_INTERMEDIATE;
864 else
865 hr = S_OK;
867 BaseFilterImpl_GetState(iface, dwMilliSecsTimeout, pState);
869 return hr;
872 /** IBaseFilter implementation **/
874 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
876 VideoRendererImpl *This = (VideoRendererImpl *)iface;
878 FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
880 /* FIXME: critical section */
882 return E_NOTIMPL;
885 static const IBaseFilterVtbl VideoRenderer_Vtbl =
887 VideoRenderer_QueryInterface,
888 VideoRenderer_AddRef,
889 VideoRenderer_Release,
890 BaseFilterImpl_GetClassID,
891 VideoRenderer_Stop,
892 VideoRenderer_Pause,
893 VideoRenderer_Run,
894 VideoRenderer_GetState,
895 VideoRenderer_SetSyncSource,
896 BaseFilterImpl_GetSyncSource,
897 BaseFilterImpl_EnumPins,
898 VideoRenderer_FindPin,
899 BaseFilterImpl_QueryFilterInfo,
900 BaseFilterImpl_JoinFilterGraph,
901 BaseFilterImpl_QueryVendorInfo
904 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
906 BaseInputPin* This = (BaseInputPin*)iface;
907 VideoRendererImpl *pFilter;
908 IMediaEventSink* pEventSink;
909 HRESULT hr = S_OK;
911 TRACE("(%p/%p)->()\n", This, iface);
913 EnterCriticalSection(This->pin.pCritSec);
914 pFilter = (VideoRendererImpl*)This->pin.pinInfo.pFilter;
915 if (This->flushing || This->end_of_stream)
916 goto out;
917 hr = IFilterGraph_QueryInterface(pFilter->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
918 if (SUCCEEDED(hr))
920 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)pFilter);
921 IMediaEventSink_Release(pEventSink);
923 MediaSeekingPassThru_EOS(pFilter->seekthru_unk);
924 This->end_of_stream = 1;
925 out:
926 LeaveCriticalSection(This->pin.pCritSec);
928 return hr;
931 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
933 BaseInputPin* This = (BaseInputPin*)iface;
934 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
936 TRACE("(%p/%p)->()\n", This, iface);
938 SetEvent(pVideoRenderer->blocked);
939 return BaseInputPinImpl_BeginFlush(iface);
942 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
944 BaseInputPin* This = (BaseInputPin*)iface;
945 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
946 HRESULT hr;
948 TRACE("(%p/%p)->()\n", This, iface);
950 EnterCriticalSection(This->pin.pCritSec);
951 if (pVideoRenderer->filter.state == State_Paused) {
952 ResetEvent(pVideoRenderer->blocked);
953 ResetEvent(pVideoRenderer->hEvent);
956 QualityControlRender_Start(&pVideoRenderer->qcimpl, pVideoRenderer->filter.rtStreamStart);
957 hr = BaseInputPinImpl_EndFlush(iface);
958 LeaveCriticalSection(This->pin.pCritSec);
959 MediaSeekingPassThru_ResetMediaTime(pVideoRenderer->seekthru_unk);
961 return hr;
964 static const IPinVtbl VideoRenderer_InputPin_Vtbl =
966 BaseInputPinImpl_QueryInterface,
967 BasePinImpl_AddRef,
968 BaseInputPinImpl_Release,
969 BaseInputPinImpl_Connect,
970 BaseInputPinImpl_ReceiveConnection,
971 BasePinImpl_Disconnect,
972 BasePinImpl_ConnectedTo,
973 BasePinImpl_ConnectionMediaType,
974 BasePinImpl_QueryPinInfo,
975 BasePinImpl_QueryDirection,
976 BasePinImpl_QueryId,
977 BaseInputPinImpl_QueryAccept,
978 BasePinImpl_EnumMediaTypes,
979 BasePinImpl_QueryInternalConnections,
980 VideoRenderer_InputPin_EndOfStream,
981 VideoRenderer_InputPin_BeginFlush,
982 VideoRenderer_InputPin_EndFlush,
983 BaseInputPinImpl_NewSegment
986 /*** IUnknown methods ***/
987 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
988 REFIID riid,
989 LPVOID*ppvObj) {
990 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
992 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
994 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
997 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
998 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1000 TRACE("(%p/%p)->()\n", This, iface);
1002 return VideoRenderer_AddRef((IBaseFilter*)This);
1005 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1006 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1008 TRACE("(%p/%p)->()\n", This, iface);
1010 return VideoRenderer_Release((IBaseFilter*)This);
1013 /*** IDispatch methods ***/
1014 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1015 UINT*pctinfo) {
1016 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1018 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1020 return S_OK;
1023 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1024 UINT iTInfo,
1025 LCID lcid,
1026 ITypeInfo**ppTInfo) {
1027 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1029 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1031 return S_OK;
1034 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1035 REFIID riid,
1036 LPOLESTR*rgszNames,
1037 UINT cNames,
1038 LCID lcid,
1039 DISPID*rgDispId) {
1040 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1042 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1044 return S_OK;
1047 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1048 DISPID dispIdMember,
1049 REFIID riid,
1050 LCID lcid,
1051 WORD wFlags,
1052 DISPPARAMS*pDispParams,
1053 VARIANT*pVarResult,
1054 EXCEPINFO*pExepInfo,
1055 UINT*puArgErr) {
1056 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1058 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);
1060 return S_OK;
1063 /*** IBasicVideo methods ***/
1064 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1065 REFTIME *pAvgTimePerFrame) {
1066 AM_MEDIA_TYPE *pmt;
1067 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1069 if (!This->pInputPin->pin.pConnectedTo)
1070 return VFW_E_NOT_CONNECTED;
1072 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
1074 pmt = &This->pInputPin->pin.mtCurrent;
1075 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
1076 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)pmt->pbFormat;
1077 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1078 } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
1079 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)pmt->pbFormat;
1080 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1081 } else {
1082 ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
1083 *pAvgTimePerFrame = 0;
1085 return S_OK;
1088 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1089 LONG *pBitRate) {
1090 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1092 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1094 return S_OK;
1097 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1098 LONG *pBitErrorRate) {
1099 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1101 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1103 return S_OK;
1106 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1107 LONG *pVideoWidth) {
1108 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1110 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1112 *pVideoWidth = This->VideoWidth;
1114 return S_OK;
1117 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1118 LONG *pVideoHeight) {
1119 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1121 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1123 *pVideoHeight = This->VideoHeight;
1125 return S_OK;
1128 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1129 LONG SourceLeft) {
1130 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1132 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
1134 This->SourceRect.left = SourceLeft;
1136 return S_OK;
1139 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1140 LONG *pSourceLeft) {
1141 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1143 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1145 *pSourceLeft = This->SourceRect.left;
1147 return S_OK;
1150 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1151 LONG SourceWidth) {
1152 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1154 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
1156 This->SourceRect.right = This->SourceRect.left + SourceWidth;
1158 return S_OK;
1161 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1162 LONG *pSourceWidth) {
1163 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1165 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1167 *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1169 return S_OK;
1172 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1173 LONG SourceTop) {
1174 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1176 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
1178 This->SourceRect.top = SourceTop;
1180 return S_OK;
1183 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1184 LONG *pSourceTop) {
1185 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1187 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1189 *pSourceTop = This->SourceRect.top;
1191 return S_OK;
1194 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1195 LONG SourceHeight) {
1196 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1198 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
1200 This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1202 return S_OK;
1205 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1206 LONG *pSourceHeight) {
1207 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1209 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1211 *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1213 return S_OK;
1216 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1217 LONG DestinationLeft) {
1218 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1220 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
1222 This->DestRect.left = DestinationLeft;
1224 return S_OK;
1227 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1228 LONG *pDestinationLeft) {
1229 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1231 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1233 *pDestinationLeft = This->DestRect.left;
1235 return S_OK;
1238 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1239 LONG DestinationWidth) {
1240 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1242 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
1244 This->DestRect.right = This->DestRect.left + DestinationWidth;
1246 return S_OK;
1249 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1250 LONG *pDestinationWidth) {
1251 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1253 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1255 *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1257 return S_OK;
1260 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1261 LONG DestinationTop) {
1262 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1264 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
1266 This->DestRect.top = DestinationTop;
1268 return S_OK;
1271 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1272 LONG *pDestinationTop) {
1273 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1275 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1277 *pDestinationTop = This->DestRect.top;
1279 return S_OK;
1282 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1283 LONG DestinationHeight) {
1284 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1286 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
1288 This->DestRect.right = This->DestRect.left + DestinationHeight;
1290 return S_OK;
1293 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1294 LONG *pDestinationHeight) {
1295 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1297 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1299 *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1301 return S_OK;
1304 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1305 LONG Left,
1306 LONG Top,
1307 LONG Width,
1308 LONG Height) {
1309 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1311 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1313 This->SourceRect.left = Left;
1314 This->SourceRect.top = Top;
1315 This->SourceRect.right = Left + Width;
1316 This->SourceRect.bottom = Top + Height;
1318 return S_OK;
1321 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1322 LONG *pLeft,
1323 LONG *pTop,
1324 LONG *pWidth,
1325 LONG *pHeight) {
1326 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1328 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1330 *pLeft = This->SourceRect.left;
1331 *pTop = This->SourceRect.top;
1332 *pWidth = This->SourceRect.right - This->SourceRect.left;
1333 *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1335 return S_OK;
1338 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1339 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1341 TRACE("(%p/%p)->()\n", This, iface);
1343 This->SourceRect.left = 0;
1344 This->SourceRect.top = 0;
1345 This->SourceRect.right = This->VideoWidth;
1346 This->SourceRect.bottom = This->VideoHeight;
1348 return S_OK;
1351 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1352 LONG Left,
1353 LONG Top,
1354 LONG Width,
1355 LONG Height) {
1356 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1358 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1360 This->DestRect.left = Left;
1361 This->DestRect.top = Top;
1362 This->DestRect.right = Left + Width;
1363 This->DestRect.bottom = Top + Height;
1365 return S_OK;
1368 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1369 LONG *pLeft,
1370 LONG *pTop,
1371 LONG *pWidth,
1372 LONG *pHeight) {
1373 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1375 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1377 *pLeft = This->DestRect.left;
1378 *pTop = This->DestRect.top;
1379 *pWidth = This->DestRect.right - This->DestRect.left;
1380 *pHeight = This->DestRect.bottom - This->DestRect.top;
1382 return S_OK;
1385 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1386 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1387 RECT rect;
1389 TRACE("(%p/%p)->()\n", This, iface);
1391 if (!GetClientRect(This->hWnd, &rect))
1392 return E_FAIL;
1394 This->SourceRect.left = 0;
1395 This->SourceRect.top = 0;
1396 This->SourceRect.right = rect.right;
1397 This->SourceRect.bottom = rect.bottom;
1399 return S_OK;
1402 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1403 LONG *pWidth,
1404 LONG *pHeight) {
1405 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1407 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1409 *pWidth = This->VideoWidth;
1410 *pHeight = This->VideoHeight;
1412 return S_OK;
1415 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1416 LONG StartIndex,
1417 LONG Entries,
1418 LONG *pRetrieved,
1419 LONG *pPalette) {
1420 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1422 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1424 if (pRetrieved)
1425 *pRetrieved = 0;
1426 return VFW_E_NO_PALETTE_AVAILABLE;
1429 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1430 LONG *pBufferSize,
1431 LONG *pDIBImage) {
1432 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1433 BITMAPINFOHEADER *bmiHeader;
1434 LONG needed_size;
1435 AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1436 char *ptr;
1438 FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1440 EnterCriticalSection(&This->filter.csFilter);
1442 if (!This->sample_held)
1444 LeaveCriticalSection(&This->filter.csFilter);
1445 return (This->filter.state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1448 if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1450 bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1452 else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1454 bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1456 else
1458 FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1459 LeaveCriticalSection(&This->filter.csFilter);
1460 return VFW_E_RUNTIME_ERROR;
1463 needed_size = bmiHeader->biSize;
1464 needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1466 if (!pDIBImage)
1468 *pBufferSize = needed_size;
1469 LeaveCriticalSection(&This->filter.csFilter);
1470 return S_OK;
1473 if (needed_size < *pBufferSize)
1475 ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
1476 LeaveCriticalSection(&This->filter.csFilter);
1477 return E_FAIL;
1479 *pBufferSize = needed_size;
1481 memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1482 IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1483 memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1485 LeaveCriticalSection(&This->filter.csFilter);
1487 return S_OK;
1490 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1491 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1493 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1495 return S_OK;
1498 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1499 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1501 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1503 return S_OK;
1507 static const IBasicVideoVtbl IBasicVideo_VTable =
1509 Basicvideo_QueryInterface,
1510 Basicvideo_AddRef,
1511 Basicvideo_Release,
1512 Basicvideo_GetTypeInfoCount,
1513 Basicvideo_GetTypeInfo,
1514 Basicvideo_GetIDsOfNames,
1515 Basicvideo_Invoke,
1516 Basicvideo_get_AvgTimePerFrame,
1517 Basicvideo_get_BitRate,
1518 Basicvideo_get_BitErrorRate,
1519 Basicvideo_get_VideoWidth,
1520 Basicvideo_get_VideoHeight,
1521 Basicvideo_put_SourceLeft,
1522 Basicvideo_get_SourceLeft,
1523 Basicvideo_put_SourceWidth,
1524 Basicvideo_get_SourceWidth,
1525 Basicvideo_put_SourceTop,
1526 Basicvideo_get_SourceTop,
1527 Basicvideo_put_SourceHeight,
1528 Basicvideo_get_SourceHeight,
1529 Basicvideo_put_DestinationLeft,
1530 Basicvideo_get_DestinationLeft,
1531 Basicvideo_put_DestinationWidth,
1532 Basicvideo_get_DestinationWidth,
1533 Basicvideo_put_DestinationTop,
1534 Basicvideo_get_DestinationTop,
1535 Basicvideo_put_DestinationHeight,
1536 Basicvideo_get_DestinationHeight,
1537 Basicvideo_SetSourcePosition,
1538 Basicvideo_GetSourcePosition,
1539 Basicvideo_SetDefaultSourcePosition,
1540 Basicvideo_SetDestinationPosition,
1541 Basicvideo_GetDestinationPosition,
1542 Basicvideo_SetDefaultDestinationPosition,
1543 Basicvideo_GetVideoSize,
1544 Basicvideo_GetVideoPaletteEntries,
1545 Basicvideo_GetCurrentImage,
1546 Basicvideo_IsUsingDefaultSource,
1547 Basicvideo_IsUsingDefaultDestination
1551 /*** IUnknown methods ***/
1552 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1553 REFIID riid,
1554 LPVOID*ppvObj) {
1555 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1557 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1559 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1562 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1563 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1565 TRACE("(%p/%p)->()\n", This, iface);
1567 return VideoRenderer_AddRef((IBaseFilter*)This);
1570 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1571 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1573 TRACE("(%p/%p)->()\n", This, iface);
1575 return VideoRenderer_Release((IBaseFilter*)This);
1578 /*** IDispatch methods ***/
1579 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1580 UINT*pctinfo) {
1581 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1583 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1585 return S_OK;
1588 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1589 UINT iTInfo,
1590 LCID lcid,
1591 ITypeInfo**ppTInfo) {
1592 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1594 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1596 return S_OK;
1599 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1600 REFIID riid,
1601 LPOLESTR*rgszNames,
1602 UINT cNames,
1603 LCID lcid,
1604 DISPID*rgDispId) {
1605 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1607 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1609 return S_OK;
1612 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1613 DISPID dispIdMember,
1614 REFIID riid,
1615 LCID lcid,
1616 WORD wFlags,
1617 DISPPARAMS*pDispParams,
1618 VARIANT*pVarResult,
1619 EXCEPINFO*pExepInfo,
1620 UINT*puArgErr) {
1621 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1623 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);
1625 return S_OK;
1628 /*** IVideoWindow methods ***/
1629 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1630 BSTR strCaption) {
1631 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1633 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1635 if (!SetWindowTextW(This->hWnd, strCaption))
1636 return E_FAIL;
1638 return S_OK;
1641 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1642 BSTR *strCaption) {
1643 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1645 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1647 GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1649 return S_OK;
1652 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1653 LONG WindowStyle) {
1654 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1655 LONG old;
1657 old = GetWindowLongA(This->hWnd, GWL_STYLE);
1659 TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
1661 if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1662 return E_INVALIDARG;
1664 SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1665 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1666 This->WindowStyle = WindowStyle;
1668 return S_OK;
1671 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1672 LONG *WindowStyle) {
1673 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1675 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1677 *WindowStyle = This->WindowStyle;
1679 return S_OK;
1682 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1683 LONG WindowStyleEx) {
1684 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1686 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
1688 if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1689 return E_FAIL;
1691 return S_OK;
1694 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1695 LONG *WindowStyleEx) {
1696 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1698 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1700 *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1702 return S_OK;
1705 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1706 LONG AutoShow) {
1707 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1709 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
1711 This->AutoShow = AutoShow;
1713 return S_OK;
1716 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1717 LONG *AutoShow) {
1718 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1720 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1722 *AutoShow = This->AutoShow;
1724 return S_OK;
1727 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1728 LONG WindowState) {
1729 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1731 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
1732 ShowWindow(This->hWnd, WindowState);
1733 return S_OK;
1736 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1737 LONG *WindowState) {
1738 WINDOWPLACEMENT place;
1739 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1741 place.length = sizeof(place);
1742 GetWindowPlacement(This->hWnd, &place);
1743 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
1744 *WindowState = place.showCmd;
1746 return S_OK;
1749 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1750 LONG BackgroundPalette) {
1751 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1753 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
1755 return S_OK;
1758 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1759 LONG *pBackgroundPalette) {
1760 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1762 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1764 return S_OK;
1767 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1768 LONG Visible) {
1769 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1771 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
1773 ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1775 return S_OK;
1778 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1779 LONG *pVisible) {
1780 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1782 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1784 *pVisible = IsWindowVisible(This->hWnd);
1786 return S_OK;
1789 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1790 LONG Left) {
1791 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1793 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
1795 if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1796 return E_FAIL;
1798 This->WindowPos.left = Left;
1800 return S_OK;
1803 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1804 LONG *pLeft) {
1805 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1807 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1809 *pLeft = This->WindowPos.left;
1811 return S_OK;
1814 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1815 LONG Width) {
1816 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1818 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
1820 if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1821 return E_FAIL;
1823 This->WindowPos.right = This->WindowPos.left + Width;
1825 return S_OK;
1828 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1829 LONG *pWidth) {
1830 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1832 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1834 *pWidth = This->WindowPos.right - This->WindowPos.left;
1836 return S_OK;
1839 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1840 LONG Top) {
1841 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1843 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
1845 if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1846 return E_FAIL;
1848 This->WindowPos.top = Top;
1850 return S_OK;
1853 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1854 LONG *pTop) {
1855 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1857 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1859 *pTop = This->WindowPos.top;
1861 return S_OK;
1864 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1865 LONG Height) {
1866 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1868 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
1870 if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1871 return E_FAIL;
1873 This->WindowPos.bottom = This->WindowPos.top + Height;
1875 return S_OK;
1878 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1879 LONG *pHeight) {
1880 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1882 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1884 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1886 return S_OK;
1889 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1890 OAHWND Owner) {
1891 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1893 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1895 SetParent(This->hWnd, (HWND)Owner);
1896 if (This->WindowStyle & WS_CHILD)
1898 LONG old = GetWindowLongA(This->hWnd, GWL_STYLE);
1899 if (old != This->WindowStyle)
1901 SetWindowLongA(This->hWnd, GWL_STYLE, This->WindowStyle);
1902 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1906 return S_OK;
1909 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
1910 OAHWND *Owner) {
1911 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1913 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
1915 *(HWND*)Owner = GetParent(This->hWnd);
1917 return S_OK;
1920 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
1921 OAHWND Drain) {
1922 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1924 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
1926 This->hWndMsgDrain = (HWND)Drain;
1928 return S_OK;
1931 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
1932 OAHWND *Drain) {
1933 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1935 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
1937 *Drain = (OAHWND)This->hWndMsgDrain;
1939 return S_OK;
1942 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
1943 LONG *Color) {
1944 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1946 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
1948 return S_OK;
1951 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
1952 LONG Color) {
1953 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1955 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
1957 return S_OK;
1960 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
1961 LONG *FullScreenMode) {
1962 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1964 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
1966 return S_OK;
1969 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
1970 LONG FullScreenMode) {
1971 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1973 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
1975 return S_OK;
1978 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
1979 LONG Focus) {
1980 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1981 BOOL ret;
1982 IPin* pPin;
1983 HRESULT hr;
1985 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
1987 if ((Focus != FALSE) && (Focus != TRUE))
1988 return E_INVALIDARG;
1990 hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
1991 if ((hr != S_OK) || !pPin)
1992 return VFW_E_NOT_CONNECTED;
1994 if (Focus)
1995 ret = SetForegroundWindow(This->hWnd);
1996 else
1997 ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
1999 if (!ret)
2000 return E_FAIL;
2002 return S_OK;
2005 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2006 OAHWND hwnd,
2007 LONG uMsg,
2008 LONG_PTR wParam,
2009 LONG_PTR lParam) {
2010 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2012 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
2014 if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
2015 return E_FAIL;
2017 return S_OK;
2020 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2021 LONG Left,
2022 LONG Top,
2023 LONG Width,
2024 LONG Height) {
2025 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2027 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
2029 if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2030 return E_FAIL;
2032 This->WindowPos.left = Left;
2033 This->WindowPos.top = Top;
2034 This->WindowPos.right = Left + Width;
2035 This->WindowPos.bottom = Top + Height;
2037 return S_OK;
2040 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2041 LONG *pLeft,
2042 LONG *pTop,
2043 LONG *pWidth,
2044 LONG *pHeight) {
2045 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2047 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2049 *pLeft = This->WindowPos.left;
2050 *pTop = This->WindowPos.top;
2051 *pWidth = This->WindowPos.right - This->WindowPos.left;
2052 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2054 return S_OK;
2057 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2058 LONG *pWidth,
2059 LONG *pHeight) {
2060 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2062 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2064 *pWidth = This->VideoWidth;
2065 *pHeight = This->VideoHeight;
2067 return S_OK;
2070 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2071 LONG *pWidth,
2072 LONG *pHeight) {
2073 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2075 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2077 *pWidth = This->VideoWidth;
2078 *pHeight = This->VideoHeight;
2080 return S_OK;
2083 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2084 LONG *pLeft,
2085 LONG *pTop,
2086 LONG *pWidth,
2087 LONG *pHeight) {
2088 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2090 FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2092 return S_OK;
2095 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2096 LONG HideCursor) {
2097 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2099 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
2101 return S_OK;
2104 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2105 LONG *CursorHidden) {
2106 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2108 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2110 return S_OK;
2113 static const IVideoWindowVtbl IVideoWindow_VTable =
2115 Videowindow_QueryInterface,
2116 Videowindow_AddRef,
2117 Videowindow_Release,
2118 Videowindow_GetTypeInfoCount,
2119 Videowindow_GetTypeInfo,
2120 Videowindow_GetIDsOfNames,
2121 Videowindow_Invoke,
2122 Videowindow_put_Caption,
2123 Videowindow_get_Caption,
2124 Videowindow_put_WindowStyle,
2125 Videowindow_get_WindowStyle,
2126 Videowindow_put_WindowStyleEx,
2127 Videowindow_get_WindowStyleEx,
2128 Videowindow_put_AutoShow,
2129 Videowindow_get_AutoShow,
2130 Videowindow_put_WindowState,
2131 Videowindow_get_WindowState,
2132 Videowindow_put_BackgroundPalette,
2133 Videowindow_get_BackgroundPalette,
2134 Videowindow_put_Visible,
2135 Videowindow_get_Visible,
2136 Videowindow_put_Left,
2137 Videowindow_get_Left,
2138 Videowindow_put_Width,
2139 Videowindow_get_Width,
2140 Videowindow_put_Top,
2141 Videowindow_get_Top,
2142 Videowindow_put_Height,
2143 Videowindow_get_Height,
2144 Videowindow_put_Owner,
2145 Videowindow_get_Owner,
2146 Videowindow_put_MessageDrain,
2147 Videowindow_get_MessageDrain,
2148 Videowindow_get_BorderColor,
2149 Videowindow_put_BorderColor,
2150 Videowindow_get_FullScreenMode,
2151 Videowindow_put_FullScreenMode,
2152 Videowindow_SetWindowForeground,
2153 Videowindow_NotifyOwnerMessage,
2154 Videowindow_SetWindowPosition,
2155 Videowindow_GetWindowPosition,
2156 Videowindow_GetMinIdealImageSize,
2157 Videowindow_GetMaxIdealImageSize,
2158 Videowindow_GetRestorePosition,
2159 Videowindow_HideCursor,
2160 Videowindow_IsCursorHidden
2163 static VideoRendererImpl *from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface) {
2164 return (VideoRendererImpl*)((char*)iface - offsetof(VideoRendererImpl, IAMFilterMiscFlags_vtbl));
2167 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, const REFIID riid, void **ppv) {
2168 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2169 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
2172 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
2173 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2174 return IUnknown_AddRef((IUnknown*)This);
2177 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
2178 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2179 return IUnknown_Release((IUnknown*)This);
2182 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
2183 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
2186 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
2187 AMFilterMiscFlags_QueryInterface,
2188 AMFilterMiscFlags_AddRef,
2189 AMFilterMiscFlags_Release,
2190 AMFilterMiscFlags_GetMiscFlags