include: Add declarations for metadata handler info interfaces.
[wine/multimedia.git] / dlls / quartz / videorenderer.c
blobcf6fc2a57f724afaffcd386e5e96f7a92ceecaaf
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 HWND hWndOwner;
86 BOOL AutoShow;
87 RECT SourceRect;
88 RECT DestRect;
89 RECT WindowPos;
90 LONG VideoWidth;
91 LONG VideoHeight;
92 IUnknown * pUnkOuter;
93 BOOL bUnkOuterValid;
94 BOOL bAggregatable;
95 LONG WindowStyle;
97 /* During pause we can hold a single sample, for use in GetCurrentImage */
98 IMediaSample *sample_held;
99 } VideoRendererImpl;
101 static LRESULT CALLBACK VideoWndProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
103 VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongPtrW(hwnd, 0);
104 LPRECT lprect = (LPRECT)lParam;
106 if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
108 switch(uMsg)
110 case WM_KEYDOWN:
111 case WM_KEYUP:
112 case WM_LBUTTONDBLCLK:
113 case WM_LBUTTONDOWN:
114 case WM_LBUTTONUP:
115 case WM_MBUTTONDBLCLK:
116 case WM_MBUTTONDOWN:
117 case WM_MBUTTONUP:
118 case WM_MOUSEACTIVATE:
119 case WM_MOUSEMOVE:
120 case WM_NCLBUTTONDBLCLK:
121 case WM_NCLBUTTONDOWN:
122 case WM_NCLBUTTONUP:
123 case WM_NCMBUTTONDBLCLK:
124 case WM_NCMBUTTONDOWN:
125 case WM_NCMBUTTONUP:
126 case WM_NCMOUSEMOVE:
127 case WM_NCRBUTTONDBLCLK:
128 case WM_NCRBUTTONDOWN:
129 case WM_NCRBUTTONUP:
130 case WM_RBUTTONDBLCLK:
131 case WM_RBUTTONDOWN:
132 case WM_RBUTTONUP:
133 PostMessageW(pVideoRenderer->hWndMsgDrain, uMsg, wParam, lParam);
134 break;
135 default:
136 break;
140 switch(uMsg)
142 case WM_SIZING:
143 /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
144 SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
145 GetClientRect(hwnd, &pVideoRenderer->DestRect);
146 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
147 pVideoRenderer->DestRect.left,
148 pVideoRenderer->DestRect.top,
149 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
150 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
151 return TRUE;
152 case WM_SIZE:
153 TRACE("WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
154 GetClientRect(hwnd, &pVideoRenderer->DestRect);
155 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
156 pVideoRenderer->DestRect.left,
157 pVideoRenderer->DestRect.top,
158 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
159 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
160 return TRUE;
161 default:
162 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
164 return 0;
167 static const WCHAR classnameW[] = { 'W','i','n','e',' ','A','c','t','i','v','e','M','o','v','i','e',' ','C','l','a','s','s',0 };
168 static const WCHAR windownameW[] = { 'A','c','t','i','v','e','M','o','v','i','e',' ','W','i','n','d','o','w',0 };
170 static BOOL video_register_windowclass(void) {
171 WNDCLASSW winclass;
172 if (wnd_class_registered)
173 return 1;
175 winclass.style = 0;
176 winclass.lpfnWndProc = VideoWndProcW;
177 winclass.cbClsExtra = 0;
178 winclass.cbWndExtra = sizeof(VideoRendererImpl*);
179 winclass.hInstance = NULL;
180 winclass.hIcon = NULL;
181 winclass.hCursor = NULL;
182 winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
183 winclass.lpszMenuName = NULL;
184 winclass.lpszClassName = classnameW;
185 if (!RegisterClassW(&winclass))
187 ERR("Unable to register window class: %u\n", GetLastError());
188 return FALSE;
190 wnd_class_registered = 1;
191 return 1;
194 void video_unregister_windowclass(void) {
195 if (!wnd_class_registered)
196 return;
197 UnregisterClassW(classnameW, NULL);
200 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
202 TRACE("(%p)->()\n", This);
203 if (!video_register_windowclass())
204 return FALSE;
205 This->hWnd = CreateWindowExW(0, classnameW, windownameW, WS_SIZEBOX,
206 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
207 NULL, NULL, NULL);
209 if (!This->hWnd)
211 ERR("Unable to create window\n");
212 return FALSE;
215 SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
217 return TRUE;
220 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
222 VideoRendererImpl* This = lpParameter;
223 MSG msg;
224 BOOL fGotMessage;
226 TRACE("Starting message loop\n");
228 if (!CreateRenderingWindow(This))
230 This->ThreadResult = FALSE;
231 SetEvent(This->hEvent);
232 return 0;
235 This->ThreadResult = TRUE;
236 SetEvent(This->hEvent);
238 while ((fGotMessage = GetMessageW(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
240 TranslateMessage(&msg);
241 DispatchMessageW(&msg);
244 TRACE("End of message loop\n");
246 return msg.wParam;
249 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
251 This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
252 if (!This->hEvent)
253 return FALSE;
255 This->hThread = CreateThread(NULL, 0, MessageLoop, This, 0, &This->ThreadID);
256 if (!This->hThread)
258 CloseHandle(This->hEvent);
259 return FALSE;
262 WaitForSingleObject(This->hEvent, INFINITE);
264 if (!This->ThreadResult)
266 CloseHandle(This->hEvent);
267 CloseHandle(This->hThread);
268 return FALSE;
271 return TRUE;
274 static void VideoRenderer_AutoShowWindow(VideoRendererImpl *This) {
275 if (!This->init && (!This->WindowPos.right || !This->WindowPos.top))
277 DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
278 DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
280 if (!This->WindowPos.right)
282 This->WindowPos.left = This->SourceRect.left;
283 This->WindowPos.right = This->SourceRect.right;
285 if (!This->WindowPos.bottom)
287 This->WindowPos.top = This->SourceRect.top;
288 This->WindowPos.bottom = This->SourceRect.bottom;
291 AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);
293 TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
294 SetWindowPos(This->hWnd, NULL,
295 This->WindowPos.left,
296 This->WindowPos.top,
297 This->WindowPos.right - This->WindowPos.left,
298 This->WindowPos.bottom - This->WindowPos.top,
299 SWP_NOZORDER|SWP_NOMOVE|SWP_DEFERERASE);
301 GetClientRect(This->hWnd, &This->DestRect);
303 else if (!This->init)
304 This->DestRect = This->WindowPos;
305 This->init = TRUE;
306 if (This->AutoShow)
307 ShowWindow(This->hWnd, SW_SHOW);
310 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
312 AM_MEDIA_TYPE amt;
313 HRESULT hr = S_OK;
314 DDSURFACEDESC sdesc;
315 HDC hDC;
316 BITMAPINFOHEADER *bmiHeader;
318 TRACE("(%p)->(%p, %d)\n", This, data, size);
320 sdesc.dwSize = sizeof(sdesc);
321 hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
322 if (FAILED(hr)) {
323 ERR("Unable to retrieve media type\n");
324 return hr;
327 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
329 bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
331 else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
333 bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
335 else
337 FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
338 return VFW_E_RUNTIME_ERROR;
341 TRACE("biSize = %d\n", bmiHeader->biSize);
342 TRACE("biWidth = %d\n", bmiHeader->biWidth);
343 TRACE("biHeight = %d\n", bmiHeader->biHeight);
344 TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
345 TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
346 TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
347 TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
349 hDC = GetDC(This->hWnd);
351 if (!hDC) {
352 ERR("Cannot get DC from window!\n");
353 return E_FAIL;
356 TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
357 TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
359 StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
360 This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
361 This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
362 data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
364 ReleaseDC(This->hWnd, hDC);
366 return S_OK;
369 static HRESULT WINAPI VideoRenderer_Receive(BaseInputPin* pin, IMediaSample * pSample)
371 VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
372 LPBYTE pbSrcStream = NULL;
373 LONG cbSrcStream = 0;
374 REFERENCE_TIME tStart, tStop;
375 HRESULT hr;
377 TRACE("(%p)->(%p)\n", pin, pSample);
379 EnterCriticalSection(&This->filter.csFilter);
381 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
383 LeaveCriticalSection(&This->filter.csFilter);
384 return S_FALSE;
387 if (This->filter.state == State_Stopped)
389 LeaveCriticalSection(&This->filter.csFilter);
390 return VFW_E_WRONG_STATE;
393 if (IMediaSample_GetMediaTime(pSample, &tStart, &tStop) == S_OK)
394 MediaSeekingPassThru_RegisterMediaTime(This->seekthru_unk, tStart);
396 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
397 if (IMediaSample_IsPreroll(pSample) == S_OK) {
398 LeaveCriticalSection(&This->filter.csFilter);
399 return S_OK;
402 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
403 if (FAILED(hr))
405 ERR("Cannot get pointer to sample data (%x)\n", hr);
406 LeaveCriticalSection(&This->filter.csFilter);
407 return hr;
410 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
412 TRACE("val %p %d\n", pbSrcStream, cbSrcStream);
414 #if 0 /* For debugging purpose */
416 int i;
417 for(i = 0; i < cbSrcStream; i++)
419 if ((i!=0) && !(i%16))
420 TRACE("\n");
421 TRACE("%02x ", pbSrcStream[i]);
423 TRACE("\n");
425 #endif
427 SetEvent(This->hEvent);
428 if (This->filter.state == State_Paused)
430 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
431 This->sample_held = pSample;
432 LeaveCriticalSection(&This->filter.csFilter);
433 WaitForSingleObject(This->blocked, INFINITE);
434 EnterCriticalSection(&This->filter.csFilter);
435 SetEvent(This->hEvent);
436 This->sample_held = NULL;
437 if (This->filter.state == State_Paused)
439 /* Flushing */
440 LeaveCriticalSection(&This->filter.csFilter);
441 return S_OK;
443 if (This->filter.state == State_Stopped)
445 LeaveCriticalSection(&This->filter.csFilter);
446 return VFW_E_WRONG_STATE;
448 } else {
449 hr = QualityControlRender_WaitFor(&This->qcimpl, pSample, This->blocked);
450 if (hr == S_OK) {
451 QualityControlRender_BeginRender(&This->qcimpl);
452 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
453 QualityControlRender_EndRender(&This->qcimpl);
455 QualityControlRender_DoQOS(&This->qcimpl);
457 LeaveCriticalSection(&This->filter.csFilter);
458 return S_OK;
461 static HRESULT WINAPI VideoRenderer_CheckMediaType(BasePin *iface, const AM_MEDIA_TYPE * pmt)
463 BaseInputPin* pin = (BaseInputPin*)iface;
464 VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
466 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
467 return S_FALSE;
469 if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
470 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
471 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
472 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
474 LONG height;
476 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
478 VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
479 This->SourceRect.left = 0;
480 This->SourceRect.top = 0;
481 This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
482 height = format->bmiHeader.biHeight;
483 if (height < 0)
484 This->SourceRect.bottom = This->VideoHeight = -height;
485 else
486 This->SourceRect.bottom = This->VideoHeight = height;
488 else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
490 VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
492 This->SourceRect.left = 0;
493 This->SourceRect.top = 0;
494 This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
495 height = format2->bmiHeader.biHeight;
496 if (height < 0)
497 This->SourceRect.bottom = This->VideoHeight = -height;
498 else
499 This->SourceRect.bottom = This->VideoHeight = height;
501 else
503 WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
504 return S_FALSE;
506 return S_OK;
508 return S_FALSE;
511 static IPin* WINAPI VideoRenderer_GetPin(BaseFilter *iface, int pos)
513 VideoRendererImpl *This = (VideoRendererImpl *)iface;
515 if (pos >= 1 || pos < 0)
516 return NULL;
518 IPin_AddRef((IPin *)This->pInputPin);
519 return (IPin *)This->pInputPin;
522 static LONG WINAPI VideoRenderer_GetPinCount(BaseFilter *iface)
524 return 1;
527 static const BaseFilterFuncTable BaseFuncTable = {
528 VideoRenderer_GetPin,
529 VideoRenderer_GetPinCount
532 static const BasePinFuncTable input_BaseFuncTable = {
533 VideoRenderer_CheckMediaType,
534 NULL,
535 BasePinImpl_GetMediaTypeVersion,
536 BasePinImpl_GetMediaType
539 static const BaseInputPinFuncTable input_BaseInputFuncTable = {
540 VideoRenderer_Receive
543 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
545 HRESULT hr;
546 PIN_INFO piInput;
547 VideoRendererImpl * pVideoRenderer;
548 ISeekingPassThru *passthru;
550 TRACE("(%p, %p)\n", pUnkOuter, ppv);
552 *ppv = NULL;
554 pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
555 pVideoRenderer->pUnkOuter = pUnkOuter;
556 pVideoRenderer->bUnkOuterValid = FALSE;
557 pVideoRenderer->bAggregatable = FALSE;
558 pVideoRenderer->IInner_vtbl = &IInner_VTable;
559 pVideoRenderer->IAMFilterMiscFlags_vtbl = &IAMFilterMiscFlags_Vtbl;
561 BaseFilter_Init(&pVideoRenderer->filter, &VideoRenderer_Vtbl, &CLSID_VideoRenderer, (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter"), &BaseFuncTable);
563 pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
564 pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
566 pVideoRenderer->init = 0;
567 pVideoRenderer->AutoShow = 1;
568 ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
569 ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
570 ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
571 pVideoRenderer->hWndMsgDrain = pVideoRenderer->hWndOwner = NULL;
572 pVideoRenderer->WindowStyle = WS_OVERLAPPED;
574 /* construct input pin */
575 piInput.dir = PINDIR_INPUT;
576 piInput.pFilter = (IBaseFilter *)pVideoRenderer;
577 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
579 hr = BaseInputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, &input_BaseFuncTable, &input_BaseInputFuncTable, &pVideoRenderer->filter.csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
581 if (SUCCEEDED(hr))
583 hr = CoCreateInstance(&CLSID_SeekingPassThru, pUnkOuter ? pUnkOuter : (IUnknown*)&pVideoRenderer->IInner_vtbl, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&pVideoRenderer->seekthru_unk);
584 if (FAILED(hr)) {
585 IPin_Release((IPin*)pVideoRenderer->pInputPin);
586 goto fail;
588 IUnknown_QueryInterface(pVideoRenderer->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
589 ISeekingPassThru_Init(passthru, TRUE, (IPin*)pVideoRenderer->pInputPin);
590 ISeekingPassThru_Release(passthru);
591 pVideoRenderer->sample_held = NULL;
592 *ppv = pVideoRenderer;
594 if (FAILED(hr))
595 goto fail;
597 QualityControlImpl_init(&pVideoRenderer->qcimpl, (IPin*)pVideoRenderer->pInputPin, (IBaseFilter*)pVideoRenderer);
598 pVideoRenderer->qcimpl.lpVtbl = &VideoRenderer_QualityControl_Vtbl;
600 if (!CreateRenderingSubsystem(pVideoRenderer))
601 return E_FAIL;
603 pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
604 if (!pVideoRenderer->blocked)
606 hr = HRESULT_FROM_WIN32(GetLastError());
607 IUnknown_Release((IUnknown *)pVideoRenderer);
610 return hr;
611 fail:
612 BaseFilterImpl_Release((IBaseFilter*)pVideoRenderer);
613 CoTaskMemFree(pVideoRenderer);
614 return hr;
617 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
619 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
620 return VideoRenderer_create(pUnkOuter, ppv);
623 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
625 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
626 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
628 if (This->bAggregatable)
629 This->bUnkOuterValid = TRUE;
631 *ppv = NULL;
633 if (IsEqualIID(riid, &IID_IUnknown))
634 *ppv = &This->IInner_vtbl;
635 else if (IsEqualIID(riid, &IID_IPersist))
636 *ppv = This;
637 else if (IsEqualIID(riid, &IID_IMediaFilter))
638 *ppv = This;
639 else if (IsEqualIID(riid, &IID_IBaseFilter))
640 *ppv = This;
641 else if (IsEqualIID(riid, &IID_IBasicVideo))
642 *ppv = &This->IBasicVideo_vtbl;
643 else if (IsEqualIID(riid, &IID_IVideoWindow))
644 *ppv = &This->IVideoWindow_vtbl;
645 else if (IsEqualIID(riid, &IID_IMediaSeeking))
646 return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
647 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
648 *ppv = &This->IAMFilterMiscFlags_vtbl;
649 else if (IsEqualIID(riid, &IID_IQualityControl))
650 *ppv = &This->qcimpl;
652 if (*ppv)
654 IUnknown_AddRef((IUnknown *)(*ppv));
655 return S_OK;
658 if (!IsEqualIID(riid, &IID_IPin))
659 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
661 return E_NOINTERFACE;
664 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
666 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
667 ULONG refCount = InterlockedIncrement(&This->filter.refCount);
669 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
671 return refCount;
674 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
676 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
677 ULONG refCount = InterlockedDecrement(&This->filter.refCount);
679 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
681 if (!refCount)
683 IPin *pConnectedTo;
685 if (This->hWnd)
686 SendMessageW(This->hWnd, WM_CLOSE, 0, 0);
687 PostThreadMessageW(This->ThreadID, WM_QUIT, 0, 0);
688 WaitForSingleObject(This->hThread, INFINITE);
689 CloseHandle(This->hThread);
690 CloseHandle(This->hEvent);
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->filter.lpVtbl = NULL;
702 IUnknown_Release(This->seekthru_unk);
703 This->filter.csFilter.DebugInfo->Spare[0] = 0;
704 DeleteCriticalSection(&This->filter.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 /** IMediaFilter methods **/
772 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
774 VideoRendererImpl *This = (VideoRendererImpl *)iface;
776 TRACE("(%p/%p)->()\n", This, iface);
778 EnterCriticalSection(&This->filter.csFilter);
780 This->filter.state = State_Stopped;
781 SetEvent(This->hEvent);
782 SetEvent(This->blocked);
783 MediaSeekingPassThru_ResetMediaTime(This->seekthru_unk);
784 if (This->AutoShow)
785 /* Black it out */
786 RedrawWindow(This->hWnd, NULL, NULL, RDW_INVALIDATE|RDW_ERASE);
788 LeaveCriticalSection(&This->filter.csFilter);
790 return S_OK;
793 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
795 VideoRendererImpl *This = (VideoRendererImpl *)iface;
797 TRACE("(%p/%p)->()\n", This, iface);
799 EnterCriticalSection(&This->filter.csFilter);
800 if (This->filter.state != State_Paused)
802 if (This->filter.state == State_Stopped)
804 This->pInputPin->end_of_stream = 0;
805 ResetEvent(This->hEvent);
806 VideoRenderer_AutoShowWindow(This);
809 This->filter.state = State_Paused;
810 ResetEvent(This->blocked);
812 LeaveCriticalSection(&This->filter.csFilter);
814 return S_OK;
817 static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter *iface, IReferenceClock *clock) {
818 VideoRendererImpl *This = (VideoRendererImpl *)iface;
819 HRESULT hr;
821 EnterCriticalSection(&This->filter.csFilter);
822 QualityControlRender_SetClock(&This->qcimpl, clock);
823 hr = BaseFilterImpl_SetSyncSource(iface, clock);
824 LeaveCriticalSection(&This->filter.csFilter);
825 return hr;
828 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
830 HRESULT hr = S_OK;
831 VideoRendererImpl *This = (VideoRendererImpl *)iface;
833 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
835 EnterCriticalSection(&This->filter.csFilter);
836 This->filter.rtStreamStart = tStart;
837 if (This->filter.state == State_Running)
838 goto out;
839 QualityControlRender_Start(&This->qcimpl, tStart);
840 if (This->pInputPin->pin.pConnectedTo && (This->filter.state == State_Stopped || !This->pInputPin->end_of_stream))
842 if (This->filter.state == State_Stopped)
844 ResetEvent(This->hEvent);
845 VideoRenderer_AutoShowWindow(This);
846 This->pInputPin->end_of_stream = 0;
848 SetEvent(This->blocked);
849 } else if (This->filter.filterInfo.pGraph) {
850 IMediaEventSink *pEventSink;
851 hr = IFilterGraph_QueryInterface(This->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
852 if (SUCCEEDED(hr))
854 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)This);
855 IMediaEventSink_Release(pEventSink);
857 hr = S_OK;
859 if (SUCCEEDED(hr))
860 This->filter.state = State_Running;
861 out:
862 LeaveCriticalSection(&This->filter.csFilter);
864 return hr;
867 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
869 VideoRendererImpl *This = (VideoRendererImpl *)iface;
870 HRESULT hr;
872 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
874 if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
875 hr = VFW_S_STATE_INTERMEDIATE;
876 else
877 hr = S_OK;
879 BaseFilterImpl_GetState(iface, dwMilliSecsTimeout, pState);
881 return hr;
884 /** IBaseFilter implementation **/
886 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
888 VideoRendererImpl *This = (VideoRendererImpl *)iface;
890 FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
892 /* FIXME: critical section */
894 return E_NOTIMPL;
897 static const IBaseFilterVtbl VideoRenderer_Vtbl =
899 VideoRenderer_QueryInterface,
900 VideoRenderer_AddRef,
901 VideoRenderer_Release,
902 BaseFilterImpl_GetClassID,
903 VideoRenderer_Stop,
904 VideoRenderer_Pause,
905 VideoRenderer_Run,
906 VideoRenderer_GetState,
907 VideoRenderer_SetSyncSource,
908 BaseFilterImpl_GetSyncSource,
909 BaseFilterImpl_EnumPins,
910 VideoRenderer_FindPin,
911 BaseFilterImpl_QueryFilterInfo,
912 BaseFilterImpl_JoinFilterGraph,
913 BaseFilterImpl_QueryVendorInfo
916 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
918 BaseInputPin* This = (BaseInputPin*)iface;
919 VideoRendererImpl *pFilter;
920 IMediaEventSink* pEventSink;
921 HRESULT hr = S_OK;
923 TRACE("(%p/%p)->()\n", This, iface);
925 EnterCriticalSection(This->pin.pCritSec);
926 pFilter = (VideoRendererImpl*)This->pin.pinInfo.pFilter;
927 if (This->flushing || This->end_of_stream)
928 goto out;
929 hr = IFilterGraph_QueryInterface(pFilter->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
930 if (SUCCEEDED(hr))
932 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)pFilter);
933 IMediaEventSink_Release(pEventSink);
935 MediaSeekingPassThru_EOS(pFilter->seekthru_unk);
936 This->end_of_stream = 1;
937 out:
938 LeaveCriticalSection(This->pin.pCritSec);
940 return hr;
943 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
945 BaseInputPin* This = (BaseInputPin*)iface;
946 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
948 TRACE("(%p/%p)->()\n", This, iface);
950 SetEvent(pVideoRenderer->blocked);
951 return BaseInputPinImpl_BeginFlush(iface);
954 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
956 BaseInputPin* This = (BaseInputPin*)iface;
957 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
958 HRESULT hr;
960 TRACE("(%p/%p)->()\n", This, iface);
962 EnterCriticalSection(This->pin.pCritSec);
964 if (pVideoRenderer->sample_held) {
965 SetEvent(pVideoRenderer->blocked);
966 ResetEvent(pVideoRenderer->hEvent);
967 LeaveCriticalSection(This->pin.pCritSec);
968 WaitForSingleObject(pVideoRenderer->hEvent, INFINITE);
969 EnterCriticalSection(This->pin.pCritSec);
970 ResetEvent(pVideoRenderer->blocked);
972 if (pVideoRenderer->filter.state == State_Paused) {
973 ResetEvent(pVideoRenderer->blocked);
974 ResetEvent(pVideoRenderer->hEvent);
977 QualityControlRender_Start(&pVideoRenderer->qcimpl, pVideoRenderer->filter.rtStreamStart);
978 hr = BaseInputPinImpl_EndFlush(iface);
979 LeaveCriticalSection(This->pin.pCritSec);
980 MediaSeekingPassThru_ResetMediaTime(pVideoRenderer->seekthru_unk);
982 return hr;
985 static const IPinVtbl VideoRenderer_InputPin_Vtbl =
987 BaseInputPinImpl_QueryInterface,
988 BasePinImpl_AddRef,
989 BaseInputPinImpl_Release,
990 BaseInputPinImpl_Connect,
991 BaseInputPinImpl_ReceiveConnection,
992 BasePinImpl_Disconnect,
993 BasePinImpl_ConnectedTo,
994 BasePinImpl_ConnectionMediaType,
995 BasePinImpl_QueryPinInfo,
996 BasePinImpl_QueryDirection,
997 BasePinImpl_QueryId,
998 BaseInputPinImpl_QueryAccept,
999 BasePinImpl_EnumMediaTypes,
1000 BasePinImpl_QueryInternalConnections,
1001 VideoRenderer_InputPin_EndOfStream,
1002 VideoRenderer_InputPin_BeginFlush,
1003 VideoRenderer_InputPin_EndFlush,
1004 BaseInputPinImpl_NewSegment
1007 /*** IUnknown methods ***/
1008 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
1009 REFIID riid,
1010 LPVOID*ppvObj) {
1011 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1013 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1015 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1018 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1019 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1021 TRACE("(%p/%p)->()\n", This, iface);
1023 return VideoRenderer_AddRef((IBaseFilter*)This);
1026 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1027 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1029 TRACE("(%p/%p)->()\n", This, iface);
1031 return VideoRenderer_Release((IBaseFilter*)This);
1034 /*** IDispatch methods ***/
1035 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1036 UINT*pctinfo) {
1037 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1039 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1041 return S_OK;
1044 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1045 UINT iTInfo,
1046 LCID lcid,
1047 ITypeInfo**ppTInfo) {
1048 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1050 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1052 return S_OK;
1055 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1056 REFIID riid,
1057 LPOLESTR*rgszNames,
1058 UINT cNames,
1059 LCID lcid,
1060 DISPID*rgDispId) {
1061 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1063 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1065 return S_OK;
1068 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1069 DISPID dispIdMember,
1070 REFIID riid,
1071 LCID lcid,
1072 WORD wFlags,
1073 DISPPARAMS*pDispParams,
1074 VARIANT*pVarResult,
1075 EXCEPINFO*pExepInfo,
1076 UINT*puArgErr) {
1077 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1079 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);
1081 return S_OK;
1084 /*** IBasicVideo methods ***/
1085 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1086 REFTIME *pAvgTimePerFrame) {
1087 AM_MEDIA_TYPE *pmt;
1088 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1090 if (!This->pInputPin->pin.pConnectedTo)
1091 return VFW_E_NOT_CONNECTED;
1093 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
1095 pmt = &This->pInputPin->pin.mtCurrent;
1096 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
1097 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)pmt->pbFormat;
1098 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1099 } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
1100 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)pmt->pbFormat;
1101 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1102 } else {
1103 ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
1104 *pAvgTimePerFrame = 0;
1106 return S_OK;
1109 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1110 LONG *pBitRate) {
1111 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1113 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1115 return S_OK;
1118 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1119 LONG *pBitErrorRate) {
1120 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1122 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1124 return S_OK;
1127 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1128 LONG *pVideoWidth) {
1129 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1131 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1133 *pVideoWidth = This->VideoWidth;
1135 return S_OK;
1138 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1139 LONG *pVideoHeight) {
1140 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1142 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1144 *pVideoHeight = This->VideoHeight;
1146 return S_OK;
1149 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1150 LONG SourceLeft) {
1151 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1153 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
1155 This->SourceRect.left = SourceLeft;
1157 return S_OK;
1160 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1161 LONG *pSourceLeft) {
1162 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1164 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1166 *pSourceLeft = This->SourceRect.left;
1168 return S_OK;
1171 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1172 LONG SourceWidth) {
1173 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1175 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
1177 This->SourceRect.right = This->SourceRect.left + SourceWidth;
1179 return S_OK;
1182 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1183 LONG *pSourceWidth) {
1184 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1186 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1188 *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1190 return S_OK;
1193 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1194 LONG SourceTop) {
1195 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1197 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
1199 This->SourceRect.top = SourceTop;
1201 return S_OK;
1204 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1205 LONG *pSourceTop) {
1206 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1208 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1210 *pSourceTop = This->SourceRect.top;
1212 return S_OK;
1215 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1216 LONG SourceHeight) {
1217 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1219 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
1221 This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1223 return S_OK;
1226 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1227 LONG *pSourceHeight) {
1228 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1230 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1232 *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1234 return S_OK;
1237 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1238 LONG DestinationLeft) {
1239 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1241 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
1243 This->DestRect.left = DestinationLeft;
1245 return S_OK;
1248 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1249 LONG *pDestinationLeft) {
1250 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1252 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1254 *pDestinationLeft = This->DestRect.left;
1256 return S_OK;
1259 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1260 LONG DestinationWidth) {
1261 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1263 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
1265 This->DestRect.right = This->DestRect.left + DestinationWidth;
1267 return S_OK;
1270 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1271 LONG *pDestinationWidth) {
1272 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1274 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1276 *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1278 return S_OK;
1281 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1282 LONG DestinationTop) {
1283 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1285 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
1287 This->DestRect.top = DestinationTop;
1289 return S_OK;
1292 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1293 LONG *pDestinationTop) {
1294 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1296 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1298 *pDestinationTop = This->DestRect.top;
1300 return S_OK;
1303 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1304 LONG DestinationHeight) {
1305 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1307 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
1309 This->DestRect.right = This->DestRect.left + DestinationHeight;
1311 return S_OK;
1314 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1315 LONG *pDestinationHeight) {
1316 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1318 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1320 *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1322 return S_OK;
1325 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1326 LONG Left,
1327 LONG Top,
1328 LONG Width,
1329 LONG Height) {
1330 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1332 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1334 This->SourceRect.left = Left;
1335 This->SourceRect.top = Top;
1336 This->SourceRect.right = Left + Width;
1337 This->SourceRect.bottom = Top + Height;
1339 return S_OK;
1342 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1343 LONG *pLeft,
1344 LONG *pTop,
1345 LONG *pWidth,
1346 LONG *pHeight) {
1347 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1349 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1351 *pLeft = This->SourceRect.left;
1352 *pTop = This->SourceRect.top;
1353 *pWidth = This->SourceRect.right - This->SourceRect.left;
1354 *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1356 return S_OK;
1359 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1360 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1362 TRACE("(%p/%p)->()\n", This, iface);
1364 This->SourceRect.left = 0;
1365 This->SourceRect.top = 0;
1366 This->SourceRect.right = This->VideoWidth;
1367 This->SourceRect.bottom = This->VideoHeight;
1369 return S_OK;
1372 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1373 LONG Left,
1374 LONG Top,
1375 LONG Width,
1376 LONG Height) {
1377 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1379 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1381 This->DestRect.left = Left;
1382 This->DestRect.top = Top;
1383 This->DestRect.right = Left + Width;
1384 This->DestRect.bottom = Top + Height;
1386 return S_OK;
1389 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1390 LONG *pLeft,
1391 LONG *pTop,
1392 LONG *pWidth,
1393 LONG *pHeight) {
1394 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1396 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1398 *pLeft = This->DestRect.left;
1399 *pTop = This->DestRect.top;
1400 *pWidth = This->DestRect.right - This->DestRect.left;
1401 *pHeight = This->DestRect.bottom - This->DestRect.top;
1403 return S_OK;
1406 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1407 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1408 RECT rect;
1410 TRACE("(%p/%p)->()\n", This, iface);
1412 if (!GetClientRect(This->hWnd, &rect))
1413 return E_FAIL;
1415 This->SourceRect.left = 0;
1416 This->SourceRect.top = 0;
1417 This->SourceRect.right = rect.right;
1418 This->SourceRect.bottom = rect.bottom;
1420 return S_OK;
1423 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1424 LONG *pWidth,
1425 LONG *pHeight) {
1426 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1428 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1430 *pWidth = This->VideoWidth;
1431 *pHeight = This->VideoHeight;
1433 return S_OK;
1436 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1437 LONG StartIndex,
1438 LONG Entries,
1439 LONG *pRetrieved,
1440 LONG *pPalette) {
1441 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1443 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1445 if (pRetrieved)
1446 *pRetrieved = 0;
1447 return VFW_E_NO_PALETTE_AVAILABLE;
1450 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1451 LONG *pBufferSize,
1452 LONG *pDIBImage) {
1453 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1454 BITMAPINFOHEADER *bmiHeader;
1455 LONG needed_size;
1456 AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1457 char *ptr;
1459 FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1461 EnterCriticalSection(&This->filter.csFilter);
1463 if (!This->sample_held)
1465 LeaveCriticalSection(&This->filter.csFilter);
1466 return (This->filter.state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1469 if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1471 bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1473 else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1475 bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1477 else
1479 FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1480 LeaveCriticalSection(&This->filter.csFilter);
1481 return VFW_E_RUNTIME_ERROR;
1484 needed_size = bmiHeader->biSize;
1485 needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1487 if (!pDIBImage)
1489 *pBufferSize = needed_size;
1490 LeaveCriticalSection(&This->filter.csFilter);
1491 return S_OK;
1494 if (needed_size < *pBufferSize)
1496 ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
1497 LeaveCriticalSection(&This->filter.csFilter);
1498 return E_FAIL;
1500 *pBufferSize = needed_size;
1502 memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1503 IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1504 memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1506 LeaveCriticalSection(&This->filter.csFilter);
1508 return S_OK;
1511 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1512 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1514 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1516 return S_OK;
1519 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1520 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1522 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1524 return S_OK;
1528 static const IBasicVideoVtbl IBasicVideo_VTable =
1530 Basicvideo_QueryInterface,
1531 Basicvideo_AddRef,
1532 Basicvideo_Release,
1533 Basicvideo_GetTypeInfoCount,
1534 Basicvideo_GetTypeInfo,
1535 Basicvideo_GetIDsOfNames,
1536 Basicvideo_Invoke,
1537 Basicvideo_get_AvgTimePerFrame,
1538 Basicvideo_get_BitRate,
1539 Basicvideo_get_BitErrorRate,
1540 Basicvideo_get_VideoWidth,
1541 Basicvideo_get_VideoHeight,
1542 Basicvideo_put_SourceLeft,
1543 Basicvideo_get_SourceLeft,
1544 Basicvideo_put_SourceWidth,
1545 Basicvideo_get_SourceWidth,
1546 Basicvideo_put_SourceTop,
1547 Basicvideo_get_SourceTop,
1548 Basicvideo_put_SourceHeight,
1549 Basicvideo_get_SourceHeight,
1550 Basicvideo_put_DestinationLeft,
1551 Basicvideo_get_DestinationLeft,
1552 Basicvideo_put_DestinationWidth,
1553 Basicvideo_get_DestinationWidth,
1554 Basicvideo_put_DestinationTop,
1555 Basicvideo_get_DestinationTop,
1556 Basicvideo_put_DestinationHeight,
1557 Basicvideo_get_DestinationHeight,
1558 Basicvideo_SetSourcePosition,
1559 Basicvideo_GetSourcePosition,
1560 Basicvideo_SetDefaultSourcePosition,
1561 Basicvideo_SetDestinationPosition,
1562 Basicvideo_GetDestinationPosition,
1563 Basicvideo_SetDefaultDestinationPosition,
1564 Basicvideo_GetVideoSize,
1565 Basicvideo_GetVideoPaletteEntries,
1566 Basicvideo_GetCurrentImage,
1567 Basicvideo_IsUsingDefaultSource,
1568 Basicvideo_IsUsingDefaultDestination
1572 /*** IUnknown methods ***/
1573 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1574 REFIID riid,
1575 LPVOID*ppvObj) {
1576 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1578 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1580 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1583 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1584 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1586 TRACE("(%p/%p)->()\n", This, iface);
1588 return VideoRenderer_AddRef((IBaseFilter*)This);
1591 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1592 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1594 TRACE("(%p/%p)->()\n", This, iface);
1596 return VideoRenderer_Release((IBaseFilter*)This);
1599 /*** IDispatch methods ***/
1600 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1601 UINT*pctinfo) {
1602 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1604 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1606 return S_OK;
1609 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1610 UINT iTInfo,
1611 LCID lcid,
1612 ITypeInfo**ppTInfo) {
1613 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1615 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1617 return S_OK;
1620 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1621 REFIID riid,
1622 LPOLESTR*rgszNames,
1623 UINT cNames,
1624 LCID lcid,
1625 DISPID*rgDispId) {
1626 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1628 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1630 return S_OK;
1633 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1634 DISPID dispIdMember,
1635 REFIID riid,
1636 LCID lcid,
1637 WORD wFlags,
1638 DISPPARAMS*pDispParams,
1639 VARIANT*pVarResult,
1640 EXCEPINFO*pExepInfo,
1641 UINT*puArgErr) {
1642 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1644 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);
1646 return S_OK;
1649 /*** IVideoWindow methods ***/
1650 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1651 BSTR strCaption) {
1652 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1654 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1656 if (!SetWindowTextW(This->hWnd, strCaption))
1657 return E_FAIL;
1659 return S_OK;
1662 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1663 BSTR *strCaption) {
1664 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1666 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1668 GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1670 return S_OK;
1673 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1674 LONG WindowStyle) {
1675 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1676 LONG old;
1678 old = GetWindowLongW(This->hWnd, GWL_STYLE);
1680 TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
1682 if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1683 return E_INVALIDARG;
1685 SetWindowLongW(This->hWnd, GWL_STYLE, WindowStyle);
1686 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1687 This->WindowStyle = WindowStyle;
1689 return S_OK;
1692 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1693 LONG *WindowStyle) {
1694 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1696 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1698 *WindowStyle = This->WindowStyle;
1700 return S_OK;
1703 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1704 LONG WindowStyleEx) {
1705 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1707 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
1709 if (!SetWindowLongW(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1710 return E_FAIL;
1712 return S_OK;
1715 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1716 LONG *WindowStyleEx) {
1717 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1719 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1721 *WindowStyleEx = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
1723 return S_OK;
1726 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1727 LONG AutoShow) {
1728 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1730 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
1732 This->AutoShow = AutoShow;
1734 return S_OK;
1737 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1738 LONG *AutoShow) {
1739 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1741 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1743 *AutoShow = This->AutoShow;
1745 return S_OK;
1748 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1749 LONG WindowState) {
1750 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1752 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
1753 ShowWindow(This->hWnd, WindowState);
1754 return S_OK;
1757 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1758 LONG *WindowState) {
1759 WINDOWPLACEMENT place;
1760 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1762 place.length = sizeof(place);
1763 GetWindowPlacement(This->hWnd, &place);
1764 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
1765 *WindowState = place.showCmd;
1767 return S_OK;
1770 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1771 LONG BackgroundPalette) {
1772 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1774 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
1776 return S_OK;
1779 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1780 LONG *pBackgroundPalette) {
1781 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1783 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1785 return S_OK;
1788 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1789 LONG Visible) {
1790 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1792 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
1794 ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1796 return S_OK;
1799 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1800 LONG *pVisible) {
1801 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1803 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1805 *pVisible = IsWindowVisible(This->hWnd);
1807 return S_OK;
1810 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1811 LONG Left) {
1812 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1814 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
1816 if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1817 return E_FAIL;
1819 This->WindowPos.left = Left;
1821 return S_OK;
1824 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1825 LONG *pLeft) {
1826 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1828 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1830 *pLeft = This->WindowPos.left;
1832 return S_OK;
1835 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1836 LONG Width) {
1837 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1839 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
1841 if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1842 return E_FAIL;
1844 This->WindowPos.right = This->WindowPos.left + Width;
1846 return S_OK;
1849 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1850 LONG *pWidth) {
1851 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1853 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1855 *pWidth = This->WindowPos.right - This->WindowPos.left;
1857 return S_OK;
1860 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1861 LONG Top) {
1862 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1864 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
1866 if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1867 return E_FAIL;
1869 This->WindowPos.top = Top;
1871 return S_OK;
1874 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1875 LONG *pTop) {
1876 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1878 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1880 *pTop = This->WindowPos.top;
1882 return S_OK;
1885 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1886 LONG Height) {
1887 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1889 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
1891 if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1892 return E_FAIL;
1894 This->WindowPos.bottom = This->WindowPos.top + Height;
1896 return S_OK;
1899 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1900 LONG *pHeight) {
1901 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1903 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1905 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1907 return S_OK;
1910 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1911 OAHWND Owner) {
1912 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1914 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1916 This->hWndOwner = (HWND)Owner;
1917 SetParent(This->hWnd, This->hWndOwner);
1918 if (This->WindowStyle & WS_CHILD)
1920 LONG old = GetWindowLongW(This->hWnd, GWL_STYLE);
1921 if (old != This->WindowStyle)
1923 SetWindowLongW(This->hWnd, GWL_STYLE, This->WindowStyle);
1924 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1928 return S_OK;
1931 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
1932 OAHWND *Owner) {
1933 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1935 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
1937 *(HWND*)Owner = This->hWndOwner;
1939 return S_OK;
1942 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
1943 OAHWND Drain) {
1944 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1946 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
1948 This->hWndMsgDrain = (HWND)Drain;
1950 return S_OK;
1953 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
1954 OAHWND *Drain) {
1955 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1957 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
1959 *Drain = (OAHWND)This->hWndMsgDrain;
1961 return S_OK;
1964 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
1965 LONG *Color) {
1966 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1968 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
1970 return S_OK;
1973 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
1974 LONG Color) {
1975 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1977 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
1979 return S_OK;
1982 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
1983 LONG *FullScreenMode) {
1984 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1986 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
1988 return S_OK;
1991 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
1992 LONG FullScreenMode) {
1993 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1995 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
1997 if (FullScreenMode) {
1998 ShowWindow(This->hWnd, SW_HIDE);
1999 SetParent(This->hWnd, 0);
2000 SetWindowLongW(This->hWnd, GWL_STYLE, WS_POPUP);
2001 SetWindowPos(This->hWnd,HWND_TOP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SWP_SHOWWINDOW);
2002 GetWindowRect(This->hWnd, &This->DestRect);
2003 This->WindowPos = This->DestRect;
2004 } else {
2005 ShowWindow(This->hWnd, SW_HIDE);
2006 SetParent(This->hWnd, This->hWndOwner);
2007 SetWindowLongW(This->hWnd, GWL_STYLE, This->WindowStyle);
2008 GetClientRect(This->hWnd, &This->DestRect);
2009 SetWindowPos(This->hWnd,0,This->DestRect.left,This->DestRect.top,This->DestRect.right,This->DestRect.bottom,SWP_NOZORDER|SWP_SHOWWINDOW);
2010 This->WindowPos = This->DestRect;
2013 return S_OK;
2016 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2017 LONG Focus) {
2018 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2019 BOOL ret;
2020 IPin* pPin;
2021 HRESULT hr;
2023 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
2025 if ((Focus != FALSE) && (Focus != TRUE))
2026 return E_INVALIDARG;
2028 hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2029 if ((hr != S_OK) || !pPin)
2030 return VFW_E_NOT_CONNECTED;
2032 if (Focus)
2033 ret = SetForegroundWindow(This->hWnd);
2034 else
2035 ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2037 if (!ret)
2038 return E_FAIL;
2040 return S_OK;
2043 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2044 OAHWND hwnd,
2045 LONG uMsg,
2046 LONG_PTR wParam,
2047 LONG_PTR lParam) {
2048 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2050 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
2052 if (!PostMessageW(This->hWnd, uMsg, wParam, lParam))
2053 return E_FAIL;
2055 return S_OK;
2058 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2059 LONG Left,
2060 LONG Top,
2061 LONG Width,
2062 LONG Height) {
2063 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2065 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
2067 if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2068 return E_FAIL;
2070 This->WindowPos.left = Left;
2071 This->WindowPos.top = Top;
2072 This->WindowPos.right = Left + Width;
2073 This->WindowPos.bottom = Top + Height;
2075 return S_OK;
2078 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2079 LONG *pLeft,
2080 LONG *pTop,
2081 LONG *pWidth,
2082 LONG *pHeight) {
2083 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2085 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2087 *pLeft = This->WindowPos.left;
2088 *pTop = This->WindowPos.top;
2089 *pWidth = This->WindowPos.right - This->WindowPos.left;
2090 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2092 return S_OK;
2095 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2096 LONG *pWidth,
2097 LONG *pHeight) {
2098 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2100 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2102 *pWidth = This->VideoWidth;
2103 *pHeight = This->VideoHeight;
2105 return S_OK;
2108 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2109 LONG *pWidth,
2110 LONG *pHeight) {
2111 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2113 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2115 *pWidth = This->VideoWidth;
2116 *pHeight = This->VideoHeight;
2118 return S_OK;
2121 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2122 LONG *pLeft,
2123 LONG *pTop,
2124 LONG *pWidth,
2125 LONG *pHeight) {
2126 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2128 FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2130 return S_OK;
2133 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2134 LONG HideCursor) {
2135 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2137 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
2139 return S_OK;
2142 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2143 LONG *CursorHidden) {
2144 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2146 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2148 return S_OK;
2151 static const IVideoWindowVtbl IVideoWindow_VTable =
2153 Videowindow_QueryInterface,
2154 Videowindow_AddRef,
2155 Videowindow_Release,
2156 Videowindow_GetTypeInfoCount,
2157 Videowindow_GetTypeInfo,
2158 Videowindow_GetIDsOfNames,
2159 Videowindow_Invoke,
2160 Videowindow_put_Caption,
2161 Videowindow_get_Caption,
2162 Videowindow_put_WindowStyle,
2163 Videowindow_get_WindowStyle,
2164 Videowindow_put_WindowStyleEx,
2165 Videowindow_get_WindowStyleEx,
2166 Videowindow_put_AutoShow,
2167 Videowindow_get_AutoShow,
2168 Videowindow_put_WindowState,
2169 Videowindow_get_WindowState,
2170 Videowindow_put_BackgroundPalette,
2171 Videowindow_get_BackgroundPalette,
2172 Videowindow_put_Visible,
2173 Videowindow_get_Visible,
2174 Videowindow_put_Left,
2175 Videowindow_get_Left,
2176 Videowindow_put_Width,
2177 Videowindow_get_Width,
2178 Videowindow_put_Top,
2179 Videowindow_get_Top,
2180 Videowindow_put_Height,
2181 Videowindow_get_Height,
2182 Videowindow_put_Owner,
2183 Videowindow_get_Owner,
2184 Videowindow_put_MessageDrain,
2185 Videowindow_get_MessageDrain,
2186 Videowindow_get_BorderColor,
2187 Videowindow_put_BorderColor,
2188 Videowindow_get_FullScreenMode,
2189 Videowindow_put_FullScreenMode,
2190 Videowindow_SetWindowForeground,
2191 Videowindow_NotifyOwnerMessage,
2192 Videowindow_SetWindowPosition,
2193 Videowindow_GetWindowPosition,
2194 Videowindow_GetMinIdealImageSize,
2195 Videowindow_GetMaxIdealImageSize,
2196 Videowindow_GetRestorePosition,
2197 Videowindow_HideCursor,
2198 Videowindow_IsCursorHidden
2201 static VideoRendererImpl *from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface) {
2202 return (VideoRendererImpl*)((char*)iface - offsetof(VideoRendererImpl, IAMFilterMiscFlags_vtbl));
2205 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, REFIID riid, void **ppv) {
2206 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2207 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
2210 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
2211 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2212 return IUnknown_AddRef((IUnknown*)This);
2215 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
2216 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2217 return IUnknown_Release((IUnknown*)This);
2220 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
2221 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
2224 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
2225 AMFilterMiscFlags_QueryInterface,
2226 AMFilterMiscFlags_AddRef,
2227 AMFilterMiscFlags_Release,
2228 AMFilterMiscFlags_GetMiscFlags