quartz: Add IQualityControl to video renderer.
[wine/multimedia.git] / dlls / quartz / videorenderer.c
blobe135fb9b774d008804ba32160103fd4b2d8d25ff
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 REFERENCE_TIME rtLastStop;
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 VideoWndProcA(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 PostMessageA(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 DefWindowProcA(hwnd, uMsg, wParam, lParam);
164 return 0;
167 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
169 WNDCLASSA winclass;
171 TRACE("(%p)->()\n", This);
173 winclass.style = 0;
174 winclass.lpfnWndProc = VideoWndProcA;
175 winclass.cbClsExtra = 0;
176 winclass.cbWndExtra = sizeof(VideoRendererImpl*);
177 winclass.hInstance = NULL;
178 winclass.hIcon = NULL;
179 winclass.hCursor = NULL;
180 winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
181 winclass.lpszMenuName = NULL;
182 winclass.lpszClassName = "Wine ActiveMovie Class";
184 if (!wnd_class_registered)
186 if (!RegisterClassA(&winclass))
188 ERR("Unable to register window %u\n", GetLastError());
189 return FALSE;
191 wnd_class_registered = TRUE;
194 This->hWnd = CreateWindowExA(0, "Wine ActiveMovie Class", "Wine ActiveMovie Window", WS_SIZEBOX,
195 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
196 NULL, NULL, NULL);
198 if (!This->hWnd)
200 ERR("Unable to create window\n");
201 return FALSE;
204 SetWindowLongPtrW(This->hWnd, 0, (LONG_PTR)This);
206 return TRUE;
209 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
211 VideoRendererImpl* This = lpParameter;
212 MSG msg;
213 BOOL fGotMessage;
215 TRACE("Starting message loop\n");
217 if (!CreateRenderingWindow(This))
219 This->ThreadResult = FALSE;
220 SetEvent(This->hEvent);
221 return 0;
224 This->ThreadResult = TRUE;
225 SetEvent(This->hEvent);
227 while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
229 TranslateMessage(&msg);
230 DispatchMessageA(&msg);
233 TRACE("End of message loop\n");
235 return msg.wParam;
238 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
240 This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
241 if (!This->hEvent)
242 return FALSE;
244 This->hThread = CreateThread(NULL, 0, MessageLoop, This, 0, &This->ThreadID);
245 if (!This->hThread)
247 CloseHandle(This->hEvent);
248 return FALSE;
251 WaitForSingleObject(This->hEvent, INFINITE);
253 if (!This->ThreadResult)
255 CloseHandle(This->hEvent);
256 CloseHandle(This->hThread);
257 return FALSE;
260 return TRUE;
263 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
265 AM_MEDIA_TYPE amt;
266 HRESULT hr = S_OK;
267 DDSURFACEDESC sdesc;
268 HDC hDC;
269 BITMAPINFOHEADER *bmiHeader;
271 TRACE("(%p)->(%p, %d)\n", This, data, size);
273 sdesc.dwSize = sizeof(sdesc);
274 hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
275 if (FAILED(hr)) {
276 ERR("Unable to retrieve media type\n");
277 return hr;
280 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
282 bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
284 else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
286 bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
288 else
290 FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
291 return VFW_E_RUNTIME_ERROR;
294 TRACE("biSize = %d\n", bmiHeader->biSize);
295 TRACE("biWidth = %d\n", bmiHeader->biWidth);
296 TRACE("biHeight = %d\n", bmiHeader->biHeight);
297 TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
298 TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
299 TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
300 TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
302 if (!This->init)
304 if (!This->WindowPos.right || !This->WindowPos.top)
306 DWORD style = GetWindowLongW(This->hWnd, GWL_STYLE);
307 DWORD style_ex = GetWindowLongW(This->hWnd, GWL_EXSTYLE);
309 if (!This->WindowPos.right)
311 This->WindowPos.left = This->SourceRect.left;
312 This->WindowPos.right = This->SourceRect.right;
314 if (!This->WindowPos.bottom)
316 This->WindowPos.top = This->SourceRect.top;
317 This->WindowPos.bottom = This->SourceRect.bottom;
320 AdjustWindowRectEx(&This->WindowPos, style, TRUE, style_ex);
322 TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
323 SetWindowPos(This->hWnd, NULL,
324 This->WindowPos.left,
325 This->WindowPos.top,
326 This->WindowPos.right - This->WindowPos.left,
327 This->WindowPos.bottom - This->WindowPos.top,
328 SWP_NOZORDER|SWP_NOMOVE|SWP_DEFERERASE);
330 GetClientRect(This->hWnd, &This->DestRect);
332 else
333 This->DestRect = This->WindowPos;
334 This->init = TRUE;
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);
353 if (This->AutoShow)
354 ShowWindow(This->hWnd, SW_SHOW);
356 return S_OK;
359 static HRESULT WINAPI VideoRenderer_Receive(BaseInputPin* pin, IMediaSample * pSample)
361 VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
362 LPBYTE pbSrcStream = NULL;
363 LONG cbSrcStream = 0;
364 REFERENCE_TIME tStart, tStop;
365 HRESULT hr;
367 TRACE("(%p)->(%p)\n", pin, pSample);
369 EnterCriticalSection(&This->filter.csFilter);
371 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
373 LeaveCriticalSection(&This->filter.csFilter);
374 return S_FALSE;
377 if (This->filter.state == State_Stopped)
379 LeaveCriticalSection(&This->filter.csFilter);
380 return VFW_E_WRONG_STATE;
383 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
384 if (FAILED(hr))
385 ERR("Cannot get sample time (%x)\n", hr);
386 else
387 MediaSeekingPassThru_RegisterMediaTime(This->seekthru_unk, tStart);
389 if (This->rtLastStop != tStart && This->filter.state == State_Running)
391 LONG64 delta;
392 delta = tStart - This->rtLastStop;
393 if ((delta < -100000 || delta > 100000) &&
394 IMediaSample_IsDiscontinuity(pSample) == S_FALSE)
395 ERR("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
396 (DWORD)(This->rtLastStop / 10000000),
397 (DWORD)((This->rtLastStop / 10000)%1000),
398 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
399 This->rtLastStop = tStart;
402 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
403 if (IMediaSample_IsPreroll(pSample) == S_OK)
405 This->rtLastStop = tStop;
406 LeaveCriticalSection(&This->filter.csFilter);
407 return S_OK;
410 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
411 if (FAILED(hr))
413 ERR("Cannot get pointer to sample data (%x)\n", hr);
414 LeaveCriticalSection(&This->filter.csFilter);
415 return hr;
418 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
420 TRACE("val %p %d\n", pbSrcStream, cbSrcStream);
422 #if 0 /* For debugging purpose */
424 int i;
425 for(i = 0; i < cbSrcStream; i++)
427 if ((i!=0) && !(i%16))
428 TRACE("\n");
429 TRACE("%02x ", pbSrcStream[i]);
431 TRACE("\n");
433 #endif
435 SetEvent(This->hEvent);
436 if (This->filter.state == State_Paused)
438 This->sample_held = pSample;
439 LeaveCriticalSection(&This->filter.csFilter);
440 WaitForSingleObject(This->blocked, INFINITE);
441 EnterCriticalSection(&This->filter.csFilter);
442 This->sample_held = NULL;
443 if (This->filter.state == State_Paused)
445 /* Flushing */
446 LeaveCriticalSection(&This->filter.csFilter);
447 return S_OK;
449 if (This->filter.state == State_Stopped)
451 LeaveCriticalSection(&This->filter.csFilter);
452 return VFW_E_WRONG_STATE;
456 if (This->filter.pClock && This->filter.state == State_Running)
458 REFERENCE_TIME time, trefstart, trefstop;
459 LONG delta;
461 /* Perhaps I <SHOULD> use the reference clock AdviseTime function here
462 * I'm not going to! When I tried, it seemed to generate lag and
463 * it caused instability.
465 IReferenceClock_GetTime(This->filter.pClock, &time);
467 trefstart = This->filter.rtStreamStart;
468 trefstop = (REFERENCE_TIME)((double)(tStop - tStart) / This->pInputPin->pin.dRate) + This->filter.rtStreamStart;
469 delta = (LONG)((trefstart-time)/10000);
470 This->filter.rtStreamStart = trefstop;
471 This->rtLastStop = tStop;
473 if (delta > 0)
475 TRACE("Sleeping for %u ms\n", delta);
476 Sleep(delta);
478 else if (time > trefstop)
480 TRACE("Dropping sample: Time: %u.%03u ms trefstop: %u.%03u ms!\n",
481 (DWORD)(time / 10000000), (DWORD)((time / 10000)%1000),
482 (DWORD)(trefstop / 10000000), (DWORD)((trefstop / 10000)%1000) );
483 This->rtLastStop = tStop;
484 LeaveCriticalSection(&This->filter.csFilter);
485 return S_OK;
488 This->rtLastStop = tStop;
490 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
492 LeaveCriticalSection(&This->filter.csFilter);
493 return S_OK;
496 static HRESULT WINAPI VideoRenderer_CheckMediaType(BasePin *iface, const AM_MEDIA_TYPE * pmt)
498 BaseInputPin* pin = (BaseInputPin*)iface;
499 VideoRendererImpl *This = (VideoRendererImpl *)pin->pin.pinInfo.pFilter;
501 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
502 return S_FALSE;
504 if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
505 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
506 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
507 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
509 LONG height;
511 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
513 VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
514 This->SourceRect.left = 0;
515 This->SourceRect.top = 0;
516 This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
517 height = format->bmiHeader.biHeight;
518 if (height < 0)
519 This->SourceRect.bottom = This->VideoHeight = -height;
520 else
521 This->SourceRect.bottom = This->VideoHeight = height;
523 else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
525 VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
527 This->SourceRect.left = 0;
528 This->SourceRect.top = 0;
529 This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
530 height = format2->bmiHeader.biHeight;
531 if (height < 0)
532 This->SourceRect.bottom = This->VideoHeight = -height;
533 else
534 This->SourceRect.bottom = This->VideoHeight = height;
536 else
538 WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
539 return S_FALSE;
541 return S_OK;
543 return S_FALSE;
546 static IPin* WINAPI VideoRenderer_GetPin(BaseFilter *iface, int pos)
548 VideoRendererImpl *This = (VideoRendererImpl *)iface;
550 if (pos >= 1 || pos < 0)
551 return NULL;
553 IPin_AddRef((IPin *)This->pInputPin);
554 return (IPin *)This->pInputPin;
557 static LONG WINAPI VideoRenderer_GetPinCount(BaseFilter *iface)
559 return 1;
562 static const BaseFilterFuncTable BaseFuncTable = {
563 VideoRenderer_GetPin,
564 VideoRenderer_GetPinCount
567 static const BasePinFuncTable input_BaseFuncTable = {
568 VideoRenderer_CheckMediaType,
569 NULL,
570 BasePinImpl_GetMediaTypeVersion,
571 BasePinImpl_GetMediaType
574 static const BaseInputPinFuncTable input_BaseInputFuncTable = {
575 VideoRenderer_Receive
578 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
580 HRESULT hr;
581 PIN_INFO piInput;
582 VideoRendererImpl * pVideoRenderer;
583 ISeekingPassThru *passthru;
585 TRACE("(%p, %p)\n", pUnkOuter, ppv);
587 *ppv = NULL;
589 pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
590 pVideoRenderer->pUnkOuter = pUnkOuter;
591 pVideoRenderer->bUnkOuterValid = FALSE;
592 pVideoRenderer->bAggregatable = FALSE;
593 pVideoRenderer->IInner_vtbl = &IInner_VTable;
594 pVideoRenderer->IAMFilterMiscFlags_vtbl = &IAMFilterMiscFlags_Vtbl;
596 BaseFilter_Init(&pVideoRenderer->filter, &VideoRenderer_Vtbl, &CLSID_VideoRenderer, (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter"), &BaseFuncTable);
598 pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
599 pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
601 pVideoRenderer->init = 0;
602 pVideoRenderer->AutoShow = 1;
603 pVideoRenderer->rtLastStop = -1;
604 ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
605 ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
606 ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
607 pVideoRenderer->hWndMsgDrain = NULL;
608 pVideoRenderer->WindowStyle = WS_OVERLAPPED;
610 /* construct input pin */
611 piInput.dir = PINDIR_INPUT;
612 piInput.pFilter = (IBaseFilter *)pVideoRenderer;
613 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
615 hr = BaseInputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, &input_BaseFuncTable, &input_BaseInputFuncTable, &pVideoRenderer->filter.csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
617 if (SUCCEEDED(hr))
619 hr = CoCreateInstance(&CLSID_SeekingPassThru, pUnkOuter ? pUnkOuter : (IUnknown*)&pVideoRenderer->IInner_vtbl, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&pVideoRenderer->seekthru_unk);
620 if (FAILED(hr)) {
621 IPin_Release((IPin*)pVideoRenderer->pInputPin);
622 goto fail;
624 IUnknown_QueryInterface(pVideoRenderer->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
625 ISeekingPassThru_Init(passthru, TRUE, (IPin*)pVideoRenderer->pInputPin);
626 ISeekingPassThru_Release(passthru);
627 pVideoRenderer->sample_held = NULL;
628 *ppv = pVideoRenderer;
630 if (FAILED(hr))
631 goto fail;
633 QualityControlImpl_init(&pVideoRenderer->qcimpl, (IPin*)pVideoRenderer->pInputPin, (IBaseFilter*)pVideoRenderer);
634 pVideoRenderer->qcimpl.lpVtbl = &VideoRenderer_QualityControl_Vtbl;
636 if (!CreateRenderingSubsystem(pVideoRenderer))
637 return E_FAIL;
639 pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
640 if (!pVideoRenderer->blocked)
642 hr = HRESULT_FROM_WIN32(GetLastError());
643 IUnknown_Release((IUnknown *)pVideoRenderer);
646 return hr;
647 fail:
648 BaseFilterImpl_Release((IBaseFilter*)pVideoRenderer);
649 CoTaskMemFree(pVideoRenderer);
650 return hr;
653 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
655 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
656 return VideoRenderer_create(pUnkOuter, ppv);
659 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
661 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
662 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
664 if (This->bAggregatable)
665 This->bUnkOuterValid = TRUE;
667 *ppv = NULL;
669 if (IsEqualIID(riid, &IID_IUnknown))
670 *ppv = &This->IInner_vtbl;
671 else if (IsEqualIID(riid, &IID_IPersist))
672 *ppv = This;
673 else if (IsEqualIID(riid, &IID_IMediaFilter))
674 *ppv = This;
675 else if (IsEqualIID(riid, &IID_IBaseFilter))
676 *ppv = This;
677 else if (IsEqualIID(riid, &IID_IBasicVideo))
678 *ppv = &This->IBasicVideo_vtbl;
679 else if (IsEqualIID(riid, &IID_IVideoWindow))
680 *ppv = &This->IVideoWindow_vtbl;
681 else if (IsEqualIID(riid, &IID_IMediaSeeking))
682 return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
683 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
684 *ppv = &This->IAMFilterMiscFlags_vtbl;
685 else if (IsEqualIID(riid, &IID_IQualityControl))
686 *ppv = &This->qcimpl;
688 if (*ppv)
690 IUnknown_AddRef((IUnknown *)(*ppv));
691 return S_OK;
694 if (!IsEqualIID(riid, &IID_IPin))
695 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
697 return E_NOINTERFACE;
700 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
702 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
703 ULONG refCount = InterlockedIncrement(&This->filter.refCount);
705 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
707 return refCount;
710 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
712 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
713 ULONG refCount = InterlockedDecrement(&This->filter.refCount);
715 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
717 if (!refCount)
719 IPin *pConnectedTo;
721 DestroyWindow(This->hWnd);
722 PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
723 WaitForSingleObject(This->hThread, INFINITE);
724 CloseHandle(This->hThread);
725 CloseHandle(This->hEvent);
727 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
729 IPin_Disconnect(pConnectedTo);
730 IPin_Release(pConnectedTo);
732 IPin_Disconnect((IPin *)This->pInputPin);
734 IPin_Release((IPin *)This->pInputPin);
736 This->filter.lpVtbl = NULL;
737 IUnknown_Release(This->seekthru_unk);
738 This->filter.csFilter.DebugInfo->Spare[0] = 0;
739 DeleteCriticalSection(&This->filter.csFilter);
741 TRACE("Destroying Video Renderer\n");
742 CoTaskMemFree(This);
744 return 0;
746 else
747 return refCount;
750 static const IUnknownVtbl IInner_VTable =
752 VideoRendererInner_QueryInterface,
753 VideoRendererInner_AddRef,
754 VideoRendererInner_Release
757 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
759 VideoRendererImpl *This = (VideoRendererImpl *)iface;
761 if (This->bAggregatable)
762 This->bUnkOuterValid = TRUE;
764 if (This->pUnkOuter)
766 if (This->bAggregatable)
767 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
769 if (IsEqualIID(riid, &IID_IUnknown))
771 HRESULT hr;
773 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
774 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
775 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
776 This->bAggregatable = TRUE;
777 return hr;
780 *ppv = NULL;
781 return E_NOINTERFACE;
784 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
787 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
789 VideoRendererImpl *This = (VideoRendererImpl *)iface;
791 if (This->pUnkOuter && This->bUnkOuterValid)
792 return IUnknown_AddRef(This->pUnkOuter);
793 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
796 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
798 VideoRendererImpl *This = (VideoRendererImpl *)iface;
800 if (This->pUnkOuter && This->bUnkOuterValid)
801 return IUnknown_Release(This->pUnkOuter);
802 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
805 /** IMediaFilter methods **/
807 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
809 VideoRendererImpl *This = (VideoRendererImpl *)iface;
811 TRACE("(%p/%p)->()\n", This, iface);
813 EnterCriticalSection(&This->filter.csFilter);
815 This->filter.state = State_Stopped;
816 SetEvent(This->hEvent);
817 SetEvent(This->blocked);
818 MediaSeekingPassThru_ResetMediaTime(This->seekthru_unk);
820 LeaveCriticalSection(&This->filter.csFilter);
822 return S_OK;
825 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
827 VideoRendererImpl *This = (VideoRendererImpl *)iface;
829 TRACE("(%p/%p)->()\n", This, iface);
831 EnterCriticalSection(&This->filter.csFilter);
832 if (This->filter.state != State_Paused)
834 if (This->filter.state == State_Stopped)
836 This->pInputPin->end_of_stream = 0;
837 ResetEvent(This->hEvent);
840 This->filter.state = State_Paused;
841 ResetEvent(This->blocked);
843 LeaveCriticalSection(&This->filter.csFilter);
845 return S_OK;
848 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
850 HRESULT hr = S_OK;
851 VideoRendererImpl *This = (VideoRendererImpl *)iface;
853 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
855 EnterCriticalSection(&This->filter.csFilter);
856 if (This->filter.state == State_Running)
857 goto out;
858 if (This->pInputPin->pin.pConnectedTo)
860 if (This->filter.state == State_Stopped)
862 This->pInputPin->end_of_stream = 0;
863 ResetEvent(This->hEvent);
865 SetEvent(This->blocked);
867 This->filter.rtStreamStart = tStart;
868 This->filter.state = State_Running;
869 } else if (This->filter.filterInfo.pGraph) {
870 IMediaEventSink *pEventSink;
871 hr = IFilterGraph_QueryInterface(This->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
872 if (SUCCEEDED(hr))
874 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)This);
875 IMediaEventSink_Release(pEventSink);
877 hr = S_OK;
879 if (SUCCEEDED(hr))
880 This->filter.state = State_Running;
881 out:
882 LeaveCriticalSection(&This->filter.csFilter);
884 return hr;
887 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
889 VideoRendererImpl *This = (VideoRendererImpl *)iface;
890 HRESULT hr;
892 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
894 if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
895 hr = VFW_S_STATE_INTERMEDIATE;
896 else
897 hr = S_OK;
899 BaseFilterImpl_GetState(iface, dwMilliSecsTimeout, pState);
901 return hr;
904 /** IBaseFilter implementation **/
906 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
908 VideoRendererImpl *This = (VideoRendererImpl *)iface;
910 FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
912 /* FIXME: critical section */
914 return E_NOTIMPL;
917 static const IBaseFilterVtbl VideoRenderer_Vtbl =
919 VideoRenderer_QueryInterface,
920 VideoRenderer_AddRef,
921 VideoRenderer_Release,
922 BaseFilterImpl_GetClassID,
923 VideoRenderer_Stop,
924 VideoRenderer_Pause,
925 VideoRenderer_Run,
926 VideoRenderer_GetState,
927 BaseFilterImpl_SetSyncSource,
928 BaseFilterImpl_GetSyncSource,
929 BaseFilterImpl_EnumPins,
930 VideoRenderer_FindPin,
931 BaseFilterImpl_QueryFilterInfo,
932 BaseFilterImpl_JoinFilterGraph,
933 BaseFilterImpl_QueryVendorInfo
936 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
938 BaseInputPin* This = (BaseInputPin*)iface;
939 VideoRendererImpl *pFilter;
940 IMediaEventSink* pEventSink;
941 HRESULT hr;
943 TRACE("(%p/%p)->()\n", This, iface);
945 pFilter = (VideoRendererImpl*)This->pin.pinInfo.pFilter;
946 hr = IFilterGraph_QueryInterface(pFilter->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
947 if (SUCCEEDED(hr))
949 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)pFilter);
950 IMediaEventSink_Release(pEventSink);
952 MediaSeekingPassThru_EOS(pFilter->seekthru_unk);
954 return hr;
957 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
959 BaseInputPin* This = (BaseInputPin*)iface;
960 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
961 HRESULT hr;
963 TRACE("(%p/%p)->()\n", This, iface);
965 EnterCriticalSection(This->pin.pCritSec);
966 if (pVideoRenderer->filter.state == State_Paused)
967 SetEvent(pVideoRenderer->blocked);
969 hr = BaseInputPinImpl_BeginFlush(iface);
970 LeaveCriticalSection(This->pin.pCritSec);
972 return hr;
975 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
977 BaseInputPin* This = (BaseInputPin*)iface;
978 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
979 HRESULT hr;
981 TRACE("(%p/%p)->()\n", This, iface);
983 EnterCriticalSection(This->pin.pCritSec);
984 if (pVideoRenderer->filter.state == State_Paused)
985 ResetEvent(pVideoRenderer->blocked);
987 hr = BaseInputPinImpl_EndFlush(iface);
988 LeaveCriticalSection(This->pin.pCritSec);
989 MediaSeekingPassThru_ResetMediaTime(pVideoRenderer->seekthru_unk);
991 return hr;
994 static const IPinVtbl VideoRenderer_InputPin_Vtbl =
996 BaseInputPinImpl_QueryInterface,
997 BasePinImpl_AddRef,
998 BaseInputPinImpl_Release,
999 BaseInputPinImpl_Connect,
1000 BaseInputPinImpl_ReceiveConnection,
1001 BasePinImpl_Disconnect,
1002 BasePinImpl_ConnectedTo,
1003 BasePinImpl_ConnectionMediaType,
1004 BasePinImpl_QueryPinInfo,
1005 BasePinImpl_QueryDirection,
1006 BasePinImpl_QueryId,
1007 BaseInputPinImpl_QueryAccept,
1008 BasePinImpl_EnumMediaTypes,
1009 BasePinImpl_QueryInternalConnections,
1010 VideoRenderer_InputPin_EndOfStream,
1011 VideoRenderer_InputPin_BeginFlush,
1012 VideoRenderer_InputPin_EndFlush,
1013 BaseInputPinImpl_NewSegment
1016 /*** IUnknown methods ***/
1017 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
1018 REFIID riid,
1019 LPVOID*ppvObj) {
1020 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1022 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1024 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1027 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1028 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1030 TRACE("(%p/%p)->()\n", This, iface);
1032 return VideoRenderer_AddRef((IBaseFilter*)This);
1035 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1036 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1038 TRACE("(%p/%p)->()\n", This, iface);
1040 return VideoRenderer_Release((IBaseFilter*)This);
1043 /*** IDispatch methods ***/
1044 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1045 UINT*pctinfo) {
1046 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1048 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1050 return S_OK;
1053 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1054 UINT iTInfo,
1055 LCID lcid,
1056 ITypeInfo**ppTInfo) {
1057 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1059 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1061 return S_OK;
1064 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1065 REFIID riid,
1066 LPOLESTR*rgszNames,
1067 UINT cNames,
1068 LCID lcid,
1069 DISPID*rgDispId) {
1070 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1072 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1074 return S_OK;
1077 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1078 DISPID dispIdMember,
1079 REFIID riid,
1080 LCID lcid,
1081 WORD wFlags,
1082 DISPPARAMS*pDispParams,
1083 VARIANT*pVarResult,
1084 EXCEPINFO*pExepInfo,
1085 UINT*puArgErr) {
1086 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1088 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);
1090 return S_OK;
1093 /*** IBasicVideo methods ***/
1094 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1095 REFTIME *pAvgTimePerFrame) {
1096 AM_MEDIA_TYPE *pmt;
1097 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1099 if (!This->pInputPin->pin.pConnectedTo)
1100 return VFW_E_NOT_CONNECTED;
1102 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
1104 pmt = &This->pInputPin->pin.mtCurrent;
1105 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
1106 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)pmt->pbFormat;
1107 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1108 } else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) {
1109 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)pmt->pbFormat;
1110 *pAvgTimePerFrame = vih->AvgTimePerFrame;
1111 } else {
1112 ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt->formattype));
1113 *pAvgTimePerFrame = 0;
1115 return S_OK;
1118 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1119 LONG *pBitRate) {
1120 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1122 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1124 return S_OK;
1127 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1128 LONG *pBitErrorRate) {
1129 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1131 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1133 return S_OK;
1136 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1137 LONG *pVideoWidth) {
1138 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1140 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1142 *pVideoWidth = This->VideoWidth;
1144 return S_OK;
1147 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1148 LONG *pVideoHeight) {
1149 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1151 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1153 *pVideoHeight = This->VideoHeight;
1155 return S_OK;
1158 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1159 LONG SourceLeft) {
1160 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1162 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
1164 This->SourceRect.left = SourceLeft;
1166 return S_OK;
1169 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1170 LONG *pSourceLeft) {
1171 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1173 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1175 *pSourceLeft = This->SourceRect.left;
1177 return S_OK;
1180 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1181 LONG SourceWidth) {
1182 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1184 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
1186 This->SourceRect.right = This->SourceRect.left + SourceWidth;
1188 return S_OK;
1191 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1192 LONG *pSourceWidth) {
1193 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1195 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1197 *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1199 return S_OK;
1202 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1203 LONG SourceTop) {
1204 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1206 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
1208 This->SourceRect.top = SourceTop;
1210 return S_OK;
1213 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1214 LONG *pSourceTop) {
1215 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1217 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1219 *pSourceTop = This->SourceRect.top;
1221 return S_OK;
1224 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1225 LONG SourceHeight) {
1226 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1228 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
1230 This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1232 return S_OK;
1235 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1236 LONG *pSourceHeight) {
1237 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1239 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1241 *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1243 return S_OK;
1246 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1247 LONG DestinationLeft) {
1248 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1250 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
1252 This->DestRect.left = DestinationLeft;
1254 return S_OK;
1257 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1258 LONG *pDestinationLeft) {
1259 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1261 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1263 *pDestinationLeft = This->DestRect.left;
1265 return S_OK;
1268 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1269 LONG DestinationWidth) {
1270 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1272 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
1274 This->DestRect.right = This->DestRect.left + DestinationWidth;
1276 return S_OK;
1279 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1280 LONG *pDestinationWidth) {
1281 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1283 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1285 *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1287 return S_OK;
1290 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1291 LONG DestinationTop) {
1292 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1294 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
1296 This->DestRect.top = DestinationTop;
1298 return S_OK;
1301 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1302 LONG *pDestinationTop) {
1303 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1305 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1307 *pDestinationTop = This->DestRect.top;
1309 return S_OK;
1312 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1313 LONG DestinationHeight) {
1314 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1316 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
1318 This->DestRect.right = This->DestRect.left + DestinationHeight;
1320 return S_OK;
1323 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1324 LONG *pDestinationHeight) {
1325 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1327 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1329 *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1331 return S_OK;
1334 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1335 LONG Left,
1336 LONG Top,
1337 LONG Width,
1338 LONG Height) {
1339 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1341 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1343 This->SourceRect.left = Left;
1344 This->SourceRect.top = Top;
1345 This->SourceRect.right = Left + Width;
1346 This->SourceRect.bottom = Top + Height;
1348 return S_OK;
1351 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1352 LONG *pLeft,
1353 LONG *pTop,
1354 LONG *pWidth,
1355 LONG *pHeight) {
1356 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1358 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1360 *pLeft = This->SourceRect.left;
1361 *pTop = This->SourceRect.top;
1362 *pWidth = This->SourceRect.right - This->SourceRect.left;
1363 *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1365 return S_OK;
1368 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1369 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1371 TRACE("(%p/%p)->()\n", This, iface);
1373 This->SourceRect.left = 0;
1374 This->SourceRect.top = 0;
1375 This->SourceRect.right = This->VideoWidth;
1376 This->SourceRect.bottom = This->VideoHeight;
1378 return S_OK;
1381 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1382 LONG Left,
1383 LONG Top,
1384 LONG Width,
1385 LONG Height) {
1386 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1388 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
1390 This->DestRect.left = Left;
1391 This->DestRect.top = Top;
1392 This->DestRect.right = Left + Width;
1393 This->DestRect.bottom = Top + Height;
1395 return S_OK;
1398 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1399 LONG *pLeft,
1400 LONG *pTop,
1401 LONG *pWidth,
1402 LONG *pHeight) {
1403 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1405 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1407 *pLeft = This->DestRect.left;
1408 *pTop = This->DestRect.top;
1409 *pWidth = This->DestRect.right - This->DestRect.left;
1410 *pHeight = This->DestRect.bottom - This->DestRect.top;
1412 return S_OK;
1415 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1416 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1417 RECT rect;
1419 TRACE("(%p/%p)->()\n", This, iface);
1421 if (!GetClientRect(This->hWnd, &rect))
1422 return E_FAIL;
1424 This->SourceRect.left = 0;
1425 This->SourceRect.top = 0;
1426 This->SourceRect.right = rect.right;
1427 This->SourceRect.bottom = rect.bottom;
1429 return S_OK;
1432 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1433 LONG *pWidth,
1434 LONG *pHeight) {
1435 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1437 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1439 *pWidth = This->VideoWidth;
1440 *pHeight = This->VideoHeight;
1442 return S_OK;
1445 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1446 LONG StartIndex,
1447 LONG Entries,
1448 LONG *pRetrieved,
1449 LONG *pPalette) {
1450 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1452 FIXME("(%p/%p)->(%d, %d, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1454 return S_OK;
1457 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1458 LONG *pBufferSize,
1459 LONG *pDIBImage) {
1460 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1461 BITMAPINFOHEADER *bmiHeader;
1462 LONG needed_size;
1463 AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1464 char *ptr;
1466 FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1468 EnterCriticalSection(&This->filter.csFilter);
1470 if (!This->sample_held)
1472 LeaveCriticalSection(&This->filter.csFilter);
1473 return (This->filter.state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1476 if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1478 bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1480 else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1482 bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1484 else
1486 FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1487 LeaveCriticalSection(&This->filter.csFilter);
1488 return VFW_E_RUNTIME_ERROR;
1491 needed_size = bmiHeader->biSize;
1492 needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1494 if (!pDIBImage)
1496 *pBufferSize = needed_size;
1497 LeaveCriticalSection(&This->filter.csFilter);
1498 return S_OK;
1501 if (needed_size < *pBufferSize)
1503 ERR("Buffer too small %u/%u\n", needed_size, *pBufferSize);
1504 LeaveCriticalSection(&This->filter.csFilter);
1505 return E_FAIL;
1507 *pBufferSize = needed_size;
1509 memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1510 IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1511 memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1513 LeaveCriticalSection(&This->filter.csFilter);
1515 return S_OK;
1518 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1519 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1521 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1523 return S_OK;
1526 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1527 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1529 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1531 return S_OK;
1535 static const IBasicVideoVtbl IBasicVideo_VTable =
1537 Basicvideo_QueryInterface,
1538 Basicvideo_AddRef,
1539 Basicvideo_Release,
1540 Basicvideo_GetTypeInfoCount,
1541 Basicvideo_GetTypeInfo,
1542 Basicvideo_GetIDsOfNames,
1543 Basicvideo_Invoke,
1544 Basicvideo_get_AvgTimePerFrame,
1545 Basicvideo_get_BitRate,
1546 Basicvideo_get_BitErrorRate,
1547 Basicvideo_get_VideoWidth,
1548 Basicvideo_get_VideoHeight,
1549 Basicvideo_put_SourceLeft,
1550 Basicvideo_get_SourceLeft,
1551 Basicvideo_put_SourceWidth,
1552 Basicvideo_get_SourceWidth,
1553 Basicvideo_put_SourceTop,
1554 Basicvideo_get_SourceTop,
1555 Basicvideo_put_SourceHeight,
1556 Basicvideo_get_SourceHeight,
1557 Basicvideo_put_DestinationLeft,
1558 Basicvideo_get_DestinationLeft,
1559 Basicvideo_put_DestinationWidth,
1560 Basicvideo_get_DestinationWidth,
1561 Basicvideo_put_DestinationTop,
1562 Basicvideo_get_DestinationTop,
1563 Basicvideo_put_DestinationHeight,
1564 Basicvideo_get_DestinationHeight,
1565 Basicvideo_SetSourcePosition,
1566 Basicvideo_GetSourcePosition,
1567 Basicvideo_SetDefaultSourcePosition,
1568 Basicvideo_SetDestinationPosition,
1569 Basicvideo_GetDestinationPosition,
1570 Basicvideo_SetDefaultDestinationPosition,
1571 Basicvideo_GetVideoSize,
1572 Basicvideo_GetVideoPaletteEntries,
1573 Basicvideo_GetCurrentImage,
1574 Basicvideo_IsUsingDefaultSource,
1575 Basicvideo_IsUsingDefaultDestination
1579 /*** IUnknown methods ***/
1580 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1581 REFIID riid,
1582 LPVOID*ppvObj) {
1583 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1585 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1587 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1590 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1591 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1593 TRACE("(%p/%p)->()\n", This, iface);
1595 return VideoRenderer_AddRef((IBaseFilter*)This);
1598 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1599 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1601 TRACE("(%p/%p)->()\n", This, iface);
1603 return VideoRenderer_Release((IBaseFilter*)This);
1606 /*** IDispatch methods ***/
1607 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1608 UINT*pctinfo) {
1609 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1611 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1613 return S_OK;
1616 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1617 UINT iTInfo,
1618 LCID lcid,
1619 ITypeInfo**ppTInfo) {
1620 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1622 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1624 return S_OK;
1627 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1628 REFIID riid,
1629 LPOLESTR*rgszNames,
1630 UINT cNames,
1631 LCID lcid,
1632 DISPID*rgDispId) {
1633 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1635 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1637 return S_OK;
1640 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1641 DISPID dispIdMember,
1642 REFIID riid,
1643 LCID lcid,
1644 WORD wFlags,
1645 DISPPARAMS*pDispParams,
1646 VARIANT*pVarResult,
1647 EXCEPINFO*pExepInfo,
1648 UINT*puArgErr) {
1649 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1651 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);
1653 return S_OK;
1656 /*** IVideoWindow methods ***/
1657 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1658 BSTR strCaption) {
1659 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1661 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1663 if (!SetWindowTextW(This->hWnd, strCaption))
1664 return E_FAIL;
1666 return S_OK;
1669 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1670 BSTR *strCaption) {
1671 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1673 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1675 GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1677 return S_OK;
1680 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1681 LONG WindowStyle) {
1682 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1683 LONG old;
1685 old = GetWindowLongA(This->hWnd, GWL_STYLE);
1687 TRACE("(%p/%p)->(%x -> %x)\n", This, iface, old, WindowStyle);
1689 if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1690 return E_INVALIDARG;
1692 SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1693 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1694 This->WindowStyle = WindowStyle;
1696 return S_OK;
1699 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1700 LONG *WindowStyle) {
1701 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1703 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1705 *WindowStyle = This->WindowStyle;
1707 return S_OK;
1710 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1711 LONG WindowStyleEx) {
1712 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1714 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
1716 if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1717 return E_FAIL;
1719 return S_OK;
1722 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1723 LONG *WindowStyleEx) {
1724 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1726 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1728 *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1730 return S_OK;
1733 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1734 LONG AutoShow) {
1735 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1737 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
1739 This->AutoShow = AutoShow;
1741 return S_OK;
1744 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1745 LONG *AutoShow) {
1746 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1748 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1750 *AutoShow = This->AutoShow;
1752 return S_OK;
1755 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1756 LONG WindowState) {
1757 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1759 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
1760 ShowWindow(This->hWnd, WindowState);
1761 return S_OK;
1764 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1765 LONG *WindowState) {
1766 WINDOWPLACEMENT place;
1767 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1769 place.length = sizeof(place);
1770 GetWindowPlacement(This->hWnd, &place);
1771 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
1772 *WindowState = place.showCmd;
1774 return S_OK;
1777 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1778 LONG BackgroundPalette) {
1779 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1781 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, BackgroundPalette);
1783 return S_OK;
1786 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1787 LONG *pBackgroundPalette) {
1788 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1790 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1792 return S_OK;
1795 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1796 LONG Visible) {
1797 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1799 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
1801 ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1803 return S_OK;
1806 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1807 LONG *pVisible) {
1808 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1810 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1812 *pVisible = IsWindowVisible(This->hWnd);
1814 return S_OK;
1817 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1818 LONG Left) {
1819 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1821 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
1823 if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1824 return E_FAIL;
1826 This->WindowPos.left = Left;
1828 return S_OK;
1831 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1832 LONG *pLeft) {
1833 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1835 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1837 *pLeft = This->WindowPos.left;
1839 return S_OK;
1842 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1843 LONG Width) {
1844 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1846 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
1848 if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1849 return E_FAIL;
1851 This->WindowPos.right = This->WindowPos.left + Width;
1853 return S_OK;
1856 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1857 LONG *pWidth) {
1858 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1860 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1862 *pWidth = This->WindowPos.right - This->WindowPos.left;
1864 return S_OK;
1867 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1868 LONG Top) {
1869 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1871 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
1873 if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1874 return E_FAIL;
1876 This->WindowPos.top = Top;
1878 return S_OK;
1881 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1882 LONG *pTop) {
1883 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1885 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1887 *pTop = This->WindowPos.top;
1889 return S_OK;
1892 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1893 LONG Height) {
1894 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1896 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
1898 if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1899 return E_FAIL;
1901 This->WindowPos.bottom = This->WindowPos.top + Height;
1903 return S_OK;
1906 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1907 LONG *pHeight) {
1908 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1910 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1912 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1914 return S_OK;
1917 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1918 OAHWND Owner) {
1919 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1921 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1923 SetParent(This->hWnd, (HWND)Owner);
1924 if (This->WindowStyle & WS_CHILD)
1926 LONG old = GetWindowLongA(This->hWnd, GWL_STYLE);
1927 if (old != This->WindowStyle)
1929 SetWindowLongA(This->hWnd, GWL_STYLE, This->WindowStyle);
1930 SetWindowPos(This->hWnd,0,0,0,0,0,SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOZORDER);
1934 return S_OK;
1937 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
1938 OAHWND *Owner) {
1939 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1941 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
1943 *(HWND*)Owner = GetParent(This->hWnd);
1945 return S_OK;
1948 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
1949 OAHWND Drain) {
1950 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1952 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
1954 This->hWndMsgDrain = (HWND)Drain;
1956 return S_OK;
1959 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
1960 OAHWND *Drain) {
1961 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1963 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
1965 *Drain = (OAHWND)This->hWndMsgDrain;
1967 return S_OK;
1970 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
1971 LONG *Color) {
1972 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1974 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
1976 return S_OK;
1979 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
1980 LONG Color) {
1981 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1983 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, Color);
1985 return S_OK;
1988 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
1989 LONG *FullScreenMode) {
1990 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1992 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
1994 return S_OK;
1997 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
1998 LONG FullScreenMode) {
1999 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2001 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, FullScreenMode);
2003 return S_OK;
2006 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2007 LONG Focus) {
2008 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2009 BOOL ret;
2010 IPin* pPin;
2011 HRESULT hr;
2013 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
2015 if ((Focus != FALSE) && (Focus != TRUE))
2016 return E_INVALIDARG;
2018 hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2019 if ((hr != S_OK) || !pPin)
2020 return VFW_E_NOT_CONNECTED;
2022 if (Focus)
2023 ret = SetForegroundWindow(This->hWnd);
2024 else
2025 ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2027 if (!ret)
2028 return E_FAIL;
2030 return S_OK;
2033 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2034 OAHWND hwnd,
2035 LONG uMsg,
2036 LONG_PTR wParam,
2037 LONG_PTR lParam) {
2038 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2040 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
2042 if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
2043 return E_FAIL;
2045 return S_OK;
2048 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2049 LONG Left,
2050 LONG Top,
2051 LONG Width,
2052 LONG Height) {
2053 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2055 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
2057 if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2058 return E_FAIL;
2060 This->WindowPos.left = Left;
2061 This->WindowPos.top = Top;
2062 This->WindowPos.right = Left + Width;
2063 This->WindowPos.bottom = Top + Height;
2065 return S_OK;
2068 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2069 LONG *pLeft,
2070 LONG *pTop,
2071 LONG *pWidth,
2072 LONG *pHeight) {
2073 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2075 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2077 *pLeft = This->WindowPos.left;
2078 *pTop = This->WindowPos.top;
2079 *pWidth = This->WindowPos.right - This->WindowPos.left;
2080 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2082 return S_OK;
2085 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2086 LONG *pWidth,
2087 LONG *pHeight) {
2088 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2090 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2092 *pWidth = This->VideoWidth;
2093 *pHeight = This->VideoHeight;
2095 return S_OK;
2098 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2099 LONG *pWidth,
2100 LONG *pHeight) {
2101 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2103 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2105 *pWidth = This->VideoWidth;
2106 *pHeight = This->VideoHeight;
2108 return S_OK;
2111 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2112 LONG *pLeft,
2113 LONG *pTop,
2114 LONG *pWidth,
2115 LONG *pHeight) {
2116 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2118 FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2120 return S_OK;
2123 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2124 LONG HideCursor) {
2125 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2127 FIXME("(%p/%p)->(%d): stub !!!\n", This, iface, HideCursor);
2129 return S_OK;
2132 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2133 LONG *CursorHidden) {
2134 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2136 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2138 return S_OK;
2141 static const IVideoWindowVtbl IVideoWindow_VTable =
2143 Videowindow_QueryInterface,
2144 Videowindow_AddRef,
2145 Videowindow_Release,
2146 Videowindow_GetTypeInfoCount,
2147 Videowindow_GetTypeInfo,
2148 Videowindow_GetIDsOfNames,
2149 Videowindow_Invoke,
2150 Videowindow_put_Caption,
2151 Videowindow_get_Caption,
2152 Videowindow_put_WindowStyle,
2153 Videowindow_get_WindowStyle,
2154 Videowindow_put_WindowStyleEx,
2155 Videowindow_get_WindowStyleEx,
2156 Videowindow_put_AutoShow,
2157 Videowindow_get_AutoShow,
2158 Videowindow_put_WindowState,
2159 Videowindow_get_WindowState,
2160 Videowindow_put_BackgroundPalette,
2161 Videowindow_get_BackgroundPalette,
2162 Videowindow_put_Visible,
2163 Videowindow_get_Visible,
2164 Videowindow_put_Left,
2165 Videowindow_get_Left,
2166 Videowindow_put_Width,
2167 Videowindow_get_Width,
2168 Videowindow_put_Top,
2169 Videowindow_get_Top,
2170 Videowindow_put_Height,
2171 Videowindow_get_Height,
2172 Videowindow_put_Owner,
2173 Videowindow_get_Owner,
2174 Videowindow_put_MessageDrain,
2175 Videowindow_get_MessageDrain,
2176 Videowindow_get_BorderColor,
2177 Videowindow_put_BorderColor,
2178 Videowindow_get_FullScreenMode,
2179 Videowindow_put_FullScreenMode,
2180 Videowindow_SetWindowForeground,
2181 Videowindow_NotifyOwnerMessage,
2182 Videowindow_SetWindowPosition,
2183 Videowindow_GetWindowPosition,
2184 Videowindow_GetMinIdealImageSize,
2185 Videowindow_GetMaxIdealImageSize,
2186 Videowindow_GetRestorePosition,
2187 Videowindow_HideCursor,
2188 Videowindow_IsCursorHidden
2191 static VideoRendererImpl *from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface) {
2192 return (VideoRendererImpl*)((char*)iface - offsetof(VideoRendererImpl, IAMFilterMiscFlags_vtbl));
2195 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, const REFIID riid, void **ppv) {
2196 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2197 return IUnknown_QueryInterface((IUnknown*)This, riid, ppv);
2200 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface) {
2201 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2202 return IUnknown_AddRef((IUnknown*)This);
2205 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface) {
2206 VideoRendererImpl *This = from_IAMFilterMiscFlags(iface);
2207 return IUnknown_Release((IUnknown*)This);
2210 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface) {
2211 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
2214 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
2215 AMFilterMiscFlags_QueryInterface,
2216 AMFilterMiscFlags_AddRef,
2217 AMFilterMiscFlags_Release,
2218 AMFilterMiscFlags_GetMiscFlags