quartz: Fix some traces and fixmes.
[wine/hacks.git] / dlls / quartz / videorenderer.c
blob0d9896e5618f9a1da61ccff2e62ab4e33b994d76
1 /*
2 * Video Renderer (Fullscreen and Windowed using Direct Draw)
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
25 #include "quartz_private.h"
26 #include "control_private.h"
27 #include "pin.h"
29 #include "uuids.h"
30 #include "vfwmsgs.h"
31 #include "amvideo.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "dshow.h"
35 #include "evcode.h"
36 #include "strmif.h"
37 #include "ddraw.h"
38 #include "dvdmedia.h"
40 #include <assert.h>
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
46 static BOOL wnd_class_registered = FALSE;
48 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
50 static const IBaseFilterVtbl VideoRenderer_Vtbl;
51 static const IUnknownVtbl IInner_VTable;
52 static const IBasicVideoVtbl IBasicVideo_VTable;
53 static const IVideoWindowVtbl IVideoWindow_VTable;
54 static const IPinVtbl VideoRenderer_InputPin_Vtbl;
56 typedef struct VideoRendererImpl
58 const IBaseFilterVtbl * lpVtbl;
59 const IBasicVideoVtbl * IBasicVideo_vtbl;
60 const IVideoWindowVtbl * IVideoWindow_vtbl;
61 const IUnknownVtbl * IInner_vtbl;
63 LONG refCount;
64 CRITICAL_SECTION csFilter;
65 FILTER_STATE state;
66 REFERENCE_TIME rtStreamStart;
67 IReferenceClock * pClock;
68 FILTER_INFO filterInfo;
70 InputPin *pInputPin;
72 BOOL init;
73 HANDLE hThread;
74 HANDLE blocked;
76 DWORD ThreadID;
77 HANDLE hEvent;
78 BOOL ThreadResult;
79 HWND hWnd;
80 HWND hWndMsgDrain;
81 BOOL AutoShow;
82 RECT SourceRect;
83 RECT DestRect;
84 RECT WindowPos;
85 long VideoWidth;
86 long VideoHeight;
87 IUnknown * pUnkOuter;
88 BOOL bUnkOuterValid;
89 BOOL bAggregatable;
90 REFERENCE_TIME rtLastStop;
91 MediaSeekingImpl mediaSeeking;
93 /* During pause we can hold a single sample, for use in GetCurrentImage */
94 IMediaSample *sample_held;
95 } VideoRendererImpl;
97 static LRESULT CALLBACK VideoWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
99 VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongA(hwnd, 0);
100 LPRECT lprect = (LPRECT)lParam;
102 if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
104 switch(uMsg)
106 case WM_KEYDOWN:
107 case WM_KEYUP:
108 case WM_LBUTTONDBLCLK:
109 case WM_LBUTTONDOWN:
110 case WM_LBUTTONUP:
111 case WM_MBUTTONDBLCLK:
112 case WM_MBUTTONDOWN:
113 case WM_MBUTTONUP:
114 case WM_MOUSEACTIVATE:
115 case WM_MOUSEMOVE:
116 case WM_NCLBUTTONDBLCLK:
117 case WM_NCLBUTTONDOWN:
118 case WM_NCLBUTTONUP:
119 case WM_NCMBUTTONDBLCLK:
120 case WM_NCMBUTTONDOWN:
121 case WM_NCMBUTTONUP:
122 case WM_NCMOUSEMOVE:
123 case WM_NCRBUTTONDBLCLK:
124 case WM_NCRBUTTONDOWN:
125 case WM_NCRBUTTONUP:
126 case WM_RBUTTONDBLCLK:
127 case WM_RBUTTONDOWN:
128 case WM_RBUTTONUP:
129 PostMessageA(pVideoRenderer->hWndMsgDrain, uMsg, wParam, lParam);
130 break;
131 default:
132 break;
136 switch(uMsg)
138 case WM_SIZING:
139 /* TRACE("WM_SIZING %d %d %d %d\n", lprect->left, lprect->top, lprect->right, lprect->bottom); */
140 SetWindowPos(hwnd, NULL, lprect->left, lprect->top, lprect->right - lprect->left, lprect->bottom - lprect->top, SWP_NOZORDER);
141 GetClientRect(hwnd, &pVideoRenderer->DestRect);
142 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
143 pVideoRenderer->DestRect.left,
144 pVideoRenderer->DestRect.top,
145 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
146 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
147 return TRUE;
148 case WM_SIZE:
149 TRACE("WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
150 GetClientRect(hwnd, &pVideoRenderer->DestRect);
151 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
152 pVideoRenderer->DestRect.left,
153 pVideoRenderer->DestRect.top,
154 pVideoRenderer->DestRect.right - pVideoRenderer->DestRect.left,
155 pVideoRenderer->DestRect.bottom - pVideoRenderer->DestRect.top);
156 return TRUE;
157 default:
158 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
160 return 0;
163 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
165 WNDCLASSA winclass;
167 TRACE("(%p)->()\n", This);
169 winclass.style = 0;
170 winclass.lpfnWndProc = VideoWndProcA;
171 winclass.cbClsExtra = 0;
172 winclass.cbWndExtra = sizeof(VideoRendererImpl*);
173 winclass.hInstance = NULL;
174 winclass.hIcon = NULL;
175 winclass.hCursor = NULL;
176 winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
177 winclass.lpszMenuName = NULL;
178 winclass.lpszClassName = "Wine ActiveMovie Class";
180 if (!wnd_class_registered)
182 if (!RegisterClassA(&winclass))
184 ERR("Unable to register window %u\n", GetLastError());
185 return FALSE;
187 wnd_class_registered = TRUE;
190 This->hWnd = CreateWindowExA(0, "Wine ActiveMovie Class", "Wine ActiveMovie Window", WS_SIZEBOX,
191 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
192 NULL, NULL, NULL);
194 if (!This->hWnd)
196 ERR("Unable to create window\n");
197 return FALSE;
200 SetWindowLongA(This->hWnd, 0, (LONG)This);
202 return TRUE;
205 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
207 VideoRendererImpl* This = (VideoRendererImpl*) lpParameter;
208 MSG msg;
209 BOOL fGotMessage;
211 TRACE("Starting message loop\n");
213 if (!CreateRenderingWindow(This))
215 This->ThreadResult = FALSE;
216 SetEvent(This->hEvent);
217 return 0;
220 This->ThreadResult = TRUE;
221 SetEvent(This->hEvent);
223 while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
225 TranslateMessage(&msg);
226 DispatchMessageA(&msg);
229 TRACE("End of message loop\n");
231 return msg.wParam;
234 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
236 This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
237 if (!This->hEvent)
238 return FALSE;
240 This->hThread = CreateThread(NULL, 0, MessageLoop, (LPVOID)This, 0, &This->ThreadID);
241 if (!This->hThread)
243 CloseHandle(This->hEvent);
244 return FALSE;
247 WaitForSingleObject(This->hEvent, INFINITE);
249 if (!This->ThreadResult)
251 CloseHandle(This->hEvent);
252 CloseHandle(This->hThread);
253 return FALSE;
256 return TRUE;
259 static const IMemInputPinVtbl MemInputPin_Vtbl =
261 MemInputPin_QueryInterface,
262 MemInputPin_AddRef,
263 MemInputPin_Release,
264 MemInputPin_GetAllocator,
265 MemInputPin_NotifyAllocator,
266 MemInputPin_GetAllocatorRequirements,
267 MemInputPin_Receive,
268 MemInputPin_ReceiveMultiple,
269 MemInputPin_ReceiveCanBlock
272 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
274 AM_MEDIA_TYPE amt;
275 HRESULT hr = S_OK;
276 DDSURFACEDESC sdesc;
277 HDC hDC;
278 BITMAPINFOHEADER *bmiHeader;
280 TRACE("(%p)->(%p, %d)\n", This, data, size);
282 sdesc.dwSize = sizeof(sdesc);
283 hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
284 if (FAILED(hr)) {
285 ERR("Unable to retrieve media type\n");
286 return hr;
289 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
291 bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
293 else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
295 bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
297 else
299 FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
300 return VFW_E_RUNTIME_ERROR;
304 TRACE("biSize = %d\n", bmiHeader->biSize);
305 TRACE("biWidth = %d\n", bmiHeader->biWidth);
306 TRACE("biHeight = %d\n", bmiHeader->biHeight);
307 TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
308 TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
309 TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
310 TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
312 if (!This->init)
314 if (!This->WindowPos.right || !This->WindowPos.bottom)
315 This->WindowPos = This->SourceRect;
317 TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
318 SetWindowPos(This->hWnd, NULL,
319 This->WindowPos.left,
320 This->WindowPos.top,
321 This->WindowPos.right - This->WindowPos.left,
322 This->WindowPos.bottom - This->WindowPos.top,
323 SWP_NOZORDER|SWP_NOMOVE);
325 GetClientRect(This->hWnd, &This->DestRect);
326 This->init = TRUE;
329 hDC = GetDC(This->hWnd);
331 if (!hDC) {
332 ERR("Cannot get DC from window!\n");
333 return E_FAIL;
336 TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
337 TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
339 StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
340 This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
341 This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
342 data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
344 ReleaseDC(This->hWnd, hDC);
345 if (This->AutoShow)
346 ShowWindow(This->hWnd, SW_SHOW);
348 return S_OK;
351 static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
353 VideoRendererImpl *This = (VideoRendererImpl *)iface;
354 LPBYTE pbSrcStream = NULL;
355 long cbSrcStream = 0;
356 REFERENCE_TIME tStart, tStop;
357 HRESULT hr;
359 TRACE("(%p)->(%p)\n", iface, pSample);
361 EnterCriticalSection(&This->csFilter);
363 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
365 LeaveCriticalSection(&This->csFilter);
366 return S_FALSE;
369 if (This->state == State_Stopped)
371 LeaveCriticalSection(&This->csFilter);
372 return VFW_E_WRONG_STATE;
375 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
376 if (FAILED(hr))
377 ERR("Cannot get sample time (%x)\n", hr);
379 if (This->rtLastStop != tStart)
381 if (IMediaSample_IsDiscontinuity(pSample) == S_FALSE)
382 ERR("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
383 (DWORD)(This->rtLastStop / 10000000),
384 (DWORD)((This->rtLastStop / 10000)%1000),
385 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
386 This->rtLastStop = tStart;
389 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
390 if (IMediaSample_IsPreroll(pSample) == S_OK)
392 This->rtLastStop = tStop;
393 LeaveCriticalSection(&This->csFilter);
394 return S_OK;
397 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
398 if (FAILED(hr))
400 ERR("Cannot get pointer to sample data (%x)\n", hr);
401 LeaveCriticalSection(&This->csFilter);
402 return hr;
405 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
407 TRACE("val %p %ld\n", pbSrcStream, cbSrcStream);
409 #if 0 /* For debugging purpose */
411 int i;
412 for(i = 0; i < cbSrcStream; i++)
414 if ((i!=0) && !(i%16))
415 TRACE("\n");
416 TRACE("%02x ", pbSrcStream[i]);
418 TRACE("\n");
420 #endif
422 SetEvent(This->hEvent);
423 if (This->state == State_Paused)
425 This->sample_held = pSample;
426 LeaveCriticalSection(&This->csFilter);
427 WaitForSingleObject(This->blocked, INFINITE);
428 EnterCriticalSection(&This->csFilter);
429 This->sample_held = NULL;
430 if (This->state == State_Paused)
432 /* Flushing */
433 LeaveCriticalSection(&This->csFilter);
434 return S_OK;
436 if (This->state == State_Stopped)
438 LeaveCriticalSection(&This->csFilter);
439 return VFW_E_WRONG_STATE;
443 if (This->pClock && This->state == State_Running)
445 REFERENCE_TIME time, trefstart, trefstop;
446 LONG delta;
448 /* Perhaps I <SHOULD> use the reference clock AdviseTime function here
449 * I'm not going to! When I tried, it seemed to generate lag and
450 * it caused instability.
452 IReferenceClock_GetTime(This->pClock, &time);
454 trefstart = This->rtStreamStart;
455 trefstop = (REFERENCE_TIME)((double)(tStop - tStart) / This->pInputPin->dRate) + This->rtStreamStart;
456 delta = (LONG)((trefstart-time)/10000);
457 This->rtStreamStart = trefstop;
458 This->rtLastStop = tStop;
460 if (delta > 0)
462 TRACE("Sleeping for %u ms\n", delta);
463 Sleep(delta);
465 else if (time > trefstop)
467 TRACE("Dropping sample: Time: %u.%03u ms trefstop: %u.%03u ms!\n",
468 (DWORD)(time / 10000000), (DWORD)((time / 10000)%1000),
469 (DWORD)(trefstop / 10000000), (DWORD)((trefstop / 10000)%1000) );
470 This->rtLastStop = tStop;
471 LeaveCriticalSection(&This->csFilter);
472 return S_OK;
475 This->rtLastStop = tStop;
477 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
479 LeaveCriticalSection(&This->csFilter);
480 return S_OK;
483 static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
485 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
486 return S_FALSE;
488 if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
489 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
490 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
491 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
493 VideoRendererImpl* This = (VideoRendererImpl*) iface;
495 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
497 VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
498 This->SourceRect.left = 0;
499 This->SourceRect.top = 0;
500 This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
501 This->SourceRect.bottom = This->VideoHeight = format->bmiHeader.biHeight;
503 else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
505 VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
507 This->SourceRect.left = 0;
508 This->SourceRect.top = 0;
509 This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
510 This->SourceRect.bottom = This->VideoHeight = format2->bmiHeader.biHeight;
512 else
514 WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
515 return S_FALSE;
517 return S_OK;
519 return S_FALSE;
522 static inline VideoRendererImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
524 return (VideoRendererImpl *)((char*)iface - FIELD_OFFSET(VideoRendererImpl, mediaSeeking.lpVtbl));
527 static HRESULT WINAPI VideoRendererImpl_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
529 VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
531 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
534 static ULONG WINAPI VideoRendererImpl_Seeking_AddRef(IMediaSeeking * iface)
536 VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
538 return IUnknown_AddRef((IUnknown *)This);
541 static ULONG WINAPI VideoRendererImpl_Seeking_Release(IMediaSeeking * iface)
543 VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
545 return IUnknown_Release((IUnknown *)This);
548 static const IMediaSeekingVtbl VideoRendererImpl_Seeking_Vtbl =
550 VideoRendererImpl_Seeking_QueryInterface,
551 VideoRendererImpl_Seeking_AddRef,
552 VideoRendererImpl_Seeking_Release,
553 MediaSeekingImpl_GetCapabilities,
554 MediaSeekingImpl_CheckCapabilities,
555 MediaSeekingImpl_IsFormatSupported,
556 MediaSeekingImpl_QueryPreferredFormat,
557 MediaSeekingImpl_GetTimeFormat,
558 MediaSeekingImpl_IsUsingTimeFormat,
559 MediaSeekingImpl_SetTimeFormat,
560 MediaSeekingImpl_GetDuration,
561 MediaSeekingImpl_GetStopPosition,
562 MediaSeekingImpl_GetCurrentPosition,
563 MediaSeekingImpl_ConvertTimeFormat,
564 MediaSeekingImpl_SetPositions,
565 MediaSeekingImpl_GetPositions,
566 MediaSeekingImpl_GetAvailable,
567 MediaSeekingImpl_SetRate,
568 MediaSeekingImpl_GetRate,
569 MediaSeekingImpl_GetPreroll
572 static HRESULT VideoRendererImpl_Change(IBaseFilter *iface)
574 TRACE("(%p)->()\n", iface);
575 return S_OK;
578 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
580 HRESULT hr;
581 PIN_INFO piInput;
582 VideoRendererImpl * pVideoRenderer;
584 TRACE("(%p, %p)\n", pUnkOuter, ppv);
586 *ppv = NULL;
588 pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
589 pVideoRenderer->pUnkOuter = pUnkOuter;
590 pVideoRenderer->bUnkOuterValid = FALSE;
591 pVideoRenderer->bAggregatable = FALSE;
592 pVideoRenderer->IInner_vtbl = &IInner_VTable;
594 pVideoRenderer->lpVtbl = &VideoRenderer_Vtbl;
595 pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
596 pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
598 pVideoRenderer->refCount = 1;
599 InitializeCriticalSection(&pVideoRenderer->csFilter);
600 pVideoRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter");
601 pVideoRenderer->state = State_Stopped;
602 pVideoRenderer->pClock = NULL;
603 pVideoRenderer->init = 0;
604 pVideoRenderer->AutoShow = 1;
605 pVideoRenderer->rtLastStop = -1;
606 ZeroMemory(&pVideoRenderer->filterInfo, sizeof(FILTER_INFO));
607 ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
608 ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
609 ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
610 pVideoRenderer->hWndMsgDrain = NULL;
612 /* construct input pin */
613 piInput.dir = PINDIR_INPUT;
614 piInput.pFilter = (IBaseFilter *)pVideoRenderer;
615 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
617 hr = InputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, VideoRenderer_Sample, (LPVOID)pVideoRenderer, VideoRenderer_QueryAccept, NULL, &pVideoRenderer->csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
619 if (SUCCEEDED(hr))
621 MediaSeekingImpl_Init((IBaseFilter*)pVideoRenderer, VideoRendererImpl_Change, VideoRendererImpl_Change, VideoRendererImpl_Change, &pVideoRenderer->mediaSeeking, &pVideoRenderer->csFilter);
622 pVideoRenderer->mediaSeeking.lpVtbl = &VideoRendererImpl_Seeking_Vtbl;
624 pVideoRenderer->sample_held = NULL;
625 *ppv = (LPVOID)pVideoRenderer;
627 else
629 pVideoRenderer->csFilter.DebugInfo->Spare[0] = 0;
630 DeleteCriticalSection(&pVideoRenderer->csFilter);
631 CoTaskMemFree(pVideoRenderer);
634 if (!CreateRenderingSubsystem(pVideoRenderer))
635 return E_FAIL;
637 pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
638 if (!pVideoRenderer->blocked)
640 hr = HRESULT_FROM_WIN32(GetLastError());
641 IUnknown_Release((IUnknown *)pVideoRenderer);
644 return hr;
647 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
649 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
650 return VideoRenderer_create(pUnkOuter, ppv);
653 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
655 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
656 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
658 if (This->bAggregatable)
659 This->bUnkOuterValid = TRUE;
661 *ppv = NULL;
663 if (IsEqualIID(riid, &IID_IUnknown))
664 *ppv = (LPVOID)&(This->IInner_vtbl);
665 else if (IsEqualIID(riid, &IID_IPersist))
666 *ppv = (LPVOID)This;
667 else if (IsEqualIID(riid, &IID_IMediaFilter))
668 *ppv = (LPVOID)This;
669 else if (IsEqualIID(riid, &IID_IBaseFilter))
670 *ppv = (LPVOID)This;
671 else if (IsEqualIID(riid, &IID_IBasicVideo))
672 *ppv = (LPVOID)&(This->IBasicVideo_vtbl);
673 else if (IsEqualIID(riid, &IID_IVideoWindow))
674 *ppv = (LPVOID)&(This->IVideoWindow_vtbl);
675 else if (IsEqualIID(riid, &IID_IMediaSeeking))
676 *ppv = &This->mediaSeeking;
678 if (*ppv)
680 IUnknown_AddRef((IUnknown *)(*ppv));
681 return S_OK;
684 if (!IsEqualIID(riid, &IID_IPin))
685 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
687 return E_NOINTERFACE;
690 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
692 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
693 ULONG refCount = InterlockedIncrement(&This->refCount);
695 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
697 return refCount;
700 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
702 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
703 ULONG refCount = InterlockedDecrement(&This->refCount);
705 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
707 if (!refCount)
709 IPin *pConnectedTo;
711 DestroyWindow(This->hWnd);
712 PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
713 WaitForSingleObject(This->hThread, INFINITE);
714 CloseHandle(This->hThread);
715 CloseHandle(This->hEvent);
717 if (This->pClock)
718 IReferenceClock_Release(This->pClock);
720 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
722 IPin_Disconnect(pConnectedTo);
723 IPin_Release(pConnectedTo);
725 IPin_Disconnect((IPin *)This->pInputPin);
727 IPin_Release((IPin *)This->pInputPin);
729 This->lpVtbl = NULL;
731 This->csFilter.DebugInfo->Spare[0] = 0;
732 DeleteCriticalSection(&This->csFilter);
734 TRACE("Destroying Video Renderer\n");
735 CoTaskMemFree(This);
737 return 0;
739 else
740 return refCount;
743 static const IUnknownVtbl IInner_VTable =
745 VideoRendererInner_QueryInterface,
746 VideoRendererInner_AddRef,
747 VideoRendererInner_Release
750 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
752 VideoRendererImpl *This = (VideoRendererImpl *)iface;
754 if (This->bAggregatable)
755 This->bUnkOuterValid = TRUE;
757 if (This->pUnkOuter)
759 if (This->bAggregatable)
760 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
762 if (IsEqualIID(riid, &IID_IUnknown))
764 HRESULT hr;
766 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
767 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
768 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
769 This->bAggregatable = TRUE;
770 return hr;
773 *ppv = NULL;
774 return E_NOINTERFACE;
777 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
780 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
782 VideoRendererImpl *This = (VideoRendererImpl *)iface;
784 if (This->pUnkOuter && This->bUnkOuterValid)
785 return IUnknown_AddRef(This->pUnkOuter);
786 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
789 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
791 VideoRendererImpl *This = (VideoRendererImpl *)iface;
793 if (This->pUnkOuter && This->bUnkOuterValid)
794 return IUnknown_Release(This->pUnkOuter);
795 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
798 /** IPersist methods **/
800 static HRESULT WINAPI VideoRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
802 VideoRendererImpl *This = (VideoRendererImpl *)iface;
804 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
806 *pClsid = CLSID_VideoRenderer;
808 return S_OK;
811 /** IMediaFilter methods **/
813 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
815 VideoRendererImpl *This = (VideoRendererImpl *)iface;
817 TRACE("(%p/%p)->()\n", This, iface);
819 EnterCriticalSection(&This->csFilter);
821 This->state = State_Stopped;
822 SetEvent(This->hEvent);
823 SetEvent(This->blocked);
825 LeaveCriticalSection(&This->csFilter);
827 return S_OK;
830 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
832 VideoRendererImpl *This = (VideoRendererImpl *)iface;
834 TRACE("(%p/%p)->()\n", This, iface);
836 EnterCriticalSection(&This->csFilter);
837 if (This->state != State_Paused)
839 if (This->state == State_Stopped)
841 This->pInputPin->end_of_stream = 0;
842 ResetEvent(This->hEvent);
845 This->state = State_Paused;
846 ResetEvent(This->blocked);
848 LeaveCriticalSection(&This->csFilter);
850 return S_OK;
853 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
855 VideoRendererImpl *This = (VideoRendererImpl *)iface;
857 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
859 EnterCriticalSection(&This->csFilter);
860 if (This->state != State_Running)
862 if (This->state == State_Stopped)
864 This->pInputPin->end_of_stream = 0;
865 ResetEvent(This->hEvent);
867 SetEvent(This->blocked);
869 This->rtStreamStart = tStart;
870 This->state = State_Running;
872 LeaveCriticalSection(&This->csFilter);
874 return S_OK;
877 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
879 VideoRendererImpl *This = (VideoRendererImpl *)iface;
880 HRESULT hr;
882 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
884 if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
885 hr = VFW_S_STATE_INTERMEDIATE;
886 else
887 hr = S_OK;
889 EnterCriticalSection(&This->csFilter);
891 *pState = This->state;
893 LeaveCriticalSection(&This->csFilter);
895 return hr;
898 static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
900 VideoRendererImpl *This = (VideoRendererImpl *)iface;
902 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
904 EnterCriticalSection(&This->csFilter);
906 if (This->pClock)
907 IReferenceClock_Release(This->pClock);
908 This->pClock = pClock;
909 if (This->pClock)
910 IReferenceClock_AddRef(This->pClock);
912 LeaveCriticalSection(&This->csFilter);
914 return S_OK;
917 static HRESULT WINAPI VideoRenderer_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
919 VideoRendererImpl *This = (VideoRendererImpl *)iface;
921 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
923 EnterCriticalSection(&This->csFilter);
925 *ppClock = This->pClock;
926 if (This->pClock)
927 IReferenceClock_AddRef(This->pClock);
929 LeaveCriticalSection(&This->csFilter);
931 return S_OK;
934 /** IBaseFilter implementation **/
936 static HRESULT VideoRenderer_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
938 VideoRendererImpl *This = (VideoRendererImpl *)iface;
940 /* Our pins are static, not changing so setting static tick count is ok */
941 *lastsynctick = 0;
943 if (pos >= 1)
944 return S_FALSE;
946 *pin = (IPin *)This->pInputPin;
947 IPin_AddRef(*pin);
948 return S_OK;
951 static HRESULT WINAPI VideoRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
953 VideoRendererImpl *This = (VideoRendererImpl *)iface;
955 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
957 return IEnumPinsImpl_Construct(ppEnum, VideoRenderer_GetPin, iface);
960 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
962 VideoRendererImpl *This = (VideoRendererImpl *)iface;
964 FIXME("(%p/%p)->(%p,%p): stub !!!\n", This, iface, debugstr_w(Id), ppPin);
966 /* FIXME: critical section */
968 return E_NOTIMPL;
971 static HRESULT WINAPI VideoRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
973 VideoRendererImpl *This = (VideoRendererImpl *)iface;
975 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
977 strcpyW(pInfo->achName, This->filterInfo.achName);
978 pInfo->pGraph = This->filterInfo.pGraph;
980 if (pInfo->pGraph)
981 IFilterGraph_AddRef(pInfo->pGraph);
983 return S_OK;
986 static HRESULT WINAPI VideoRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
988 VideoRendererImpl *This = (VideoRendererImpl *)iface;
990 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
992 EnterCriticalSection(&This->csFilter);
994 if (pName)
995 strcpyW(This->filterInfo.achName, pName);
996 else
997 *This->filterInfo.achName = '\0';
998 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
1000 LeaveCriticalSection(&This->csFilter);
1002 return S_OK;
1005 static HRESULT WINAPI VideoRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
1007 VideoRendererImpl *This = (VideoRendererImpl *)iface;
1008 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
1009 return E_NOTIMPL;
1012 static const IBaseFilterVtbl VideoRenderer_Vtbl =
1014 VideoRenderer_QueryInterface,
1015 VideoRenderer_AddRef,
1016 VideoRenderer_Release,
1017 VideoRenderer_GetClassID,
1018 VideoRenderer_Stop,
1019 VideoRenderer_Pause,
1020 VideoRenderer_Run,
1021 VideoRenderer_GetState,
1022 VideoRenderer_SetSyncSource,
1023 VideoRenderer_GetSyncSource,
1024 VideoRenderer_EnumPins,
1025 VideoRenderer_FindPin,
1026 VideoRenderer_QueryFilterInfo,
1027 VideoRenderer_JoinFilterGraph,
1028 VideoRenderer_QueryVendorInfo
1031 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
1033 InputPin* This = (InputPin*)iface;
1034 IMediaEventSink* pEventSink;
1035 HRESULT hr;
1037 TRACE("(%p/%p)->()\n", This, iface);
1039 hr = IFilterGraph_QueryInterface(((VideoRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
1040 if (SUCCEEDED(hr))
1042 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
1043 IMediaEventSink_Release(pEventSink);
1046 return hr;
1049 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
1051 InputPin* This = (InputPin*)iface;
1052 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1053 HRESULT hr;
1055 TRACE("(%p/%p)->()\n", This, iface);
1057 EnterCriticalSection(This->pin.pCritSec);
1058 if (pVideoRenderer->state == State_Paused)
1059 SetEvent(pVideoRenderer->blocked);
1061 hr = InputPin_BeginFlush(iface);
1062 LeaveCriticalSection(This->pin.pCritSec);
1064 return hr;
1067 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
1069 InputPin* This = (InputPin*)iface;
1070 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1071 HRESULT hr;
1073 TRACE("(%p/%p)->()\n", This, iface);
1075 EnterCriticalSection(This->pin.pCritSec);
1076 if (pVideoRenderer->state == State_Paused)
1077 ResetEvent(pVideoRenderer->blocked);
1079 hr = InputPin_EndFlush(iface);
1080 LeaveCriticalSection(This->pin.pCritSec);
1082 return hr;
1085 static const IPinVtbl VideoRenderer_InputPin_Vtbl =
1087 InputPin_QueryInterface,
1088 IPinImpl_AddRef,
1089 InputPin_Release,
1090 InputPin_Connect,
1091 InputPin_ReceiveConnection,
1092 IPinImpl_Disconnect,
1093 IPinImpl_ConnectedTo,
1094 IPinImpl_ConnectionMediaType,
1095 IPinImpl_QueryPinInfo,
1096 IPinImpl_QueryDirection,
1097 IPinImpl_QueryId,
1098 IPinImpl_QueryAccept,
1099 IPinImpl_EnumMediaTypes,
1100 IPinImpl_QueryInternalConnections,
1101 VideoRenderer_InputPin_EndOfStream,
1102 VideoRenderer_InputPin_BeginFlush,
1103 VideoRenderer_InputPin_EndFlush,
1104 InputPin_NewSegment
1107 /*** IUnknown methods ***/
1108 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
1109 REFIID riid,
1110 LPVOID*ppvObj) {
1111 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1113 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1115 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1118 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1119 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1121 TRACE("(%p/%p)->()\n", This, iface);
1123 return VideoRenderer_AddRef((IBaseFilter*)This);
1126 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1127 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1129 TRACE("(%p/%p)->()\n", This, iface);
1131 return VideoRenderer_Release((IBaseFilter*)This);
1134 /*** IDispatch methods ***/
1135 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1136 UINT*pctinfo) {
1137 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1139 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1141 return S_OK;
1144 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1145 UINT iTInfo,
1146 LCID lcid,
1147 ITypeInfo**ppTInfo) {
1148 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1150 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1152 return S_OK;
1155 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1156 REFIID riid,
1157 LPOLESTR*rgszNames,
1158 UINT cNames,
1159 LCID lcid,
1160 DISPID*rgDispId) {
1161 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1163 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1165 return S_OK;
1168 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1169 DISPID dispIdMember,
1170 REFIID riid,
1171 LCID lcid,
1172 WORD wFlags,
1173 DISPPARAMS*pDispParams,
1174 VARIANT*pVarResult,
1175 EXCEPINFO*pExepInfo,
1176 UINT*puArgErr) {
1177 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1179 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);
1181 return S_OK;
1184 /*** IBasicVideo methods ***/
1185 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1186 REFTIME *pAvgTimePerFrame) {
1187 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1189 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pAvgTimePerFrame);
1191 return S_OK;
1194 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1195 long *pBitRate) {
1196 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1198 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1200 return S_OK;
1203 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1204 long *pBitErrorRate) {
1205 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1207 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1209 return S_OK;
1212 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1213 long *pVideoWidth) {
1214 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1216 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1218 *pVideoWidth = This->VideoWidth;
1220 return S_OK;
1223 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1224 long *pVideoHeight) {
1225 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1227 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1229 *pVideoHeight = This->VideoHeight;
1231 return S_OK;
1234 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1235 long SourceLeft) {
1236 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1238 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceLeft);
1240 This->SourceRect.left = SourceLeft;
1242 return S_OK;
1245 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1246 long *pSourceLeft) {
1247 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1249 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1251 *pSourceLeft = This->SourceRect.left;
1253 return S_OK;
1256 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1257 long SourceWidth) {
1258 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1260 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceWidth);
1262 This->SourceRect.right = This->SourceRect.left + SourceWidth;
1264 return S_OK;
1267 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1268 long *pSourceWidth) {
1269 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1271 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1273 *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1275 return S_OK;
1278 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1279 long SourceTop) {
1280 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1282 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceTop);
1284 This->SourceRect.top = SourceTop;
1286 return S_OK;
1289 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1290 long *pSourceTop) {
1291 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1293 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1295 *pSourceTop = This->SourceRect.top;
1297 return S_OK;
1300 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1301 long SourceHeight) {
1302 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1304 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceHeight);
1306 This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1308 return S_OK;
1311 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1312 long *pSourceHeight) {
1313 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1315 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1317 *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1319 return S_OK;
1322 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1323 long DestinationLeft) {
1324 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1326 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationLeft);
1328 This->DestRect.left = DestinationLeft;
1330 return S_OK;
1333 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1334 long *pDestinationLeft) {
1335 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1337 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1339 *pDestinationLeft = This->DestRect.left;
1341 return S_OK;
1344 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1345 long DestinationWidth) {
1346 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1348 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationWidth);
1350 This->DestRect.right = This->DestRect.left + DestinationWidth;
1352 return S_OK;
1355 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1356 long *pDestinationWidth) {
1357 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1359 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1361 *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1363 return S_OK;
1366 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1367 long DestinationTop) {
1368 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1370 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationTop);
1372 This->DestRect.top = DestinationTop;
1374 return S_OK;
1377 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1378 long *pDestinationTop) {
1379 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1381 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1383 *pDestinationTop = This->DestRect.top;
1385 return S_OK;
1388 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1389 long DestinationHeight) {
1390 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1392 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationHeight);
1394 This->DestRect.right = This->DestRect.left + DestinationHeight;
1396 return S_OK;
1399 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1400 long *pDestinationHeight) {
1401 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1403 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1405 *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1407 return S_OK;
1410 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1411 long Left,
1412 long Top,
1413 long Width,
1414 long Height) {
1415 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1417 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
1419 This->SourceRect.left = Left;
1420 This->SourceRect.top = Top;
1421 This->SourceRect.right = Left + Width;
1422 This->SourceRect.bottom = Top + Height;
1424 return S_OK;
1427 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1428 long *pLeft,
1429 long *pTop,
1430 long *pWidth,
1431 long *pHeight) {
1432 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1434 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1436 *pLeft = This->SourceRect.left;
1437 *pTop = This->SourceRect.top;
1438 *pWidth = This->SourceRect.right - This->SourceRect.left;
1439 *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1441 return S_OK;
1444 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1445 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1447 TRACE("(%p/%p)->()\n", This, iface);
1449 This->SourceRect.left = 0;
1450 This->SourceRect.top = 0;
1451 This->SourceRect.right = This->VideoWidth;
1452 This->SourceRect.bottom = This->VideoHeight;
1454 return S_OK;
1457 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1458 long Left,
1459 long Top,
1460 long Width,
1461 long Height) {
1462 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1464 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
1466 This->DestRect.left = Left;
1467 This->DestRect.top = Top;
1468 This->DestRect.right = Left + Width;
1469 This->DestRect.bottom = Top + Height;
1471 return S_OK;
1474 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1475 long *pLeft,
1476 long *pTop,
1477 long *pWidth,
1478 long *pHeight) {
1479 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1481 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1483 *pLeft = This->DestRect.left;
1484 *pTop = This->DestRect.top;
1485 *pWidth = This->DestRect.right - This->DestRect.left;
1486 *pHeight = This->DestRect.bottom - This->DestRect.top;
1488 return S_OK;
1491 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1492 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1493 RECT rect;
1495 TRACE("(%p/%p)->()\n", This, iface);
1497 if (!GetClientRect(This->hWnd, &rect))
1498 return E_FAIL;
1500 This->SourceRect.left = 0;
1501 This->SourceRect.top = 0;
1502 This->SourceRect.right = rect.right;
1503 This->SourceRect.bottom = rect.bottom;
1505 return S_OK;
1508 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1509 long *pWidth,
1510 long *pHeight) {
1511 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1513 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1515 *pWidth = This->VideoWidth;
1516 *pHeight = This->VideoHeight;
1518 return S_OK;
1521 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1522 long StartIndex,
1523 long Entries,
1524 long *pRetrieved,
1525 long *pPalette) {
1526 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1528 FIXME("(%p/%p)->(%ld, %ld, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1530 return S_OK;
1533 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1534 long *pBufferSize,
1535 long *pDIBImage) {
1536 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1537 BITMAPINFOHEADER *bmiHeader;
1538 LONG needed_size;
1539 AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1540 char *ptr;
1542 FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1544 EnterCriticalSection(&This->csFilter);
1546 if (!This->sample_held)
1548 LeaveCriticalSection(&This->csFilter);
1549 return (This->state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1552 if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1554 bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1556 else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1558 bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1560 else
1562 FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1563 LeaveCriticalSection(&This->csFilter);
1564 return VFW_E_RUNTIME_ERROR;
1567 needed_size = bmiHeader->biSize;
1568 needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1570 if (!pDIBImage)
1572 *pBufferSize = needed_size;
1573 LeaveCriticalSection(&This->csFilter);
1574 return S_OK;
1577 if (needed_size < *pBufferSize)
1579 ERR("Buffer too small %u/%lu\n", needed_size, *pBufferSize);
1580 LeaveCriticalSection(&This->csFilter);
1581 return E_FAIL;
1583 *pBufferSize = needed_size;
1585 memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1586 IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1587 memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1589 LeaveCriticalSection(&This->csFilter);
1591 return S_OK;
1594 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1595 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1597 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1599 return S_OK;
1602 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1603 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1605 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1607 return S_OK;
1611 static const IBasicVideoVtbl IBasicVideo_VTable =
1613 Basicvideo_QueryInterface,
1614 Basicvideo_AddRef,
1615 Basicvideo_Release,
1616 Basicvideo_GetTypeInfoCount,
1617 Basicvideo_GetTypeInfo,
1618 Basicvideo_GetIDsOfNames,
1619 Basicvideo_Invoke,
1620 Basicvideo_get_AvgTimePerFrame,
1621 Basicvideo_get_BitRate,
1622 Basicvideo_get_BitErrorRate,
1623 Basicvideo_get_VideoWidth,
1624 Basicvideo_get_VideoHeight,
1625 Basicvideo_put_SourceLeft,
1626 Basicvideo_get_SourceLeft,
1627 Basicvideo_put_SourceWidth,
1628 Basicvideo_get_SourceWidth,
1629 Basicvideo_put_SourceTop,
1630 Basicvideo_get_SourceTop,
1631 Basicvideo_put_SourceHeight,
1632 Basicvideo_get_SourceHeight,
1633 Basicvideo_put_DestinationLeft,
1634 Basicvideo_get_DestinationLeft,
1635 Basicvideo_put_DestinationWidth,
1636 Basicvideo_get_DestinationWidth,
1637 Basicvideo_put_DestinationTop,
1638 Basicvideo_get_DestinationTop,
1639 Basicvideo_put_DestinationHeight,
1640 Basicvideo_get_DestinationHeight,
1641 Basicvideo_SetSourcePosition,
1642 Basicvideo_GetSourcePosition,
1643 Basicvideo_SetDefaultSourcePosition,
1644 Basicvideo_SetDestinationPosition,
1645 Basicvideo_GetDestinationPosition,
1646 Basicvideo_SetDefaultDestinationPosition,
1647 Basicvideo_GetVideoSize,
1648 Basicvideo_GetVideoPaletteEntries,
1649 Basicvideo_GetCurrentImage,
1650 Basicvideo_IsUsingDefaultSource,
1651 Basicvideo_IsUsingDefaultDestination
1655 /*** IUnknown methods ***/
1656 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1657 REFIID riid,
1658 LPVOID*ppvObj) {
1659 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1661 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1663 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1666 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1667 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1669 TRACE("(%p/%p)->()\n", This, iface);
1671 return VideoRenderer_AddRef((IBaseFilter*)This);
1674 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1675 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1677 TRACE("(%p/%p)->()\n", This, iface);
1679 return VideoRenderer_Release((IBaseFilter*)This);
1682 /*** IDispatch methods ***/
1683 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1684 UINT*pctinfo) {
1685 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1687 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1689 return S_OK;
1692 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1693 UINT iTInfo,
1694 LCID lcid,
1695 ITypeInfo**ppTInfo) {
1696 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1698 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1700 return S_OK;
1703 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1704 REFIID riid,
1705 LPOLESTR*rgszNames,
1706 UINT cNames,
1707 LCID lcid,
1708 DISPID*rgDispId) {
1709 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1711 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1713 return S_OK;
1716 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1717 DISPID dispIdMember,
1718 REFIID riid,
1719 LCID lcid,
1720 WORD wFlags,
1721 DISPPARAMS*pDispParams,
1722 VARIANT*pVarResult,
1723 EXCEPINFO*pExepInfo,
1724 UINT*puArgErr) {
1725 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1727 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);
1729 return S_OK;
1732 /*** IVideoWindow methods ***/
1733 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1734 BSTR strCaption) {
1735 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1737 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1739 if (!SetWindowTextW(This->hWnd, strCaption))
1740 return E_FAIL;
1742 return S_OK;
1745 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1746 BSTR *strCaption) {
1747 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1749 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1751 GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1753 return S_OK;
1756 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1757 long WindowStyle) {
1758 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1759 LONG old;
1761 old = GetWindowLongA(This->hWnd, GWL_STYLE);
1763 TRACE("(%p/%p)->(%x -> %lx)\n", This, iface, old, WindowStyle);
1765 if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1766 return E_INVALIDARG;
1768 SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1770 return S_OK;
1773 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1774 long *WindowStyle) {
1775 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1777 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1779 *WindowStyle = GetWindowLongA(This->hWnd, GWL_STYLE);
1781 return S_OK;
1784 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1785 long WindowStyleEx) {
1786 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1788 TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyleEx);
1790 if (WindowStyleEx & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1791 return E_INVALIDARG;
1793 if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1794 return E_FAIL;
1796 return S_OK;
1799 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1800 long *WindowStyleEx) {
1801 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1803 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1805 *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1807 return S_OK;
1810 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1811 long AutoShow) {
1812 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1814 TRACE("(%p/%p)->(%ld)\n", This, iface, AutoShow);
1816 This->AutoShow = 1; /* FIXME: Should be AutoShow */;
1818 return S_OK;
1821 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1822 long *AutoShow) {
1823 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1825 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1827 *AutoShow = This->AutoShow;
1829 return S_OK;
1832 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1833 long WindowState) {
1834 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1836 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, WindowState);
1838 return S_OK;
1841 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1842 long *WindowState) {
1843 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1845 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, WindowState);
1847 return S_OK;
1850 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1851 long BackgroundPalette) {
1852 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1854 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, BackgroundPalette);
1856 return S_OK;
1859 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1860 long *pBackgroundPalette) {
1861 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1863 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1865 return S_OK;
1868 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1869 long Visible) {
1870 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1872 TRACE("(%p/%p)->(%ld)\n", This, iface, Visible);
1874 ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1876 return S_OK;
1879 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1880 long *pVisible) {
1881 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1883 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1885 *pVisible = IsWindowVisible(This->hWnd);
1887 return S_OK;
1890 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1891 long Left) {
1892 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1894 TRACE("(%p/%p)->(%ld)\n", This, iface, Left);
1896 if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1897 return E_FAIL;
1899 This->WindowPos.left = Left;
1901 return S_OK;
1904 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1905 long *pLeft) {
1906 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1908 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1910 *pLeft = This->WindowPos.left;
1912 return S_OK;
1915 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1916 long Width) {
1917 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1919 TRACE("(%p/%p)->(%ld)\n", This, iface, Width);
1921 if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1922 return E_FAIL;
1924 This->WindowPos.right = This->WindowPos.left + Width;
1926 return S_OK;
1929 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1930 long *pWidth) {
1931 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1933 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1935 *pWidth = This->WindowPos.right - This->WindowPos.left;
1937 return S_OK;
1940 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1941 long Top) {
1942 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1944 TRACE("(%p/%p)->(%ld)\n", This, iface, Top);
1946 if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1947 return E_FAIL;
1949 This->WindowPos.top = Top;
1951 return S_OK;
1954 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1955 long *pTop) {
1956 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1958 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1960 *pTop = This->WindowPos.top;
1962 return S_OK;
1965 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1966 long Height) {
1967 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1969 TRACE("(%p/%p)->(%ld)\n", This, iface, Height);
1971 if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1972 return E_FAIL;
1974 This->WindowPos.bottom = This->WindowPos.top + Height;
1976 return S_OK;
1979 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1980 long *pHeight) {
1981 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1983 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1985 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1987 return S_OK;
1990 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1991 OAHWND Owner) {
1992 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1994 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1996 SetParent(This->hWnd, (HWND)Owner);
1998 return S_OK;
2001 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
2002 OAHWND *Owner) {
2003 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2005 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
2007 *(HWND*)Owner = GetParent(This->hWnd);
2009 return S_OK;
2012 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
2013 OAHWND Drain) {
2014 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2016 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
2018 This->hWndMsgDrain = (HWND)Drain;
2020 return S_OK;
2023 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
2024 OAHWND *Drain) {
2025 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2027 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
2029 *Drain = (OAHWND)This->hWndMsgDrain;
2031 return S_OK;
2034 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
2035 long *Color) {
2036 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2038 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
2040 return S_OK;
2043 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
2044 long Color) {
2045 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2047 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, Color);
2049 return S_OK;
2052 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
2053 long *FullScreenMode) {
2054 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2056 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
2058 return S_OK;
2061 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
2062 long FullScreenMode) {
2063 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2065 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, FullScreenMode);
2067 return S_OK;
2070 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2071 long Focus) {
2072 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2073 BOOL ret;
2074 IPin* pPin;
2075 HRESULT hr;
2077 TRACE("(%p/%p)->(%ld)\n", This, iface, Focus);
2079 if ((Focus != FALSE) && (Focus != TRUE))
2080 return E_INVALIDARG;
2082 hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2083 if ((hr != S_OK) || !pPin)
2084 return VFW_E_NOT_CONNECTED;
2086 if (Focus)
2087 ret = SetForegroundWindow(This->hWnd);
2088 else
2089 ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2091 if (!ret)
2092 return E_FAIL;
2094 return S_OK;
2097 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2098 OAHWND hwnd,
2099 long uMsg,
2100 LONG_PTR wParam,
2101 LONG_PTR lParam) {
2102 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2104 TRACE("(%p/%p)->(%08x, %ld, %08lx, %08lx)\n", This, iface, (DWORD) hwnd, uMsg, wParam, lParam);
2106 if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
2107 return E_FAIL;
2109 return S_OK;
2112 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2113 long Left,
2114 long Top,
2115 long Width,
2116 long Height) {
2117 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2119 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
2121 if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2122 return E_FAIL;
2124 This->WindowPos.left = Left;
2125 This->WindowPos.top = Top;
2126 This->WindowPos.right = Left + Width;
2127 This->WindowPos.bottom = Top + Height;
2129 return S_OK;
2132 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2133 long *pLeft,
2134 long *pTop,
2135 long *pWidth,
2136 long *pHeight) {
2137 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2139 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2141 *pLeft = This->WindowPos.left;
2142 *pTop = This->WindowPos.top;
2143 *pWidth = This->WindowPos.right - This->WindowPos.left;
2144 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2146 return S_OK;
2149 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2150 long *pWidth,
2151 long *pHeight) {
2152 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2154 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2156 *pWidth = This->VideoWidth;
2157 *pHeight = This->VideoHeight;
2159 return S_OK;
2162 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2163 long *pWidth,
2164 long *pHeight) {
2165 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2167 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2169 *pWidth = This->VideoWidth;
2170 *pHeight = This->VideoHeight;
2172 return S_OK;
2175 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2176 long *pLeft,
2177 long *pTop,
2178 long *pWidth,
2179 long *pHeight) {
2180 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2182 FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2184 return S_OK;
2187 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2188 long HideCursor) {
2189 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2191 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, HideCursor);
2193 return S_OK;
2196 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2197 long *CursorHidden) {
2198 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2200 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2202 return S_OK;
2205 static const IVideoWindowVtbl IVideoWindow_VTable =
2207 Videowindow_QueryInterface,
2208 Videowindow_AddRef,
2209 Videowindow_Release,
2210 Videowindow_GetTypeInfoCount,
2211 Videowindow_GetTypeInfo,
2212 Videowindow_GetIDsOfNames,
2213 Videowindow_Invoke,
2214 Videowindow_put_Caption,
2215 Videowindow_get_Caption,
2216 Videowindow_put_WindowStyle,
2217 Videowindow_get_WindowStyle,
2218 Videowindow_put_WindowStyleEx,
2219 Videowindow_get_WindowStyleEx,
2220 Videowindow_put_AutoShow,
2221 Videowindow_get_AutoShow,
2222 Videowindow_put_WindowState,
2223 Videowindow_get_WindowState,
2224 Videowindow_put_BackgroundPalette,
2225 Videowindow_get_BackgroundPalette,
2226 Videowindow_put_Visible,
2227 Videowindow_get_Visible,
2228 Videowindow_put_Left,
2229 Videowindow_get_Left,
2230 Videowindow_put_Width,
2231 Videowindow_get_Width,
2232 Videowindow_put_Top,
2233 Videowindow_get_Top,
2234 Videowindow_put_Height,
2235 Videowindow_get_Height,
2236 Videowindow_put_Owner,
2237 Videowindow_get_Owner,
2238 Videowindow_put_MessageDrain,
2239 Videowindow_get_MessageDrain,
2240 Videowindow_get_BorderColor,
2241 Videowindow_put_BorderColor,
2242 Videowindow_get_FullScreenMode,
2243 Videowindow_put_FullScreenMode,
2244 Videowindow_SetWindowForeground,
2245 Videowindow_NotifyOwnerMessage,
2246 Videowindow_SetWindowPosition,
2247 Videowindow_GetWindowPosition,
2248 Videowindow_GetMinIdealImageSize,
2249 Videowindow_GetMaxIdealImageSize,
2250 Videowindow_GetRestorePosition,
2251 Videowindow_HideCursor,
2252 Videowindow_IsCursorHidden