The real, definitive, Visual C++ support branch. Accept no substitutes
[reactos.git] / dll / directx / quartz / videorenderer.c
1 /*
2 * Video Renderer (Fullscreen and Windowed using Direct Draw)
3 *
4 * Copyright 2004 Christian Costa
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22
23 #define NONAMELESSSTRUCT
24 #define NONAMELESSUNION
25 #include "quartz_private.h"
26 #include "control_private.h"
27 #include "pin.h"
28
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"
39
40 #include <assert.h>
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45
46 static BOOL wnd_class_registered = FALSE;
47
48 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
49
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
56 typedef struct VideoRendererImpl
57 {
58 const IBaseFilterVtbl * lpVtbl;
59 const IBasicVideoVtbl * IBasicVideo_vtbl;
60 const IVideoWindowVtbl * IVideoWindow_vtbl;
61 const IUnknownVtbl * IInner_vtbl;
62
63 LONG refCount;
64 CRITICAL_SECTION csFilter;
65 FILTER_STATE state;
66 REFERENCE_TIME rtStreamStart;
67 IReferenceClock * pClock;
68 FILTER_INFO filterInfo;
69
70 InputPin *pInputPin;
71
72 BOOL init;
73 HANDLE hThread;
74 HANDLE blocked;
75
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;
92
93 /* During pause we can hold a single sample, for use in GetCurrentImage */
94 IMediaSample *sample_held;
95 } VideoRendererImpl;
96
97 static LRESULT CALLBACK VideoWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
98 {
99 VideoRendererImpl* pVideoRenderer = (VideoRendererImpl*)GetWindowLongA(hwnd, 0);
100 LPRECT lprect = (LPRECT)lParam;
101
102 if (pVideoRenderer && pVideoRenderer->hWndMsgDrain)
103 {
104 switch(uMsg)
105 {
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;
133 }
134 }
135
136 switch(uMsg)
137 {
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);
159 }
160 return 0;
161 }
162
163 static BOOL CreateRenderingWindow(VideoRendererImpl* This)
164 {
165 WNDCLASSA winclass;
166
167 TRACE("(%p)->()\n", This);
168
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";
179
180 if (!wnd_class_registered)
181 {
182 if (!RegisterClassA(&winclass))
183 {
184 ERR("Unable to register window %u\n", GetLastError());
185 return FALSE;
186 }
187 wnd_class_registered = TRUE;
188 }
189
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);
193
194 if (!This->hWnd)
195 {
196 ERR("Unable to create window\n");
197 return FALSE;
198 }
199
200 SetWindowLongA(This->hWnd, 0, (LONG)This);
201
202 return TRUE;
203 }
204
205 static DWORD WINAPI MessageLoop(LPVOID lpParameter)
206 {
207 VideoRendererImpl* This = (VideoRendererImpl*) lpParameter;
208 MSG msg;
209 BOOL fGotMessage;
210
211 TRACE("Starting message loop\n");
212
213 if (!CreateRenderingWindow(This))
214 {
215 This->ThreadResult = FALSE;
216 SetEvent(This->hEvent);
217 return 0;
218 }
219
220 This->ThreadResult = TRUE;
221 SetEvent(This->hEvent);
222
223 while ((fGotMessage = GetMessageA(&msg, NULL, 0, 0)) != 0 && fGotMessage != -1)
224 {
225 TranslateMessage(&msg);
226 DispatchMessageA(&msg);
227 }
228
229 TRACE("End of message loop\n");
230
231 return msg.wParam;
232 }
233
234 static BOOL CreateRenderingSubsystem(VideoRendererImpl* This)
235 {
236 This->hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
237 if (!This->hEvent)
238 return FALSE;
239
240 This->hThread = CreateThread(NULL, 0, MessageLoop, (LPVOID)This, 0, &This->ThreadID);
241 if (!This->hThread)
242 {
243 CloseHandle(This->hEvent);
244 return FALSE;
245 }
246
247 WaitForSingleObject(This->hEvent, INFINITE);
248
249 if (!This->ThreadResult)
250 {
251 CloseHandle(This->hEvent);
252 CloseHandle(This->hThread);
253 return FALSE;
254 }
255
256 return TRUE;
257 }
258
259 static const IMemInputPinVtbl MemInputPin_Vtbl =
260 {
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
270 };
271
272 static DWORD VideoRenderer_SendSampleData(VideoRendererImpl* This, LPBYTE data, DWORD size)
273 {
274 AM_MEDIA_TYPE amt;
275 HRESULT hr = S_OK;
276 DDSURFACEDESC sdesc;
277 int width;
278 int height;
279 LPBYTE palette = NULL;
280 HDC hDC;
281 BITMAPINFOHEADER *bmiHeader;
282
283 TRACE("%p %p %d\n", This, data, size);
284
285 sdesc.dwSize = sizeof(sdesc);
286 hr = IPin_ConnectionMediaType((IPin *)This->pInputPin, &amt);
287 if (FAILED(hr)) {
288 ERR("Unable to retrieve media type\n");
289 return hr;
290 }
291
292 if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo))
293 {
294 bmiHeader = &((VIDEOINFOHEADER *)amt.pbFormat)->bmiHeader;
295 }
296 else if (IsEqualIID(&amt.formattype, &FORMAT_VideoInfo2))
297 {
298 bmiHeader = &((VIDEOINFOHEADER2 *)amt.pbFormat)->bmiHeader;
299 }
300 else
301 {
302 FIXME("Unknown type %s\n", debugstr_guid(&amt.subtype));
303 return VFW_E_RUNTIME_ERROR;
304 }
305
306
307 TRACE("biSize = %d\n", bmiHeader->biSize);
308 TRACE("biWidth = %d\n", bmiHeader->biWidth);
309 TRACE("biHeight = %d\n", bmiHeader->biHeight);
310 TRACE("biPlanes = %d\n", bmiHeader->biPlanes);
311 TRACE("biBitCount = %d\n", bmiHeader->biBitCount);
312 TRACE("biCompression = %s\n", debugstr_an((LPSTR)&(bmiHeader->biCompression), 4));
313 TRACE("biSizeImage = %d\n", bmiHeader->biSizeImage);
314
315 width = bmiHeader->biWidth;
316 height = bmiHeader->biHeight;
317 palette = ((LPBYTE)bmiHeader) + bmiHeader->biSize;
318
319 if (!This->init)
320 {
321 if (!This->WindowPos.right || !This->WindowPos.bottom)
322 This->WindowPos = This->SourceRect;
323
324 TRACE("WindowPos: %d %d %d %d\n", This->WindowPos.left, This->WindowPos.top, This->WindowPos.right, This->WindowPos.bottom);
325 SetWindowPos(This->hWnd, NULL,
326 This->WindowPos.left,
327 This->WindowPos.top,
328 This->WindowPos.right - This->WindowPos.left,
329 This->WindowPos.bottom - This->WindowPos.top,
330 SWP_NOZORDER|SWP_NOMOVE);
331
332 GetClientRect(This->hWnd, &This->DestRect);
333 This->init = TRUE;
334 }
335
336 hDC = GetDC(This->hWnd);
337
338 if (!hDC) {
339 ERR("Cannot get DC from window!\n");
340 return E_FAIL;
341 }
342
343 TRACE("Src Rect: %d %d %d %d\n", This->SourceRect.left, This->SourceRect.top, This->SourceRect.right, This->SourceRect.bottom);
344 TRACE("Dst Rect: %d %d %d %d\n", This->DestRect.left, This->DestRect.top, This->DestRect.right, This->DestRect.bottom);
345
346 StretchDIBits(hDC, This->DestRect.left, This->DestRect.top, This->DestRect.right -This->DestRect.left,
347 This->DestRect.bottom - This->DestRect.top, This->SourceRect.left, This->SourceRect.top,
348 This->SourceRect.right - This->SourceRect.left, This->SourceRect.bottom - This->SourceRect.top,
349 data, (BITMAPINFO *)bmiHeader, DIB_RGB_COLORS, SRCCOPY);
350
351 ReleaseDC(This->hWnd, hDC);
352 if (This->AutoShow)
353 ShowWindow(This->hWnd, SW_SHOW);
354
355 return S_OK;
356 }
357
358 static HRESULT VideoRenderer_Sample(LPVOID iface, IMediaSample * pSample)
359 {
360 VideoRendererImpl *This = (VideoRendererImpl *)iface;
361 LPBYTE pbSrcStream = NULL;
362 long cbSrcStream = 0;
363 REFERENCE_TIME tStart, tStop;
364 HRESULT hr;
365 EnterCriticalSection(&This->csFilter);
366 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
367 hr = S_FALSE;
368
369 if (This->state == State_Stopped)
370 {
371 LeaveCriticalSection(&This->csFilter);
372 return VFW_E_WRONG_STATE;
373 }
374
375 TRACE("%p %p\n", iface, pSample);
376
377 hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
378 if (FAILED(hr))
379 ERR("Cannot get sample time (%x)\n", hr);
380
381 if (This->rtLastStop != tStart)
382 {
383 if (IMediaSample_IsDiscontinuity(pSample) == S_FALSE)
384 ERR("Unexpected discontinuity: Last: %u.%03u, tStart: %u.%03u\n",
385 (DWORD)(This->rtLastStop / 10000000),
386 (DWORD)((This->rtLastStop / 10000)%1000),
387 (DWORD)(tStart / 10000000), (DWORD)((tStart / 10000)%1000));
388 This->rtLastStop = tStart;
389 }
390
391 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
392 if (IMediaSample_IsPreroll(pSample) == S_OK)
393 {
394 This->rtLastStop = tStop;
395 LeaveCriticalSection(&This->csFilter);
396 return S_OK;
397 }
398
399 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
400 if (FAILED(hr))
401 {
402 ERR("Cannot get pointer to sample data (%x)\n", hr);
403 LeaveCriticalSection(&This->csFilter);
404 return hr;
405 }
406
407 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
408
409 TRACE("val %p %ld\n", pbSrcStream, cbSrcStream);
410
411 #if 0 /* For debugging purpose */
412 {
413 int i;
414 for(i = 0; i < cbSrcStream; i++)
415 {
416 if ((i!=0) && !(i%16))
417 TRACE("\n");
418 TRACE("%02x ", pbSrcStream[i]);
419 }
420 TRACE("\n");
421 }
422 #endif
423
424 SetEvent(This->hEvent);
425 if (This->state == State_Paused)
426 {
427 This->sample_held = pSample;
428 LeaveCriticalSection(&This->csFilter);
429 WaitForSingleObject(This->blocked, INFINITE);
430 EnterCriticalSection(&This->csFilter);
431 This->sample_held = NULL;
432 if (This->state == State_Paused)
433 {
434 /* Flushing */
435 LeaveCriticalSection(&This->csFilter);
436 return S_OK;
437 }
438 if (This->state == State_Stopped)
439 {
440 LeaveCriticalSection(&This->csFilter);
441 return VFW_E_WRONG_STATE;
442 }
443 }
444
445 if (This->pClock && This->state == State_Running)
446 {
447 REFERENCE_TIME time, trefstart, trefstop;
448 LONG delta;
449
450 /* Perhaps I <SHOULD> use the reference clock AdviseTime function here
451 * I'm not going to! When I tried, it seemed to generate lag and
452 * it caused instability.
453 */
454 IReferenceClock_GetTime(This->pClock, &time);
455
456 trefstart = This->rtStreamStart;
457 trefstop = (REFERENCE_TIME)((double)(tStop - tStart) / This->pInputPin->dRate) + This->rtStreamStart;
458 delta = (LONG)((trefstart-time)/10000);
459 This->rtStreamStart = trefstop;
460 This->rtLastStop = tStop;
461
462 if (delta > 0)
463 {
464 TRACE("Sleeping for %u ms\n", delta);
465 Sleep(delta);
466 }
467 else if (time > trefstop)
468 {
469 TRACE("Dropping sample: Time: %u.%03u ms trefstop: %u.%03u ms!\n",
470 (DWORD)(time / 10000000), (DWORD)((time / 10000)%1000),
471 (DWORD)(trefstop / 10000000), (DWORD)((trefstop / 10000)%1000) );
472 This->rtLastStop = tStop;
473 LeaveCriticalSection(&This->csFilter);
474 return S_OK;
475 }
476 }
477 This->rtLastStop = tStop;
478
479 VideoRenderer_SendSampleData(This, pbSrcStream, cbSrcStream);
480
481 LeaveCriticalSection(&This->csFilter);
482 return S_OK;
483 }
484
485 static HRESULT VideoRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
486 {
487 if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
488 return S_FALSE;
489
490 if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB32) ||
491 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB24) ||
492 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB565) ||
493 IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_RGB8))
494 {
495 VideoRendererImpl* This = (VideoRendererImpl*) iface;
496
497 if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
498 {
499 VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pmt->pbFormat;
500 This->SourceRect.left = 0;
501 This->SourceRect.top = 0;
502 This->SourceRect.right = This->VideoWidth = format->bmiHeader.biWidth;
503 This->SourceRect.bottom = This->VideoHeight = format->bmiHeader.biHeight;
504 }
505 else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
506 {
507 VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
508
509 This->SourceRect.left = 0;
510 This->SourceRect.top = 0;
511 This->SourceRect.right = This->VideoWidth = format2->bmiHeader.biWidth;
512 This->SourceRect.bottom = This->VideoHeight = format2->bmiHeader.biHeight;
513 }
514 else
515 {
516 WARN("Format type %s not supported\n", debugstr_guid(&pmt->formattype));
517 return S_FALSE;
518 }
519 return S_OK;
520 }
521 return S_FALSE;
522 }
523
524 static inline VideoRendererImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
525 {
526 return (VideoRendererImpl *)((char*)iface - FIELD_OFFSET(VideoRendererImpl, mediaSeeking.lpVtbl));
527 }
528
529 static HRESULT WINAPI VideoRendererImpl_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
530 {
531 VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
532
533 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
534 }
535
536 static ULONG WINAPI VideoRendererImpl_Seeking_AddRef(IMediaSeeking * iface)
537 {
538 VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
539
540 return IUnknown_AddRef((IUnknown *)This);
541 }
542
543 static ULONG WINAPI VideoRendererImpl_Seeking_Release(IMediaSeeking * iface)
544 {
545 VideoRendererImpl *This = impl_from_IMediaSeeking(iface);
546
547 return IUnknown_Release((IUnknown *)This);
548 }
549
550 static const IMediaSeekingVtbl VideoRendererImpl_Seeking_Vtbl =
551 {
552 VideoRendererImpl_Seeking_QueryInterface,
553 VideoRendererImpl_Seeking_AddRef,
554 VideoRendererImpl_Seeking_Release,
555 MediaSeekingImpl_GetCapabilities,
556 MediaSeekingImpl_CheckCapabilities,
557 MediaSeekingImpl_IsFormatSupported,
558 MediaSeekingImpl_QueryPreferredFormat,
559 MediaSeekingImpl_GetTimeFormat,
560 MediaSeekingImpl_IsUsingTimeFormat,
561 MediaSeekingImpl_SetTimeFormat,
562 MediaSeekingImpl_GetDuration,
563 MediaSeekingImpl_GetStopPosition,
564 MediaSeekingImpl_GetCurrentPosition,
565 MediaSeekingImpl_ConvertTimeFormat,
566 MediaSeekingImpl_SetPositions,
567 MediaSeekingImpl_GetPositions,
568 MediaSeekingImpl_GetAvailable,
569 MediaSeekingImpl_SetRate,
570 MediaSeekingImpl_GetRate,
571 MediaSeekingImpl_GetPreroll
572 };
573
574 static HRESULT VideoRendererImpl_Change(IBaseFilter *iface)
575 {
576 TRACE("(%p)\n", iface);
577 return S_OK;
578 }
579
580 HRESULT VideoRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
581 {
582 HRESULT hr;
583 PIN_INFO piInput;
584 VideoRendererImpl * pVideoRenderer;
585
586 TRACE("(%p, %p)\n", pUnkOuter, ppv);
587
588 *ppv = NULL;
589
590 pVideoRenderer = CoTaskMemAlloc(sizeof(VideoRendererImpl));
591 pVideoRenderer->pUnkOuter = pUnkOuter;
592 pVideoRenderer->bUnkOuterValid = FALSE;
593 pVideoRenderer->bAggregatable = FALSE;
594 pVideoRenderer->IInner_vtbl = &IInner_VTable;
595
596 pVideoRenderer->lpVtbl = &VideoRenderer_Vtbl;
597 pVideoRenderer->IBasicVideo_vtbl = &IBasicVideo_VTable;
598 pVideoRenderer->IVideoWindow_vtbl = &IVideoWindow_VTable;
599
600 pVideoRenderer->refCount = 1;
601 InitializeCriticalSection(&pVideoRenderer->csFilter);
602 pVideoRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": VideoRendererImpl.csFilter");
603 pVideoRenderer->state = State_Stopped;
604 pVideoRenderer->pClock = NULL;
605 pVideoRenderer->init = 0;
606 pVideoRenderer->AutoShow = 1;
607 pVideoRenderer->rtLastStop = -1;
608 ZeroMemory(&pVideoRenderer->filterInfo, sizeof(FILTER_INFO));
609 ZeroMemory(&pVideoRenderer->SourceRect, sizeof(RECT));
610 ZeroMemory(&pVideoRenderer->DestRect, sizeof(RECT));
611 ZeroMemory(&pVideoRenderer->WindowPos, sizeof(RECT));
612 pVideoRenderer->hWndMsgDrain = NULL;
613
614 /* construct input pin */
615 piInput.dir = PINDIR_INPUT;
616 piInput.pFilter = (IBaseFilter *)pVideoRenderer;
617 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
618
619 hr = InputPin_Construct(&VideoRenderer_InputPin_Vtbl, &piInput, VideoRenderer_Sample, (LPVOID)pVideoRenderer, VideoRenderer_QueryAccept, NULL, &pVideoRenderer->csFilter, NULL, (IPin **)&pVideoRenderer->pInputPin);
620
621 if (SUCCEEDED(hr))
622 {
623 MediaSeekingImpl_Init((IBaseFilter*)pVideoRenderer, VideoRendererImpl_Change, VideoRendererImpl_Change, VideoRendererImpl_Change, &pVideoRenderer->mediaSeeking, &pVideoRenderer->csFilter);
624 pVideoRenderer->mediaSeeking.lpVtbl = &VideoRendererImpl_Seeking_Vtbl;
625
626 pVideoRenderer->sample_held = NULL;
627 *ppv = (LPVOID)pVideoRenderer;
628 }
629 else
630 {
631 pVideoRenderer->csFilter.DebugInfo->Spare[0] = 0;
632 DeleteCriticalSection(&pVideoRenderer->csFilter);
633 CoTaskMemFree(pVideoRenderer);
634 }
635
636 if (!CreateRenderingSubsystem(pVideoRenderer))
637 return E_FAIL;
638
639 pVideoRenderer->blocked = CreateEventW(NULL, FALSE, FALSE, NULL);
640 if (!pVideoRenderer->blocked)
641 {
642 hr = HRESULT_FROM_WIN32(GetLastError());
643 IUnknown_Release((IUnknown *)pVideoRenderer);
644 }
645
646 return hr;
647 }
648
649 HRESULT VideoRendererDefault_create(IUnknown * pUnkOuter, LPVOID * ppv)
650 {
651 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
652 return VideoRenderer_create(pUnkOuter, ppv);
653 }
654
655 static HRESULT WINAPI VideoRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
656 {
657 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
658 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
659
660 if (This->bAggregatable)
661 This->bUnkOuterValid = TRUE;
662
663 *ppv = NULL;
664
665 if (IsEqualIID(riid, &IID_IUnknown))
666 *ppv = (LPVOID)&(This->IInner_vtbl);
667 else if (IsEqualIID(riid, &IID_IPersist))
668 *ppv = (LPVOID)This;
669 else if (IsEqualIID(riid, &IID_IMediaFilter))
670 *ppv = (LPVOID)This;
671 else if (IsEqualIID(riid, &IID_IBaseFilter))
672 *ppv = (LPVOID)This;
673 else if (IsEqualIID(riid, &IID_IBasicVideo))
674 *ppv = (LPVOID)&(This->IBasicVideo_vtbl);
675 else if (IsEqualIID(riid, &IID_IVideoWindow))
676 *ppv = (LPVOID)&(This->IVideoWindow_vtbl);
677 else if (IsEqualIID(riid, &IID_IMediaSeeking))
678 *ppv = &This->mediaSeeking;
679
680 if (*ppv)
681 {
682 IUnknown_AddRef((IUnknown *)(*ppv));
683 return S_OK;
684 }
685
686 if (!IsEqualIID(riid, &IID_IPin))
687 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
688
689 return E_NOINTERFACE;
690 }
691
692 static ULONG WINAPI VideoRendererInner_AddRef(IUnknown * iface)
693 {
694 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
695 ULONG refCount = InterlockedIncrement(&This->refCount);
696
697 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
698
699 return refCount;
700 }
701
702 static ULONG WINAPI VideoRendererInner_Release(IUnknown * iface)
703 {
704 ICOM_THIS_MULTI(VideoRendererImpl, IInner_vtbl, iface);
705 ULONG refCount = InterlockedDecrement(&This->refCount);
706
707 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
708
709 if (!refCount)
710 {
711 IPin *pConnectedTo;
712
713 DestroyWindow(This->hWnd);
714 PostThreadMessageA(This->ThreadID, WM_QUIT, 0, 0);
715 WaitForSingleObject(This->hThread, INFINITE);
716 CloseHandle(This->hThread);
717 CloseHandle(This->hEvent);
718
719 if (This->pClock)
720 IReferenceClock_Release(This->pClock);
721
722 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
723 {
724 IPin_Disconnect(pConnectedTo);
725 IPin_Release(pConnectedTo);
726 }
727 IPin_Disconnect((IPin *)This->pInputPin);
728
729 IPin_Release((IPin *)This->pInputPin);
730
731 This->lpVtbl = NULL;
732
733 This->csFilter.DebugInfo->Spare[0] = 0;
734 DeleteCriticalSection(&This->csFilter);
735
736 TRACE("Destroying Video Renderer\n");
737 CoTaskMemFree(This);
738
739 return 0;
740 }
741 else
742 return refCount;
743 }
744
745 static const IUnknownVtbl IInner_VTable =
746 {
747 VideoRendererInner_QueryInterface,
748 VideoRendererInner_AddRef,
749 VideoRendererInner_Release
750 };
751
752 static HRESULT WINAPI VideoRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
753 {
754 VideoRendererImpl *This = (VideoRendererImpl *)iface;
755
756 if (This->bAggregatable)
757 This->bUnkOuterValid = TRUE;
758
759 if (This->pUnkOuter)
760 {
761 if (This->bAggregatable)
762 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
763
764 if (IsEqualIID(riid, &IID_IUnknown))
765 {
766 HRESULT hr;
767
768 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
769 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
770 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
771 This->bAggregatable = TRUE;
772 return hr;
773 }
774
775 *ppv = NULL;
776 return E_NOINTERFACE;
777 }
778
779 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
780 }
781
782 static ULONG WINAPI VideoRenderer_AddRef(IBaseFilter * iface)
783 {
784 VideoRendererImpl *This = (VideoRendererImpl *)iface;
785
786 if (This->pUnkOuter && This->bUnkOuterValid)
787 return IUnknown_AddRef(This->pUnkOuter);
788 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
789 }
790
791 static ULONG WINAPI VideoRenderer_Release(IBaseFilter * iface)
792 {
793 VideoRendererImpl *This = (VideoRendererImpl *)iface;
794
795 if (This->pUnkOuter && This->bUnkOuterValid)
796 return IUnknown_Release(This->pUnkOuter);
797 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
798 }
799
800 /** IPersist methods **/
801
802 static HRESULT WINAPI VideoRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
803 {
804 VideoRendererImpl *This = (VideoRendererImpl *)iface;
805
806 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
807
808 *pClsid = CLSID_VideoRenderer;
809
810 return S_OK;
811 }
812
813 /** IMediaFilter methods **/
814
815 static HRESULT WINAPI VideoRenderer_Stop(IBaseFilter * iface)
816 {
817 VideoRendererImpl *This = (VideoRendererImpl *)iface;
818
819 TRACE("(%p/%p)->()\n", This, iface);
820
821 EnterCriticalSection(&This->csFilter);
822 {
823 This->state = State_Stopped;
824 SetEvent(This->hEvent);
825 SetEvent(This->blocked);
826 }
827 LeaveCriticalSection(&This->csFilter);
828
829 return S_OK;
830 }
831
832 static HRESULT WINAPI VideoRenderer_Pause(IBaseFilter * iface)
833 {
834 VideoRendererImpl *This = (VideoRendererImpl *)iface;
835
836 TRACE("(%p/%p)->()\n", This, iface);
837
838 EnterCriticalSection(&This->csFilter);
839 if (This->state != State_Paused)
840 {
841 if (This->state == State_Stopped)
842 {
843 This->pInputPin->end_of_stream = 0;
844 ResetEvent(This->hEvent);
845 }
846
847 This->state = State_Paused;
848 ResetEvent(This->blocked);
849 }
850 LeaveCriticalSection(&This->csFilter);
851
852 return S_OK;
853 }
854
855 static HRESULT WINAPI VideoRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
856 {
857 VideoRendererImpl *This = (VideoRendererImpl *)iface;
858
859 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
860
861 EnterCriticalSection(&This->csFilter);
862 if (This->state != State_Running)
863 {
864 if (This->state == State_Stopped)
865 {
866 This->pInputPin->end_of_stream = 0;
867 ResetEvent(This->hEvent);
868 }
869 SetEvent(This->blocked);
870
871 This->rtStreamStart = tStart;
872 This->state = State_Running;
873 }
874 LeaveCriticalSection(&This->csFilter);
875
876 return S_OK;
877 }
878
879 static HRESULT WINAPI VideoRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
880 {
881 VideoRendererImpl *This = (VideoRendererImpl *)iface;
882 HRESULT hr;
883
884 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
885
886 if (WaitForSingleObject(This->hEvent, dwMilliSecsTimeout) == WAIT_TIMEOUT)
887 hr = VFW_S_STATE_INTERMEDIATE;
888 else
889 hr = S_OK;
890
891 EnterCriticalSection(&This->csFilter);
892 {
893 *pState = This->state;
894 }
895 LeaveCriticalSection(&This->csFilter);
896
897 return hr;
898 }
899
900 static HRESULT WINAPI VideoRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
901 {
902 VideoRendererImpl *This = (VideoRendererImpl *)iface;
903
904 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
905
906 EnterCriticalSection(&This->csFilter);
907 {
908 if (This->pClock)
909 IReferenceClock_Release(This->pClock);
910 This->pClock = pClock;
911 if (This->pClock)
912 IReferenceClock_AddRef(This->pClock);
913 }
914 LeaveCriticalSection(&This->csFilter);
915
916 return S_OK;
917 }
918
919 static HRESULT WINAPI VideoRenderer_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
920 {
921 VideoRendererImpl *This = (VideoRendererImpl *)iface;
922
923 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
924
925 EnterCriticalSection(&This->csFilter);
926 {
927 *ppClock = This->pClock;
928 if (This->pClock)
929 IReferenceClock_AddRef(This->pClock);
930 }
931 LeaveCriticalSection(&This->csFilter);
932
933 return S_OK;
934 }
935
936 /** IBaseFilter implementation **/
937
938 static HRESULT VideoRenderer_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
939 {
940 VideoRendererImpl *This = (VideoRendererImpl *)iface;
941
942 /* Our pins are static, not changing so setting static tick count is ok */
943 *lastsynctick = 0;
944
945 if (pos >= 1)
946 return S_FALSE;
947
948 *pin = (IPin *)This->pInputPin;
949 IPin_AddRef(*pin);
950 return S_OK;
951 }
952
953 static HRESULT WINAPI VideoRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
954 {
955 VideoRendererImpl *This = (VideoRendererImpl *)iface;
956
957 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
958
959 return IEnumPinsImpl_Construct(ppEnum, VideoRenderer_GetPin, iface);
960 }
961
962 static HRESULT WINAPI VideoRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
963 {
964 VideoRendererImpl *This = (VideoRendererImpl *)iface;
965
966 TRACE("(%p/%p)->(%p,%p)\n", This, iface, debugstr_w(Id), ppPin);
967
968 FIXME("VideoRenderer::FindPin(...)\n");
969
970 /* FIXME: critical section */
971
972 return E_NOTIMPL;
973 }
974
975 static HRESULT WINAPI VideoRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
976 {
977 VideoRendererImpl *This = (VideoRendererImpl *)iface;
978
979 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
980
981 strcpyW(pInfo->achName, This->filterInfo.achName);
982 pInfo->pGraph = This->filterInfo.pGraph;
983
984 if (pInfo->pGraph)
985 IFilterGraph_AddRef(pInfo->pGraph);
986
987 return S_OK;
988 }
989
990 static HRESULT WINAPI VideoRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
991 {
992 VideoRendererImpl *This = (VideoRendererImpl *)iface;
993
994 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
995
996 EnterCriticalSection(&This->csFilter);
997 {
998 if (pName)
999 strcpyW(This->filterInfo.achName, pName);
1000 else
1001 *This->filterInfo.achName = '\0';
1002 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
1003 }
1004 LeaveCriticalSection(&This->csFilter);
1005
1006 return S_OK;
1007 }
1008
1009 static HRESULT WINAPI VideoRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
1010 {
1011 VideoRendererImpl *This = (VideoRendererImpl *)iface;
1012 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
1013 return E_NOTIMPL;
1014 }
1015
1016 static const IBaseFilterVtbl VideoRenderer_Vtbl =
1017 {
1018 VideoRenderer_QueryInterface,
1019 VideoRenderer_AddRef,
1020 VideoRenderer_Release,
1021 VideoRenderer_GetClassID,
1022 VideoRenderer_Stop,
1023 VideoRenderer_Pause,
1024 VideoRenderer_Run,
1025 VideoRenderer_GetState,
1026 VideoRenderer_SetSyncSource,
1027 VideoRenderer_GetSyncSource,
1028 VideoRenderer_EnumPins,
1029 VideoRenderer_FindPin,
1030 VideoRenderer_QueryFilterInfo,
1031 VideoRenderer_JoinFilterGraph,
1032 VideoRenderer_QueryVendorInfo
1033 };
1034
1035 static HRESULT WINAPI VideoRenderer_InputPin_EndOfStream(IPin * iface)
1036 {
1037 InputPin* This = (InputPin*)iface;
1038 IMediaEventSink* pEventSink;
1039 HRESULT hr;
1040
1041 TRACE("(%p/%p)->()\n", This, iface);
1042
1043 hr = IFilterGraph_QueryInterface(((VideoRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
1044 if (SUCCEEDED(hr))
1045 {
1046 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
1047 IMediaEventSink_Release(pEventSink);
1048 }
1049
1050 return hr;
1051 }
1052
1053 static HRESULT WINAPI VideoRenderer_InputPin_BeginFlush(IPin * iface)
1054 {
1055 InputPin* This = (InputPin*)iface;
1056 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1057 HRESULT hr;
1058
1059 TRACE("(%p/%p)->()\n", This, iface);
1060
1061 EnterCriticalSection(This->pin.pCritSec);
1062 if (pVideoRenderer->state == State_Paused)
1063 SetEvent(pVideoRenderer->blocked);
1064
1065 hr = InputPin_BeginFlush(iface);
1066 LeaveCriticalSection(This->pin.pCritSec);
1067
1068 return hr;
1069 }
1070
1071 static HRESULT WINAPI VideoRenderer_InputPin_EndFlush(IPin * iface)
1072 {
1073 InputPin* This = (InputPin*)iface;
1074 VideoRendererImpl *pVideoRenderer = (VideoRendererImpl *)This->pin.pinInfo.pFilter;
1075 HRESULT hr;
1076
1077 TRACE("(%p/%p)->()\n", This, iface);
1078
1079 EnterCriticalSection(This->pin.pCritSec);
1080 if (pVideoRenderer->state == State_Paused)
1081 ResetEvent(pVideoRenderer->blocked);
1082
1083 hr = InputPin_EndFlush(iface);
1084 LeaveCriticalSection(This->pin.pCritSec);
1085
1086 return hr;
1087 }
1088
1089 static const IPinVtbl VideoRenderer_InputPin_Vtbl =
1090 {
1091 InputPin_QueryInterface,
1092 IPinImpl_AddRef,
1093 InputPin_Release,
1094 InputPin_Connect,
1095 InputPin_ReceiveConnection,
1096 IPinImpl_Disconnect,
1097 IPinImpl_ConnectedTo,
1098 IPinImpl_ConnectionMediaType,
1099 IPinImpl_QueryPinInfo,
1100 IPinImpl_QueryDirection,
1101 IPinImpl_QueryId,
1102 IPinImpl_QueryAccept,
1103 IPinImpl_EnumMediaTypes,
1104 IPinImpl_QueryInternalConnections,
1105 VideoRenderer_InputPin_EndOfStream,
1106 VideoRenderer_InputPin_BeginFlush,
1107 VideoRenderer_InputPin_EndFlush,
1108 InputPin_NewSegment
1109 };
1110
1111 /*** IUnknown methods ***/
1112 static HRESULT WINAPI Basicvideo_QueryInterface(IBasicVideo *iface,
1113 REFIID riid,
1114 LPVOID*ppvObj) {
1115 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1116
1117 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1118
1119 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1120 }
1121
1122 static ULONG WINAPI Basicvideo_AddRef(IBasicVideo *iface) {
1123 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1124
1125 TRACE("(%p/%p)->()\n", This, iface);
1126
1127 return VideoRenderer_AddRef((IBaseFilter*)This);
1128 }
1129
1130 static ULONG WINAPI Basicvideo_Release(IBasicVideo *iface) {
1131 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1132
1133 TRACE("(%p/%p)->()\n", This, iface);
1134
1135 return VideoRenderer_Release((IBaseFilter*)This);
1136 }
1137
1138 /*** IDispatch methods ***/
1139 static HRESULT WINAPI Basicvideo_GetTypeInfoCount(IBasicVideo *iface,
1140 UINT*pctinfo) {
1141 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1142
1143 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1144
1145 return S_OK;
1146 }
1147
1148 static HRESULT WINAPI Basicvideo_GetTypeInfo(IBasicVideo *iface,
1149 UINT iTInfo,
1150 LCID lcid,
1151 ITypeInfo**ppTInfo) {
1152 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1153
1154 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1155
1156 return S_OK;
1157 }
1158
1159 static HRESULT WINAPI Basicvideo_GetIDsOfNames(IBasicVideo *iface,
1160 REFIID riid,
1161 LPOLESTR*rgszNames,
1162 UINT cNames,
1163 LCID lcid,
1164 DISPID*rgDispId) {
1165 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1166
1167 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1168
1169 return S_OK;
1170 }
1171
1172 static HRESULT WINAPI Basicvideo_Invoke(IBasicVideo *iface,
1173 DISPID dispIdMember,
1174 REFIID riid,
1175 LCID lcid,
1176 WORD wFlags,
1177 DISPPARAMS*pDispParams,
1178 VARIANT*pVarResult,
1179 EXCEPINFO*pExepInfo,
1180 UINT*puArgErr) {
1181 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1182
1183 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);
1184
1185 return S_OK;
1186 }
1187
1188 /*** IBasicVideo methods ***/
1189 static HRESULT WINAPI Basicvideo_get_AvgTimePerFrame(IBasicVideo *iface,
1190 REFTIME *pAvgTimePerFrame) {
1191 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1192
1193 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pAvgTimePerFrame);
1194
1195 return S_OK;
1196 }
1197
1198 static HRESULT WINAPI Basicvideo_get_BitRate(IBasicVideo *iface,
1199 long *pBitRate) {
1200 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1201
1202 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitRate);
1203
1204 return S_OK;
1205 }
1206
1207 static HRESULT WINAPI Basicvideo_get_BitErrorRate(IBasicVideo *iface,
1208 long *pBitErrorRate) {
1209 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1210
1211 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBitErrorRate);
1212
1213 return S_OK;
1214 }
1215
1216 static HRESULT WINAPI Basicvideo_get_VideoWidth(IBasicVideo *iface,
1217 long *pVideoWidth) {
1218 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1219
1220 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
1221
1222 *pVideoWidth = This->VideoWidth;
1223
1224 return S_OK;
1225 }
1226
1227 static HRESULT WINAPI Basicvideo_get_VideoHeight(IBasicVideo *iface,
1228 long *pVideoHeight) {
1229 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1230
1231 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
1232
1233 *pVideoHeight = This->VideoHeight;
1234
1235 return S_OK;
1236 }
1237
1238 static HRESULT WINAPI Basicvideo_put_SourceLeft(IBasicVideo *iface,
1239 long SourceLeft) {
1240 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1241
1242 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceLeft);
1243
1244 This->SourceRect.left = SourceLeft;
1245
1246 return S_OK;
1247 }
1248
1249 static HRESULT WINAPI Basicvideo_get_SourceLeft(IBasicVideo *iface,
1250 long *pSourceLeft) {
1251 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1252
1253 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
1254
1255 *pSourceLeft = This->SourceRect.left;
1256
1257 return S_OK;
1258 }
1259
1260 static HRESULT WINAPI Basicvideo_put_SourceWidth(IBasicVideo *iface,
1261 long SourceWidth) {
1262 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1263
1264 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceWidth);
1265
1266 This->SourceRect.right = This->SourceRect.left + SourceWidth;
1267
1268 return S_OK;
1269 }
1270
1271 static HRESULT WINAPI Basicvideo_get_SourceWidth(IBasicVideo *iface,
1272 long *pSourceWidth) {
1273 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1274
1275 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
1276
1277 *pSourceWidth = This->SourceRect.right - This->SourceRect.left;
1278
1279 return S_OK;
1280 }
1281
1282 static HRESULT WINAPI Basicvideo_put_SourceTop(IBasicVideo *iface,
1283 long SourceTop) {
1284 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1285
1286 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceTop);
1287
1288 This->SourceRect.top = SourceTop;
1289
1290 return S_OK;
1291 }
1292
1293 static HRESULT WINAPI Basicvideo_get_SourceTop(IBasicVideo *iface,
1294 long *pSourceTop) {
1295 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1296
1297 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
1298
1299 *pSourceTop = This->SourceRect.top;
1300
1301 return S_OK;
1302 }
1303
1304 static HRESULT WINAPI Basicvideo_put_SourceHeight(IBasicVideo *iface,
1305 long SourceHeight) {
1306 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1307
1308 TRACE("(%p/%p)->(%ld)\n", This, iface, SourceHeight);
1309
1310 This->SourceRect.bottom = This->SourceRect.top + SourceHeight;
1311
1312 return S_OK;
1313 }
1314
1315 static HRESULT WINAPI Basicvideo_get_SourceHeight(IBasicVideo *iface,
1316 long *pSourceHeight) {
1317 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1318
1319 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
1320
1321 *pSourceHeight = This->SourceRect.bottom - This->SourceRect.top;
1322
1323 return S_OK;
1324 }
1325
1326 static HRESULT WINAPI Basicvideo_put_DestinationLeft(IBasicVideo *iface,
1327 long DestinationLeft) {
1328 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1329
1330 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationLeft);
1331
1332 This->DestRect.left = DestinationLeft;
1333
1334 return S_OK;
1335 }
1336
1337 static HRESULT WINAPI Basicvideo_get_DestinationLeft(IBasicVideo *iface,
1338 long *pDestinationLeft) {
1339 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1340
1341 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
1342
1343 *pDestinationLeft = This->DestRect.left;
1344
1345 return S_OK;
1346 }
1347
1348 static HRESULT WINAPI Basicvideo_put_DestinationWidth(IBasicVideo *iface,
1349 long DestinationWidth) {
1350 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1351
1352 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationWidth);
1353
1354 This->DestRect.right = This->DestRect.left + DestinationWidth;
1355
1356 return S_OK;
1357 }
1358
1359 static HRESULT WINAPI Basicvideo_get_DestinationWidth(IBasicVideo *iface,
1360 long *pDestinationWidth) {
1361 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1362
1363 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
1364
1365 *pDestinationWidth = This->DestRect.right - This->DestRect.left;
1366
1367 return S_OK;
1368 }
1369
1370 static HRESULT WINAPI Basicvideo_put_DestinationTop(IBasicVideo *iface,
1371 long DestinationTop) {
1372 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1373
1374 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationTop);
1375
1376 This->DestRect.top = DestinationTop;
1377
1378 return S_OK;
1379 }
1380
1381 static HRESULT WINAPI Basicvideo_get_DestinationTop(IBasicVideo *iface,
1382 long *pDestinationTop) {
1383 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1384
1385 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
1386
1387 *pDestinationTop = This->DestRect.top;
1388
1389 return S_OK;
1390 }
1391
1392 static HRESULT WINAPI Basicvideo_put_DestinationHeight(IBasicVideo *iface,
1393 long DestinationHeight) {
1394 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1395
1396 TRACE("(%p/%p)->(%ld)\n", This, iface, DestinationHeight);
1397
1398 This->DestRect.right = This->DestRect.left + DestinationHeight;
1399
1400 return S_OK;
1401 }
1402
1403 static HRESULT WINAPI Basicvideo_get_DestinationHeight(IBasicVideo *iface,
1404 long *pDestinationHeight) {
1405 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1406
1407 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
1408
1409 *pDestinationHeight = This->DestRect.right - This->DestRect.left;
1410
1411 return S_OK;
1412 }
1413
1414 static HRESULT WINAPI Basicvideo_SetSourcePosition(IBasicVideo *iface,
1415 long Left,
1416 long Top,
1417 long Width,
1418 long Height) {
1419 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1420
1421 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
1422
1423 This->SourceRect.left = Left;
1424 This->SourceRect.top = Top;
1425 This->SourceRect.right = Left + Width;
1426 This->SourceRect.bottom = Top + Height;
1427
1428 return S_OK;
1429 }
1430
1431 static HRESULT WINAPI Basicvideo_GetSourcePosition(IBasicVideo *iface,
1432 long *pLeft,
1433 long *pTop,
1434 long *pWidth,
1435 long *pHeight) {
1436 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1437
1438 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1439
1440 *pLeft = This->SourceRect.left;
1441 *pTop = This->SourceRect.top;
1442 *pWidth = This->SourceRect.right - This->SourceRect.left;
1443 *pHeight = This->SourceRect.bottom - This->SourceRect.top;
1444
1445 return S_OK;
1446 }
1447
1448 static HRESULT WINAPI Basicvideo_SetDefaultSourcePosition(IBasicVideo *iface) {
1449 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1450
1451 TRACE("(%p/%p)->()\n", This, iface);
1452
1453 This->SourceRect.left = 0;
1454 This->SourceRect.top = 0;
1455 This->SourceRect.right = This->VideoWidth;
1456 This->SourceRect.bottom = This->VideoHeight;
1457
1458 return S_OK;
1459 }
1460
1461 static HRESULT WINAPI Basicvideo_SetDestinationPosition(IBasicVideo *iface,
1462 long Left,
1463 long Top,
1464 long Width,
1465 long Height) {
1466 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1467
1468 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
1469
1470 This->DestRect.left = Left;
1471 This->DestRect.top = Top;
1472 This->DestRect.right = Left + Width;
1473 This->DestRect.bottom = Top + Height;
1474
1475 return S_OK;
1476 }
1477
1478 static HRESULT WINAPI Basicvideo_GetDestinationPosition(IBasicVideo *iface,
1479 long *pLeft,
1480 long *pTop,
1481 long *pWidth,
1482 long *pHeight) {
1483 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1484
1485 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
1486
1487 *pLeft = This->DestRect.left;
1488 *pTop = This->DestRect.top;
1489 *pWidth = This->DestRect.right - This->DestRect.left;
1490 *pHeight = This->DestRect.bottom - This->DestRect.top;
1491
1492 return S_OK;
1493 }
1494
1495 static HRESULT WINAPI Basicvideo_SetDefaultDestinationPosition(IBasicVideo *iface) {
1496 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1497 RECT rect;
1498
1499 TRACE("(%p/%p)->()\n", This, iface);
1500
1501 if (!GetClientRect(This->hWnd, &rect))
1502 return E_FAIL;
1503
1504 This->SourceRect.left = 0;
1505 This->SourceRect.top = 0;
1506 This->SourceRect.right = rect.right;
1507 This->SourceRect.bottom = rect.bottom;
1508
1509 return S_OK;
1510 }
1511
1512 static HRESULT WINAPI Basicvideo_GetVideoSize(IBasicVideo *iface,
1513 long *pWidth,
1514 long *pHeight) {
1515 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1516
1517 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
1518
1519 *pWidth = This->VideoWidth;
1520 *pHeight = This->VideoHeight;
1521
1522 return S_OK;
1523 }
1524
1525 static HRESULT WINAPI Basicvideo_GetVideoPaletteEntries(IBasicVideo *iface,
1526 long StartIndex,
1527 long Entries,
1528 long *pRetrieved,
1529 long *pPalette) {
1530 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1531
1532 FIXME("(%p/%p)->(%ld, %ld, %p, %p): stub !!!\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
1533
1534 return S_OK;
1535 }
1536
1537 static HRESULT WINAPI Basicvideo_GetCurrentImage(IBasicVideo *iface,
1538 long *pBufferSize,
1539 long *pDIBImage) {
1540 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1541 BITMAPINFOHEADER *bmiHeader;
1542 LONG needed_size;
1543 AM_MEDIA_TYPE *amt = &This->pInputPin->pin.mtCurrent;
1544 char *ptr;
1545
1546 EnterCriticalSection(&This->csFilter);
1547
1548 if (!This->sample_held)
1549 {
1550 LeaveCriticalSection(&This->csFilter);
1551 return (This->state == State_Paused ? E_UNEXPECTED : VFW_E_NOT_PAUSED);
1552 }
1553
1554 FIXME("(%p/%p)->(%p, %p): partial stub\n", This, iface, pBufferSize, pDIBImage);
1555
1556 if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo))
1557 {
1558 bmiHeader = &((VIDEOINFOHEADER *)amt->pbFormat)->bmiHeader;
1559 }
1560 else if (IsEqualIID(&amt->formattype, &FORMAT_VideoInfo2))
1561 {
1562 bmiHeader = &((VIDEOINFOHEADER2 *)amt->pbFormat)->bmiHeader;
1563 }
1564 else
1565 {
1566 FIXME("Unknown type %s\n", debugstr_guid(&amt->subtype));
1567 LeaveCriticalSection(&This->csFilter);
1568 return VFW_E_RUNTIME_ERROR;
1569 }
1570
1571 needed_size = bmiHeader->biSize;
1572 needed_size += IMediaSample_GetActualDataLength(This->sample_held);
1573
1574 if (!pDIBImage)
1575 {
1576 *pBufferSize = needed_size;
1577 LeaveCriticalSection(&This->csFilter);
1578 return S_OK;
1579 }
1580
1581 if (needed_size < *pBufferSize)
1582 {
1583 ERR("Buffer too small %u/%lu\n", needed_size, *pBufferSize);
1584 LeaveCriticalSection(&This->csFilter);
1585 return E_FAIL;
1586 }
1587 *pBufferSize = needed_size;
1588
1589 memcpy(pDIBImage, bmiHeader, bmiHeader->biSize);
1590 IMediaSample_GetPointer(This->sample_held, (BYTE **)&ptr);
1591 memcpy((char *)pDIBImage + bmiHeader->biSize, ptr, IMediaSample_GetActualDataLength(This->sample_held));
1592
1593 LeaveCriticalSection(&This->csFilter);
1594
1595 return S_OK;
1596 }
1597
1598 static HRESULT WINAPI Basicvideo_IsUsingDefaultSource(IBasicVideo *iface) {
1599 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1600
1601 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1602
1603 return S_OK;
1604 }
1605
1606 static HRESULT WINAPI Basicvideo_IsUsingDefaultDestination(IBasicVideo *iface) {
1607 ICOM_THIS_MULTI(VideoRendererImpl, IBasicVideo_vtbl, iface);
1608
1609 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
1610
1611 return S_OK;
1612 }
1613
1614
1615 static const IBasicVideoVtbl IBasicVideo_VTable =
1616 {
1617 Basicvideo_QueryInterface,
1618 Basicvideo_AddRef,
1619 Basicvideo_Release,
1620 Basicvideo_GetTypeInfoCount,
1621 Basicvideo_GetTypeInfo,
1622 Basicvideo_GetIDsOfNames,
1623 Basicvideo_Invoke,
1624 Basicvideo_get_AvgTimePerFrame,
1625 Basicvideo_get_BitRate,
1626 Basicvideo_get_BitErrorRate,
1627 Basicvideo_get_VideoWidth,
1628 Basicvideo_get_VideoHeight,
1629 Basicvideo_put_SourceLeft,
1630 Basicvideo_get_SourceLeft,
1631 Basicvideo_put_SourceWidth,
1632 Basicvideo_get_SourceWidth,
1633 Basicvideo_put_SourceTop,
1634 Basicvideo_get_SourceTop,
1635 Basicvideo_put_SourceHeight,
1636 Basicvideo_get_SourceHeight,
1637 Basicvideo_put_DestinationLeft,
1638 Basicvideo_get_DestinationLeft,
1639 Basicvideo_put_DestinationWidth,
1640 Basicvideo_get_DestinationWidth,
1641 Basicvideo_put_DestinationTop,
1642 Basicvideo_get_DestinationTop,
1643 Basicvideo_put_DestinationHeight,
1644 Basicvideo_get_DestinationHeight,
1645 Basicvideo_SetSourcePosition,
1646 Basicvideo_GetSourcePosition,
1647 Basicvideo_SetDefaultSourcePosition,
1648 Basicvideo_SetDestinationPosition,
1649 Basicvideo_GetDestinationPosition,
1650 Basicvideo_SetDefaultDestinationPosition,
1651 Basicvideo_GetVideoSize,
1652 Basicvideo_GetVideoPaletteEntries,
1653 Basicvideo_GetCurrentImage,
1654 Basicvideo_IsUsingDefaultSource,
1655 Basicvideo_IsUsingDefaultDestination
1656 };
1657
1658
1659 /*** IUnknown methods ***/
1660 static HRESULT WINAPI Videowindow_QueryInterface(IVideoWindow *iface,
1661 REFIID riid,
1662 LPVOID*ppvObj) {
1663 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1664
1665 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1666
1667 return VideoRenderer_QueryInterface((IBaseFilter*)This, riid, ppvObj);
1668 }
1669
1670 static ULONG WINAPI Videowindow_AddRef(IVideoWindow *iface) {
1671 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1672
1673 TRACE("(%p/%p)->()\n", This, iface);
1674
1675 return VideoRenderer_AddRef((IBaseFilter*)This);
1676 }
1677
1678 static ULONG WINAPI Videowindow_Release(IVideoWindow *iface) {
1679 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1680
1681 TRACE("(%p/%p)->()\n", This, iface);
1682
1683 return VideoRenderer_Release((IBaseFilter*)This);
1684 }
1685
1686 /*** IDispatch methods ***/
1687 static HRESULT WINAPI Videowindow_GetTypeInfoCount(IVideoWindow *iface,
1688 UINT*pctinfo) {
1689 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1690
1691 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1692
1693 return S_OK;
1694 }
1695
1696 static HRESULT WINAPI Videowindow_GetTypeInfo(IVideoWindow *iface,
1697 UINT iTInfo,
1698 LCID lcid,
1699 ITypeInfo**ppTInfo) {
1700 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1701
1702 FIXME("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1703
1704 return S_OK;
1705 }
1706
1707 static HRESULT WINAPI Videowindow_GetIDsOfNames(IVideoWindow *iface,
1708 REFIID riid,
1709 LPOLESTR*rgszNames,
1710 UINT cNames,
1711 LCID lcid,
1712 DISPID*rgDispId) {
1713 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1714
1715 FIXME("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1716
1717 return S_OK;
1718 }
1719
1720 static HRESULT WINAPI Videowindow_Invoke(IVideoWindow *iface,
1721 DISPID dispIdMember,
1722 REFIID riid,
1723 LCID lcid,
1724 WORD wFlags,
1725 DISPPARAMS*pDispParams,
1726 VARIANT*pVarResult,
1727 EXCEPINFO*pExepInfo,
1728 UINT*puArgErr) {
1729 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1730
1731 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);
1732
1733 return S_OK;
1734 }
1735
1736 /*** IVideoWindow methods ***/
1737 static HRESULT WINAPI Videowindow_put_Caption(IVideoWindow *iface,
1738 BSTR strCaption) {
1739 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1740
1741 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
1742
1743 if (!SetWindowTextW(This->hWnd, strCaption))
1744 return E_FAIL;
1745
1746 return S_OK;
1747 }
1748
1749 static HRESULT WINAPI Videowindow_get_Caption(IVideoWindow *iface,
1750 BSTR *strCaption) {
1751 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1752
1753 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
1754
1755 GetWindowTextW(This->hWnd, (LPWSTR)strCaption, 100);
1756
1757 return S_OK;
1758 }
1759
1760 static HRESULT WINAPI Videowindow_put_WindowStyle(IVideoWindow *iface,
1761 long WindowStyle) {
1762 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1763 LONG old;
1764
1765 old = GetWindowLongA(This->hWnd, GWL_STYLE);
1766
1767 TRACE("(%p/%p)->(%x -> %lx)\n", This, iface, old, WindowStyle);
1768
1769 if (WindowStyle & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1770 return E_INVALIDARG;
1771
1772 SetWindowLongA(This->hWnd, GWL_STYLE, WindowStyle);
1773
1774 return S_OK;
1775 }
1776
1777 static HRESULT WINAPI Videowindow_get_WindowStyle(IVideoWindow *iface,
1778 long *WindowStyle) {
1779 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1780
1781 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
1782
1783 *WindowStyle = GetWindowLongA(This->hWnd, GWL_STYLE);
1784
1785 return S_OK;
1786 }
1787
1788 static HRESULT WINAPI Videowindow_put_WindowStyleEx(IVideoWindow *iface,
1789 long WindowStyleEx) {
1790 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1791
1792 TRACE("(%p/%p)->(%ld)\n", This, iface, WindowStyleEx);
1793
1794 if (WindowStyleEx & (WS_DISABLED|WS_HSCROLL|WS_ICONIC|WS_MAXIMIZE|WS_MINIMIZE|WS_VSCROLL))
1795 return E_INVALIDARG;
1796
1797 if (!SetWindowLongA(This->hWnd, GWL_EXSTYLE, WindowStyleEx))
1798 return E_FAIL;
1799
1800 return S_OK;
1801 }
1802
1803 static HRESULT WINAPI Videowindow_get_WindowStyleEx(IVideoWindow *iface,
1804 long *WindowStyleEx) {
1805 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1806
1807 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
1808
1809 *WindowStyleEx = GetWindowLongA(This->hWnd, GWL_EXSTYLE);
1810
1811 return S_OK;
1812 }
1813
1814 static HRESULT WINAPI Videowindow_put_AutoShow(IVideoWindow *iface,
1815 long AutoShow) {
1816 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1817
1818 TRACE("(%p/%p)->(%ld)\n", This, iface, AutoShow);
1819
1820 This->AutoShow = 1; /* FXIME: Should be AutoShow */;
1821
1822 return S_OK;
1823 }
1824
1825 static HRESULT WINAPI Videowindow_get_AutoShow(IVideoWindow *iface,
1826 long *AutoShow) {
1827 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1828
1829 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
1830
1831 *AutoShow = This->AutoShow;
1832
1833 return S_OK;
1834 }
1835
1836 static HRESULT WINAPI Videowindow_put_WindowState(IVideoWindow *iface,
1837 long WindowState) {
1838 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1839
1840 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, WindowState);
1841
1842 return S_OK;
1843 }
1844
1845 static HRESULT WINAPI Videowindow_get_WindowState(IVideoWindow *iface,
1846 long *WindowState) {
1847 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1848
1849 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, WindowState);
1850
1851 return S_OK;
1852 }
1853
1854 static HRESULT WINAPI Videowindow_put_BackgroundPalette(IVideoWindow *iface,
1855 long BackgroundPalette) {
1856 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1857
1858 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, BackgroundPalette);
1859
1860 return S_OK;
1861 }
1862
1863 static HRESULT WINAPI Videowindow_get_BackgroundPalette(IVideoWindow *iface,
1864 long *pBackgroundPalette) {
1865 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1866
1867 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pBackgroundPalette);
1868
1869 return S_OK;
1870 }
1871
1872 static HRESULT WINAPI Videowindow_put_Visible(IVideoWindow *iface,
1873 long Visible) {
1874 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1875
1876 TRACE("(%p/%p)->(%ld)\n", This, iface, Visible);
1877
1878 ShowWindow(This->hWnd, Visible ? SW_SHOW : SW_HIDE);
1879
1880 return S_OK;
1881 }
1882
1883 static HRESULT WINAPI Videowindow_get_Visible(IVideoWindow *iface,
1884 long *pVisible) {
1885 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1886
1887 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
1888
1889 *pVisible = IsWindowVisible(This->hWnd);
1890
1891 return S_OK;
1892 }
1893
1894 static HRESULT WINAPI Videowindow_put_Left(IVideoWindow *iface,
1895 long Left) {
1896 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1897
1898 TRACE("(%p/%p)->(%ld)\n", This, iface, Left);
1899
1900 if (!SetWindowPos(This->hWnd, NULL, Left, This->WindowPos.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1901 return E_FAIL;
1902
1903 This->WindowPos.left = Left;
1904
1905 return S_OK;
1906 }
1907
1908 static HRESULT WINAPI Videowindow_get_Left(IVideoWindow *iface,
1909 long *pLeft) {
1910 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1911
1912 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
1913
1914 *pLeft = This->WindowPos.left;
1915
1916 return S_OK;
1917 }
1918
1919 static HRESULT WINAPI Videowindow_put_Width(IVideoWindow *iface,
1920 long Width) {
1921 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1922
1923 TRACE("(%p/%p)->(%ld)\n", This, iface, Width);
1924
1925 if (!SetWindowPos(This->hWnd, NULL, 0, 0, Width, This->WindowPos.bottom-This->WindowPos.top, SWP_NOZORDER|SWP_NOMOVE))
1926 return E_FAIL;
1927
1928 This->WindowPos.right = This->WindowPos.left + Width;
1929
1930 return S_OK;
1931 }
1932
1933 static HRESULT WINAPI Videowindow_get_Width(IVideoWindow *iface,
1934 long *pWidth) {
1935 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1936
1937 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
1938
1939 *pWidth = This->WindowPos.right - This->WindowPos.left;
1940
1941 return S_OK;
1942 }
1943
1944 static HRESULT WINAPI Videowindow_put_Top(IVideoWindow *iface,
1945 long Top) {
1946 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1947
1948 TRACE("(%p/%p)->(%ld)\n", This, iface, Top);
1949
1950 if (!SetWindowPos(This->hWnd, NULL, This->WindowPos.left, Top, 0, 0, SWP_NOZORDER|SWP_NOSIZE))
1951 return E_FAIL;
1952
1953 This->WindowPos.top = Top;
1954
1955 return S_OK;
1956 }
1957
1958 static HRESULT WINAPI Videowindow_get_Top(IVideoWindow *iface,
1959 long *pTop) {
1960 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1961
1962 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
1963
1964 *pTop = This->WindowPos.top;
1965
1966 return S_OK;
1967 }
1968
1969 static HRESULT WINAPI Videowindow_put_Height(IVideoWindow *iface,
1970 long Height) {
1971 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1972
1973 TRACE("(%p/%p)->(%ld)\n", This, iface, Height);
1974
1975 if (!SetWindowPos(This->hWnd, NULL, 0, 0, This->WindowPos.right-This->WindowPos.left, Height, SWP_NOZORDER|SWP_NOMOVE))
1976 return E_FAIL;
1977
1978 This->WindowPos.bottom = This->WindowPos.top + Height;
1979
1980 return S_OK;
1981 }
1982
1983 static HRESULT WINAPI Videowindow_get_Height(IVideoWindow *iface,
1984 long *pHeight) {
1985 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1986
1987 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
1988
1989 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
1990
1991 return S_OK;
1992 }
1993
1994 static HRESULT WINAPI Videowindow_put_Owner(IVideoWindow *iface,
1995 OAHWND Owner) {
1996 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
1997
1998 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
1999
2000 SetParent(This->hWnd, (HWND)Owner);
2001
2002 return S_OK;
2003 }
2004
2005 static HRESULT WINAPI Videowindow_get_Owner(IVideoWindow *iface,
2006 OAHWND *Owner) {
2007 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2008
2009 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
2010
2011 *(HWND*)Owner = GetParent(This->hWnd);
2012
2013 return S_OK;
2014 }
2015
2016 static HRESULT WINAPI Videowindow_put_MessageDrain(IVideoWindow *iface,
2017 OAHWND Drain) {
2018 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2019
2020 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
2021
2022 This->hWndMsgDrain = (HWND)Drain;
2023
2024 return S_OK;
2025 }
2026
2027 static HRESULT WINAPI Videowindow_get_MessageDrain(IVideoWindow *iface,
2028 OAHWND *Drain) {
2029 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2030
2031 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
2032
2033 *Drain = (OAHWND)This->hWndMsgDrain;
2034
2035 return S_OK;
2036 }
2037
2038 static HRESULT WINAPI Videowindow_get_BorderColor(IVideoWindow *iface,
2039 long *Color) {
2040 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2041
2042 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, Color);
2043
2044 return S_OK;
2045 }
2046
2047 static HRESULT WINAPI Videowindow_put_BorderColor(IVideoWindow *iface,
2048 long Color) {
2049 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2050
2051 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, Color);
2052
2053 return S_OK;
2054 }
2055
2056 static HRESULT WINAPI Videowindow_get_FullScreenMode(IVideoWindow *iface,
2057 long *FullScreenMode) {
2058 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2059
2060 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, FullScreenMode);
2061
2062 return S_OK;
2063 }
2064
2065 static HRESULT WINAPI Videowindow_put_FullScreenMode(IVideoWindow *iface,
2066 long FullScreenMode) {
2067 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2068
2069 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, FullScreenMode);
2070
2071 return S_OK;
2072 }
2073
2074 static HRESULT WINAPI Videowindow_SetWindowForeground(IVideoWindow *iface,
2075 long Focus) {
2076 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2077 BOOL ret;
2078 IPin* pPin;
2079 HRESULT hr;
2080
2081 TRACE("(%p/%p)->(%ld)\n", This, iface, Focus);
2082
2083 if ((Focus != FALSE) && (Focus != TRUE))
2084 return E_INVALIDARG;
2085
2086 hr = IPin_ConnectedTo((IPin *)This->pInputPin, &pPin);
2087 if ((hr != S_OK) || !pPin)
2088 return VFW_E_NOT_CONNECTED;
2089
2090 if (Focus)
2091 ret = SetForegroundWindow(This->hWnd);
2092 else
2093 ret = SetWindowPos(This->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2094
2095 if (!ret)
2096 return E_FAIL;
2097
2098 return S_OK;
2099 }
2100
2101 static HRESULT WINAPI Videowindow_NotifyOwnerMessage(IVideoWindow *iface,
2102 OAHWND hwnd,
2103 long uMsg,
2104 LONG_PTR wParam,
2105 LONG_PTR lParam) {
2106 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2107
2108 TRACE("(%p/%p)->(%08x, %ld, %08lx, %08lx)\n", This, iface, (DWORD) hwnd, uMsg, wParam, lParam);
2109
2110 if (!PostMessageA(This->hWnd, uMsg, wParam, lParam))
2111 return E_FAIL;
2112
2113 return S_OK;
2114 }
2115
2116 static HRESULT WINAPI Videowindow_SetWindowPosition(IVideoWindow *iface,
2117 long Left,
2118 long Top,
2119 long Width,
2120 long Height) {
2121 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2122
2123 TRACE("(%p/%p)->(%ld, %ld, %ld, %ld)\n", This, iface, Left, Top, Width, Height);
2124
2125 if (!SetWindowPos(This->hWnd, NULL, Left, Top, Width, Height, SWP_NOZORDER))
2126 return E_FAIL;
2127
2128 This->WindowPos.left = Left;
2129 This->WindowPos.top = Top;
2130 This->WindowPos.right = Left + Width;
2131 This->WindowPos.bottom = Top + Height;
2132
2133 return S_OK;
2134 }
2135
2136 static HRESULT WINAPI Videowindow_GetWindowPosition(IVideoWindow *iface,
2137 long *pLeft,
2138 long *pTop,
2139 long *pWidth,
2140 long *pHeight) {
2141 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2142
2143 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
2144
2145 *pLeft = This->WindowPos.left;
2146 *pTop = This->WindowPos.top;
2147 *pWidth = This->WindowPos.right - This->WindowPos.left;
2148 *pHeight = This->WindowPos.bottom - This->WindowPos.top;
2149
2150 return S_OK;
2151 }
2152
2153 static HRESULT WINAPI Videowindow_GetMinIdealImageSize(IVideoWindow *iface,
2154 long *pWidth,
2155 long *pHeight) {
2156 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2157
2158 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2159
2160 *pWidth = This->VideoWidth;
2161 *pHeight = This->VideoHeight;
2162
2163 return S_OK;
2164 }
2165
2166 static HRESULT WINAPI Videowindow_GetMaxIdealImageSize(IVideoWindow *iface,
2167 long *pWidth,
2168 long *pHeight) {
2169 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2170
2171 FIXME("(%p/%p)->(%p, %p): semi stub !!!\n", This, iface, pWidth, pHeight);
2172
2173 *pWidth = This->VideoWidth;
2174 *pHeight = This->VideoHeight;
2175
2176 return S_OK;
2177 }
2178
2179 static HRESULT WINAPI Videowindow_GetRestorePosition(IVideoWindow *iface,
2180 long *pLeft,
2181 long *pTop,
2182 long *pWidth,
2183 long *pHeight) {
2184 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2185
2186 FIXME("(%p/%p)->(%p, %p, %p, %p): stub !!!\n", This, iface, pLeft, pTop, pWidth, pHeight);
2187
2188 return S_OK;
2189 }
2190
2191 static HRESULT WINAPI Videowindow_HideCursor(IVideoWindow *iface,
2192 long HideCursor) {
2193 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2194
2195 FIXME("(%p/%p)->(%ld): stub !!!\n", This, iface, HideCursor);
2196
2197 return S_OK;
2198 }
2199
2200 static HRESULT WINAPI Videowindow_IsCursorHidden(IVideoWindow *iface,
2201 long *CursorHidden) {
2202 ICOM_THIS_MULTI(VideoRendererImpl, IVideoWindow_vtbl, iface);
2203
2204 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, CursorHidden);
2205
2206 return S_OK;
2207 }
2208
2209 static const IVideoWindowVtbl IVideoWindow_VTable =
2210 {
2211 Videowindow_QueryInterface,
2212 Videowindow_AddRef,
2213 Videowindow_Release,
2214 Videowindow_GetTypeInfoCount,
2215 Videowindow_GetTypeInfo,
2216 Videowindow_GetIDsOfNames,
2217 Videowindow_Invoke,
2218 Videowindow_put_Caption,
2219 Videowindow_get_Caption,
2220 Videowindow_put_WindowStyle,
2221 Videowindow_get_WindowStyle,
2222 Videowindow_put_WindowStyleEx,
2223 Videowindow_get_WindowStyleEx,
2224 Videowindow_put_AutoShow,
2225 Videowindow_get_AutoShow,
2226 Videowindow_put_WindowState,
2227 Videowindow_get_WindowState,
2228 Videowindow_put_BackgroundPalette,
2229 Videowindow_get_BackgroundPalette,
2230 Videowindow_put_Visible,
2231 Videowindow_get_Visible,
2232 Videowindow_put_Left,
2233 Videowindow_get_Left,
2234 Videowindow_put_Width,
2235 Videowindow_get_Width,
2236 Videowindow_put_Top,
2237 Videowindow_get_Top,
2238 Videowindow_put_Height,
2239 Videowindow_get_Height,
2240 Videowindow_put_Owner,
2241 Videowindow_get_Owner,
2242 Videowindow_put_MessageDrain,
2243 Videowindow_get_MessageDrain,
2244 Videowindow_get_BorderColor,
2245 Videowindow_put_BorderColor,
2246 Videowindow_get_FullScreenMode,
2247 Videowindow_put_FullScreenMode,
2248 Videowindow_SetWindowForeground,
2249 Videowindow_NotifyOwnerMessage,
2250 Videowindow_SetWindowPosition,
2251 Videowindow_GetWindowPosition,
2252 Videowindow_GetMinIdealImageSize,
2253 Videowindow_GetMaxIdealImageSize,
2254 Videowindow_GetRestorePosition,
2255 Videowindow_HideCursor,
2256 Videowindow_IsCursorHidden
2257 };