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
23 #include "quartz_private.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
43 typedef struct VideoRendererImpl
45 BaseRenderer renderer
;
46 BaseControlWindow baseControlWindow
;
47 BaseControlVideo baseControlVideo
;
49 IUnknown IUnknown_inner
;
50 IAMFilterMiscFlags IAMFilterMiscFlags_iface
;
58 /* hEvent == evComplete? */
68 static inline VideoRendererImpl
*impl_from_BaseWindow(BaseWindow
*iface
)
70 return CONTAINING_RECORD(iface
, VideoRendererImpl
, baseControlWindow
.baseWindow
);
73 static inline VideoRendererImpl
*impl_from_BaseRenderer(BaseRenderer
*iface
)
75 return CONTAINING_RECORD(iface
, VideoRendererImpl
, renderer
);
78 static inline VideoRendererImpl
*impl_from_IBaseFilter(IBaseFilter
*iface
)
80 return CONTAINING_RECORD(iface
, VideoRendererImpl
, renderer
.filter
.IBaseFilter_iface
);
83 static inline VideoRendererImpl
*impl_from_IVideoWindow(IVideoWindow
*iface
)
85 return CONTAINING_RECORD(iface
, VideoRendererImpl
, baseControlWindow
.IVideoWindow_iface
);
88 static inline VideoRendererImpl
*impl_from_BaseControlVideo(BaseControlVideo
*iface
)
90 return CONTAINING_RECORD(iface
, VideoRendererImpl
, baseControlVideo
);
93 static inline VideoRendererImpl
*impl_from_IBasicVideo(IBasicVideo
*iface
)
95 return CONTAINING_RECORD(iface
, VideoRendererImpl
, baseControlVideo
.IBasicVideo_iface
);
98 static DWORD WINAPI
MessageLoop(LPVOID lpParameter
)
100 VideoRendererImpl
* This
= lpParameter
;
104 TRACE("Starting message loop\n");
106 if (FAILED(BaseWindowImpl_PrepareWindow(&This
->baseControlWindow
.baseWindow
)))
108 This
->ThreadResult
= FALSE
;
109 SetEvent(This
->hEvent
);
113 This
->ThreadResult
= TRUE
;
114 SetEvent(This
->hEvent
);
116 while ((fGotMessage
= GetMessageW(&msg
, NULL
, 0, 0)) != 0 && fGotMessage
!= -1)
118 TranslateMessage(&msg
);
119 DispatchMessageW(&msg
);
122 TRACE("End of message loop\n");
127 static BOOL
CreateRenderingSubsystem(VideoRendererImpl
* This
)
129 This
->hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
133 This
->hThread
= CreateThread(NULL
, 0, MessageLoop
, This
, 0, &This
->ThreadID
);
136 CloseHandle(This
->hEvent
);
140 WaitForSingleObject(This
->hEvent
, INFINITE
);
142 if (!This
->ThreadResult
)
144 CloseHandle(This
->hEvent
);
145 CloseHandle(This
->hThread
);
152 static void VideoRenderer_AutoShowWindow(VideoRendererImpl
*This
)
154 if (!This
->init
&& (!This
->WindowPos
.right
|| !This
->WindowPos
.top
))
156 DWORD style
= GetWindowLongW(This
->baseControlWindow
.baseWindow
.hWnd
, GWL_STYLE
);
157 DWORD style_ex
= GetWindowLongW(This
->baseControlWindow
.baseWindow
.hWnd
, GWL_EXSTYLE
);
159 if (!This
->WindowPos
.right
)
161 if (This
->DestRect
.right
)
163 This
->WindowPos
.left
= This
->DestRect
.left
;
164 This
->WindowPos
.right
= This
->DestRect
.right
;
168 This
->WindowPos
.left
= This
->SourceRect
.left
;
169 This
->WindowPos
.right
= This
->SourceRect
.right
;
172 if (!This
->WindowPos
.bottom
)
174 if (This
->DestRect
.bottom
)
176 This
->WindowPos
.top
= This
->DestRect
.top
;
177 This
->WindowPos
.bottom
= This
->DestRect
.bottom
;
181 This
->WindowPos
.top
= This
->SourceRect
.top
;
182 This
->WindowPos
.bottom
= This
->SourceRect
.bottom
;
186 AdjustWindowRectEx(&This
->WindowPos
, style
, FALSE
, style_ex
);
188 TRACE("WindowPos: %s\n", wine_dbgstr_rect(&This
->WindowPos
));
189 SetWindowPos(This
->baseControlWindow
.baseWindow
.hWnd
, NULL
,
190 This
->WindowPos
.left
,
192 This
->WindowPos
.right
- This
->WindowPos
.left
,
193 This
->WindowPos
.bottom
- This
->WindowPos
.top
,
194 SWP_NOZORDER
|SWP_NOMOVE
|SWP_DEFERERASE
);
196 GetClientRect(This
->baseControlWindow
.baseWindow
.hWnd
, &This
->DestRect
);
198 else if (!This
->init
)
199 This
->DestRect
= This
->WindowPos
;
201 if (This
->baseControlWindow
.AutoShow
)
202 ShowWindow(This
->baseControlWindow
.baseWindow
.hWnd
, SW_SHOW
);
205 static DWORD
VideoRenderer_SendSampleData(VideoRendererImpl
* This
, LPBYTE data
, DWORD size
)
209 BITMAPINFOHEADER
*bmiHeader
;
211 TRACE("(%p)->(%p, %d)\n", This
, data
, size
);
213 hr
= IPin_ConnectionMediaType(&This
->renderer
.pInputPin
->pin
.IPin_iface
, &amt
);
215 ERR("Unable to retrieve media type\n");
219 if (IsEqualIID(&amt
.formattype
, &FORMAT_VideoInfo
))
221 bmiHeader
= &((VIDEOINFOHEADER
*)amt
.pbFormat
)->bmiHeader
;
223 else if (IsEqualIID(&amt
.formattype
, &FORMAT_VideoInfo2
))
225 bmiHeader
= &((VIDEOINFOHEADER2
*)amt
.pbFormat
)->bmiHeader
;
229 FIXME("Unknown type %s\n", debugstr_guid(&amt
.subtype
));
230 return VFW_E_RUNTIME_ERROR
;
233 TRACE("biSize = %d\n", bmiHeader
->biSize
);
234 TRACE("biWidth = %d\n", bmiHeader
->biWidth
);
235 TRACE("biHeight = %d\n", bmiHeader
->biHeight
);
236 TRACE("biPlanes = %d\n", bmiHeader
->biPlanes
);
237 TRACE("biBitCount = %d\n", bmiHeader
->biBitCount
);
238 TRACE("biCompression = %s\n", debugstr_an((LPSTR
)&(bmiHeader
->biCompression
), 4));
239 TRACE("biSizeImage = %d\n", bmiHeader
->biSizeImage
);
241 if (!This
->baseControlWindow
.baseWindow
.hDC
) {
242 ERR("Cannot get DC from window!\n");
246 TRACE("Src Rect: %s\n", wine_dbgstr_rect(&This
->SourceRect
));
247 TRACE("Dst Rect: %s\n", wine_dbgstr_rect(&This
->DestRect
));
249 StretchDIBits(This
->baseControlWindow
.baseWindow
.hDC
, This
->DestRect
.left
, This
->DestRect
.top
, This
->DestRect
.right
-This
->DestRect
.left
,
250 This
->DestRect
.bottom
- This
->DestRect
.top
, This
->SourceRect
.left
, This
->SourceRect
.top
,
251 This
->SourceRect
.right
- This
->SourceRect
.left
, This
->SourceRect
.bottom
- This
->SourceRect
.top
,
252 data
, (BITMAPINFO
*)bmiHeader
, DIB_RGB_COLORS
, SRCCOPY
);
257 static HRESULT WINAPI
VideoRenderer_ShouldDrawSampleNow(BaseRenderer
*This
, IMediaSample
*pSample
, REFERENCE_TIME
*pStartTime
, REFERENCE_TIME
*pEndTime
)
259 /* Preroll means the sample isn't shown, this is used for key frames and things like that */
260 if (IMediaSample_IsPreroll(pSample
) == S_OK
)
265 static HRESULT WINAPI
VideoRenderer_DoRenderSample(BaseRenderer
* iface
, IMediaSample
* pSample
)
267 VideoRendererImpl
*This
= impl_from_BaseRenderer(iface
);
268 LPBYTE pbSrcStream
= NULL
;
269 LONG cbSrcStream
= 0;
272 TRACE("(%p)->(%p)\n", This
, pSample
);
274 hr
= IMediaSample_GetPointer(pSample
, &pbSrcStream
);
277 ERR("Cannot get pointer to sample data (%x)\n", hr
);
281 cbSrcStream
= IMediaSample_GetActualDataLength(pSample
);
283 TRACE("val %p %d\n", pbSrcStream
, cbSrcStream
);
285 #if 0 /* For debugging purpose */
288 for(i
= 0; i
< cbSrcStream
; i
++)
290 if ((i
!=0) && !(i
%16))
292 TRACE("%02x ", pbSrcStream
[i
]);
298 SetEvent(This
->hEvent
);
299 if (This
->renderer
.filter
.state
== State_Paused
)
301 VideoRenderer_SendSampleData(This
, pbSrcStream
, cbSrcStream
);
302 SetEvent(This
->hEvent
);
303 if (This
->renderer
.filter
.state
== State_Paused
)
308 if (This
->renderer
.filter
.state
== State_Stopped
)
310 return VFW_E_WRONG_STATE
;
313 VideoRenderer_SendSampleData(This
, pbSrcStream
, cbSrcStream
);
318 static HRESULT WINAPI
VideoRenderer_CheckMediaType(BaseRenderer
*iface
, const AM_MEDIA_TYPE
* pmt
)
320 VideoRendererImpl
*This
= impl_from_BaseRenderer(iface
);
322 if (!IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Video
))
325 if (IsEqualIID(&pmt
->subtype
, &MEDIASUBTYPE_RGB32
) ||
326 IsEqualIID(&pmt
->subtype
, &MEDIASUBTYPE_RGB24
) ||
327 IsEqualIID(&pmt
->subtype
, &MEDIASUBTYPE_RGB565
) ||
328 IsEqualIID(&pmt
->subtype
, &MEDIASUBTYPE_RGB8
))
332 if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
))
334 VIDEOINFOHEADER
*format
= (VIDEOINFOHEADER
*)pmt
->pbFormat
;
335 This
->SourceRect
.left
= 0;
336 This
->SourceRect
.top
= 0;
337 This
->SourceRect
.right
= This
->VideoWidth
= format
->bmiHeader
.biWidth
;
338 height
= format
->bmiHeader
.biHeight
;
340 This
->SourceRect
.bottom
= This
->VideoHeight
= -height
;
342 This
->SourceRect
.bottom
= This
->VideoHeight
= height
;
344 else if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo2
))
346 VIDEOINFOHEADER2
*format2
= (VIDEOINFOHEADER2
*)pmt
->pbFormat
;
348 This
->SourceRect
.left
= 0;
349 This
->SourceRect
.top
= 0;
350 This
->SourceRect
.right
= This
->VideoWidth
= format2
->bmiHeader
.biWidth
;
351 height
= format2
->bmiHeader
.biHeight
;
353 This
->SourceRect
.bottom
= This
->VideoHeight
= -height
;
355 This
->SourceRect
.bottom
= This
->VideoHeight
= height
;
359 WARN("Format type %s not supported\n", debugstr_guid(&pmt
->formattype
));
367 static HRESULT WINAPI
VideoRenderer_EndFlush(BaseRenderer
* iface
)
369 VideoRendererImpl
*This
= impl_from_BaseRenderer(iface
);
371 TRACE("(%p)->()\n", iface
);
373 if (This
->renderer
.pMediaSample
) {
374 ResetEvent(This
->hEvent
);
375 LeaveCriticalSection(iface
->pInputPin
->pin
.pCritSec
);
376 LeaveCriticalSection(&iface
->filter
.csFilter
);
377 LeaveCriticalSection(&iface
->csRenderLock
);
378 WaitForSingleObject(This
->hEvent
, INFINITE
);
379 EnterCriticalSection(&iface
->csRenderLock
);
380 EnterCriticalSection(&iface
->filter
.csFilter
);
381 EnterCriticalSection(iface
->pInputPin
->pin
.pCritSec
);
383 if (This
->renderer
.filter
.state
== State_Paused
) {
384 ResetEvent(This
->hEvent
);
387 return BaseRendererImpl_EndFlush(iface
);
390 static VOID WINAPI
VideoRenderer_OnStopStreaming(BaseRenderer
* iface
)
392 VideoRendererImpl
*This
= impl_from_BaseRenderer(iface
);
394 TRACE("(%p)->()\n", This
);
396 SetEvent(This
->hEvent
);
397 if (This
->baseControlWindow
.AutoShow
)
399 RedrawWindow(This
->baseControlWindow
.baseWindow
.hWnd
, NULL
, NULL
, RDW_INVALIDATE
|RDW_ERASE
);
402 static VOID WINAPI
VideoRenderer_OnStartStreaming(BaseRenderer
* iface
)
404 VideoRendererImpl
*This
= impl_from_BaseRenderer(iface
);
406 TRACE("(%p)\n", This
);
408 if (This
->renderer
.pInputPin
->pin
.pConnectedTo
&& (This
->renderer
.filter
.state
== State_Stopped
|| !This
->renderer
.pInputPin
->end_of_stream
))
410 if (This
->renderer
.filter
.state
== State_Stopped
)
412 ResetEvent(This
->hEvent
);
413 VideoRenderer_AutoShowWindow(This
);
418 static LPWSTR WINAPI
VideoRenderer_GetClassWindowStyles(BaseWindow
*This
, DWORD
*pClassStyles
, DWORD
*pWindowStyles
, DWORD
*pWindowStylesEx
)
420 static const WCHAR classnameW
[] = { 'W','i','n','e',' ','A','c','t','i','v','e','M','o','v','i','e',' ','C','l','a','s','s',0 };
423 *pWindowStyles
= WS_SIZEBOX
;
424 *pWindowStylesEx
= 0;
426 return (LPWSTR
)classnameW
;
429 static RECT WINAPI
VideoRenderer_GetDefaultRect(BaseWindow
*iface
)
431 VideoRendererImpl
*This
= impl_from_BaseWindow(iface
);
434 SetRect(&defRect
, 0, 0, This
->VideoWidth
, This
->VideoHeight
);
439 static BOOL WINAPI
VideoRenderer_OnSize(BaseWindow
*iface
, LONG Width
, LONG Height
)
441 VideoRendererImpl
*This
= impl_from_BaseWindow(iface
);
443 TRACE("WM_SIZE %d %d\n", Width
, Height
);
444 GetClientRect(iface
->hWnd
, &This
->DestRect
);
445 TRACE("WM_SIZING: DestRect=(%d,%d),(%d,%d)\n",
448 This
->DestRect
.right
- This
->DestRect
.left
,
449 This
->DestRect
.bottom
- This
->DestRect
.top
);
450 return BaseWindowImpl_OnSize(iface
, Width
, Height
);
453 static const BaseRendererFuncTable BaseFuncTable
= {
454 VideoRenderer_CheckMediaType
,
455 VideoRenderer_DoRenderSample
,
460 VideoRenderer_OnStartStreaming
,
461 VideoRenderer_OnStopStreaming
,
465 VideoRenderer_ShouldDrawSampleNow
,
472 VideoRenderer_EndFlush
,
475 static const BaseWindowFuncTable renderer_BaseWindowFuncTable
= {
476 VideoRenderer_GetClassWindowStyles
,
477 VideoRenderer_GetDefaultRect
,
479 BaseControlWindowImpl_PossiblyEatMessage
,
483 static HRESULT WINAPI
VideoRenderer_GetSourceRect(BaseControlVideo
* iface
, RECT
*pSourceRect
)
485 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
486 CopyRect(pSourceRect
,&This
->SourceRect
);
490 static HRESULT WINAPI
VideoRenderer_GetStaticImage(BaseControlVideo
* iface
, LONG
*pBufferSize
, LONG
*pDIBImage
)
492 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
493 BITMAPINFOHEADER
*bmiHeader
;
495 AM_MEDIA_TYPE
*amt
= &This
->renderer
.pInputPin
->pin
.mtCurrent
;
498 FIXME("(%p/%p)->(%p, %p): partial stub\n", This
, iface
, pBufferSize
, pDIBImage
);
500 EnterCriticalSection(&This
->renderer
.filter
.csFilter
);
502 if (!This
->renderer
.pMediaSample
)
504 LeaveCriticalSection(&This
->renderer
.filter
.csFilter
);
505 return (This
->renderer
.filter
.state
== State_Paused
? E_UNEXPECTED
: VFW_E_NOT_PAUSED
);
508 if (IsEqualIID(&amt
->formattype
, &FORMAT_VideoInfo
))
510 bmiHeader
= &((VIDEOINFOHEADER
*)amt
->pbFormat
)->bmiHeader
;
512 else if (IsEqualIID(&amt
->formattype
, &FORMAT_VideoInfo2
))
514 bmiHeader
= &((VIDEOINFOHEADER2
*)amt
->pbFormat
)->bmiHeader
;
518 FIXME("Unknown type %s\n", debugstr_guid(&amt
->subtype
));
519 LeaveCriticalSection(&This
->renderer
.filter
.csFilter
);
520 return VFW_E_RUNTIME_ERROR
;
523 needed_size
= bmiHeader
->biSize
;
524 needed_size
+= IMediaSample_GetActualDataLength(This
->renderer
.pMediaSample
);
528 *pBufferSize
= needed_size
;
529 LeaveCriticalSection(&This
->renderer
.filter
.csFilter
);
533 if (needed_size
< *pBufferSize
)
535 ERR("Buffer too small %u/%u\n", needed_size
, *pBufferSize
);
536 LeaveCriticalSection(&This
->renderer
.filter
.csFilter
);
539 *pBufferSize
= needed_size
;
541 memcpy(pDIBImage
, bmiHeader
, bmiHeader
->biSize
);
542 IMediaSample_GetPointer(This
->renderer
.pMediaSample
, (BYTE
**)&ptr
);
543 memcpy((char *)pDIBImage
+ bmiHeader
->biSize
, ptr
, IMediaSample_GetActualDataLength(This
->renderer
.pMediaSample
));
545 LeaveCriticalSection(&This
->renderer
.filter
.csFilter
);
549 static HRESULT WINAPI
VideoRenderer_GetTargetRect(BaseControlVideo
* iface
, RECT
*pTargetRect
)
551 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
552 CopyRect(pTargetRect
,&This
->DestRect
);
556 static VIDEOINFOHEADER
* WINAPI
VideoRenderer_GetVideoFormat(BaseControlVideo
* iface
)
558 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
561 TRACE("(%p/%p)\n", This
, iface
);
563 pmt
= &This
->renderer
.pInputPin
->pin
.mtCurrent
;
564 if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
)) {
565 return (VIDEOINFOHEADER
*)pmt
->pbFormat
;
566 } else if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo2
)) {
567 static VIDEOINFOHEADER vih
;
568 VIDEOINFOHEADER2
*vih2
= (VIDEOINFOHEADER2
*)pmt
->pbFormat
;
569 memcpy(&vih
,vih2
,sizeof(VIDEOINFOHEADER
));
570 memcpy(&vih
.bmiHeader
, &vih2
->bmiHeader
, sizeof(BITMAPINFOHEADER
));
573 ERR("Unknown format type %s\n", qzdebugstr_guid(&pmt
->formattype
));
578 static HRESULT WINAPI
VideoRenderer_IsDefaultSourceRect(BaseControlVideo
* iface
)
580 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
581 FIXME("(%p/%p)->(): stub !!!\n", This
, iface
);
586 static HRESULT WINAPI
VideoRenderer_IsDefaultTargetRect(BaseControlVideo
* iface
)
588 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
589 FIXME("(%p/%p)->(): stub !!!\n", This
, iface
);
594 static HRESULT WINAPI
VideoRenderer_SetDefaultSourceRect(BaseControlVideo
* iface
)
596 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
598 SetRect(&This
->SourceRect
, 0, 0, This
->VideoWidth
, This
->VideoHeight
);
603 static HRESULT WINAPI
VideoRenderer_SetDefaultTargetRect(BaseControlVideo
* iface
)
605 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
608 if (!GetClientRect(This
->baseControlWindow
.baseWindow
.hWnd
, &rect
))
611 SetRect(&This
->DestRect
, 0, 0, rect
.right
, rect
.bottom
);
616 static HRESULT WINAPI
VideoRenderer_SetSourceRect(BaseControlVideo
* iface
, RECT
*pSourceRect
)
618 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
619 CopyRect(&This
->SourceRect
,pSourceRect
);
623 static HRESULT WINAPI
VideoRenderer_SetTargetRect(BaseControlVideo
* iface
, RECT
*pTargetRect
)
625 VideoRendererImpl
*This
= impl_from_BaseControlVideo(iface
);
626 CopyRect(&This
->DestRect
,pTargetRect
);
630 static const BaseControlVideoFuncTable renderer_BaseControlVideoFuncTable
= {
631 VideoRenderer_GetSourceRect
,
632 VideoRenderer_GetStaticImage
,
633 VideoRenderer_GetTargetRect
,
634 VideoRenderer_GetVideoFormat
,
635 VideoRenderer_IsDefaultSourceRect
,
636 VideoRenderer_IsDefaultTargetRect
,
637 VideoRenderer_SetDefaultSourceRect
,
638 VideoRenderer_SetDefaultTargetRect
,
639 VideoRenderer_SetSourceRect
,
640 VideoRenderer_SetTargetRect
643 static inline VideoRendererImpl
*impl_from_IUnknown(IUnknown
*iface
)
645 return CONTAINING_RECORD(iface
, VideoRendererImpl
, IUnknown_inner
);
648 static HRESULT WINAPI
VideoRendererInner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
650 VideoRendererImpl
*This
= impl_from_IUnknown(iface
);
652 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
656 if (IsEqualIID(riid
, &IID_IUnknown
))
657 *ppv
= &This
->IUnknown_inner
;
658 else if (IsEqualIID(riid
, &IID_IBasicVideo
))
659 *ppv
= &This
->baseControlVideo
.IBasicVideo_iface
;
660 else if (IsEqualIID(riid
, &IID_IVideoWindow
))
661 *ppv
= &This
->baseControlWindow
.IVideoWindow_iface
;
662 else if (IsEqualIID(riid
, &IID_IAMFilterMiscFlags
))
663 *ppv
= &This
->IAMFilterMiscFlags_iface
;
667 hr
= BaseRendererImpl_QueryInterface(&This
->renderer
.filter
.IBaseFilter_iface
, riid
, ppv
);
674 IUnknown_AddRef((IUnknown
*)*ppv
);
678 if (!IsEqualIID(riid
, &IID_IPin
))
679 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
681 return E_NOINTERFACE
;
684 static ULONG WINAPI
VideoRendererInner_AddRef(IUnknown
*iface
)
686 VideoRendererImpl
*This
= impl_from_IUnknown(iface
);
687 ULONG refCount
= BaseFilterImpl_AddRef(&This
->renderer
.filter
.IBaseFilter_iface
);
689 TRACE("(%p)->(): new ref = %d\n", This
, refCount
);
694 static ULONG WINAPI
VideoRendererInner_Release(IUnknown
*iface
)
696 VideoRendererImpl
*This
= impl_from_IUnknown(iface
);
697 ULONG refCount
= BaseRendererImpl_Release(&This
->renderer
.filter
.IBaseFilter_iface
);
699 TRACE("(%p)->(): new ref = %d\n", This
, refCount
);
703 BaseControlWindow_Destroy(&This
->baseControlWindow
);
704 BaseControlVideo_Destroy(&This
->baseControlVideo
);
705 PostThreadMessageW(This
->ThreadID
, WM_QUIT
, 0, 0);
706 WaitForSingleObject(This
->hThread
, INFINITE
);
707 CloseHandle(This
->hThread
);
708 CloseHandle(This
->hEvent
);
710 TRACE("Destroying Video Renderer\n");
719 static const IUnknownVtbl IInner_VTable
=
721 VideoRendererInner_QueryInterface
,
722 VideoRendererInner_AddRef
,
723 VideoRendererInner_Release
726 static HRESULT WINAPI
VideoRenderer_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
728 VideoRendererImpl
*This
= impl_from_IBaseFilter(iface
);
729 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
732 static ULONG WINAPI
VideoRenderer_AddRef(IBaseFilter
* iface
)
734 VideoRendererImpl
*This
= impl_from_IBaseFilter(iface
);
735 return IUnknown_AddRef(This
->outer_unk
);
738 static ULONG WINAPI
VideoRenderer_Release(IBaseFilter
* iface
)
740 VideoRendererImpl
*This
= impl_from_IBaseFilter(iface
);
741 return IUnknown_Release(This
->outer_unk
);
744 /** IMediaFilter methods **/
746 static HRESULT WINAPI
VideoRenderer_Pause(IBaseFilter
* iface
)
748 VideoRendererImpl
*This
= impl_from_IBaseFilter(iface
);
750 TRACE("(%p/%p)->()\n", This
, iface
);
752 EnterCriticalSection(&This
->renderer
.csRenderLock
);
753 if (This
->renderer
.filter
.state
!= State_Paused
)
755 if (This
->renderer
.filter
.state
== State_Stopped
)
757 This
->renderer
.pInputPin
->end_of_stream
= 0;
758 ResetEvent(This
->hEvent
);
759 VideoRenderer_AutoShowWindow(This
);
762 ResetEvent(This
->renderer
.RenderEvent
);
763 This
->renderer
.filter
.state
= State_Paused
;
765 LeaveCriticalSection(&This
->renderer
.csRenderLock
);
770 static const IBaseFilterVtbl VideoRenderer_Vtbl
=
772 VideoRenderer_QueryInterface
,
773 VideoRenderer_AddRef
,
774 VideoRenderer_Release
,
775 BaseFilterImpl_GetClassID
,
776 BaseRendererImpl_Stop
,
778 BaseRendererImpl_Run
,
779 BaseRendererImpl_GetState
,
780 BaseRendererImpl_SetSyncSource
,
781 BaseFilterImpl_GetSyncSource
,
782 BaseFilterImpl_EnumPins
,
783 BaseRendererImpl_FindPin
,
784 BaseFilterImpl_QueryFilterInfo
,
785 BaseFilterImpl_JoinFilterGraph
,
786 BaseFilterImpl_QueryVendorInfo
789 /*** IUnknown methods ***/
790 static HRESULT WINAPI
BasicVideo_QueryInterface(IBasicVideo
*iface
, REFIID riid
, LPVOID
*ppvObj
)
792 VideoRendererImpl
*This
= impl_from_IBasicVideo(iface
);
794 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppvObj
);
796 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
799 static ULONG WINAPI
BasicVideo_AddRef(IBasicVideo
*iface
)
801 VideoRendererImpl
*This
= impl_from_IBasicVideo(iface
);
803 TRACE("(%p/%p)->()\n", This
, iface
);
805 return IUnknown_AddRef(This
->outer_unk
);
808 static ULONG WINAPI
BasicVideo_Release(IBasicVideo
*iface
)
810 VideoRendererImpl
*This
= impl_from_IBasicVideo(iface
);
812 TRACE("(%p/%p)->()\n", This
, iface
);
814 return IUnknown_Release(This
->outer_unk
);
817 static const IBasicVideoVtbl IBasicVideo_VTable
=
819 BasicVideo_QueryInterface
,
822 BaseControlVideoImpl_GetTypeInfoCount
,
823 BaseControlVideoImpl_GetTypeInfo
,
824 BaseControlVideoImpl_GetIDsOfNames
,
825 BaseControlVideoImpl_Invoke
,
826 BaseControlVideoImpl_get_AvgTimePerFrame
,
827 BaseControlVideoImpl_get_BitRate
,
828 BaseControlVideoImpl_get_BitErrorRate
,
829 BaseControlVideoImpl_get_VideoWidth
,
830 BaseControlVideoImpl_get_VideoHeight
,
831 BaseControlVideoImpl_put_SourceLeft
,
832 BaseControlVideoImpl_get_SourceLeft
,
833 BaseControlVideoImpl_put_SourceWidth
,
834 BaseControlVideoImpl_get_SourceWidth
,
835 BaseControlVideoImpl_put_SourceTop
,
836 BaseControlVideoImpl_get_SourceTop
,
837 BaseControlVideoImpl_put_SourceHeight
,
838 BaseControlVideoImpl_get_SourceHeight
,
839 BaseControlVideoImpl_put_DestinationLeft
,
840 BaseControlVideoImpl_get_DestinationLeft
,
841 BaseControlVideoImpl_put_DestinationWidth
,
842 BaseControlVideoImpl_get_DestinationWidth
,
843 BaseControlVideoImpl_put_DestinationTop
,
844 BaseControlVideoImpl_get_DestinationTop
,
845 BaseControlVideoImpl_put_DestinationHeight
,
846 BaseControlVideoImpl_get_DestinationHeight
,
847 BaseControlVideoImpl_SetSourcePosition
,
848 BaseControlVideoImpl_GetSourcePosition
,
849 BaseControlVideoImpl_SetDefaultSourcePosition
,
850 BaseControlVideoImpl_SetDestinationPosition
,
851 BaseControlVideoImpl_GetDestinationPosition
,
852 BaseControlVideoImpl_SetDefaultDestinationPosition
,
853 BaseControlVideoImpl_GetVideoSize
,
854 BaseControlVideoImpl_GetVideoPaletteEntries
,
855 BaseControlVideoImpl_GetCurrentImage
,
856 BaseControlVideoImpl_IsUsingDefaultSource
,
857 BaseControlVideoImpl_IsUsingDefaultDestination
861 /*** IUnknown methods ***/
862 static HRESULT WINAPI
VideoWindow_QueryInterface(IVideoWindow
*iface
, REFIID riid
, LPVOID
*ppvObj
)
864 VideoRendererImpl
*This
= impl_from_IVideoWindow(iface
);
866 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppvObj
);
868 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppvObj
);
871 static ULONG WINAPI
VideoWindow_AddRef(IVideoWindow
*iface
)
873 VideoRendererImpl
*This
= impl_from_IVideoWindow(iface
);
875 TRACE("(%p/%p)->()\n", This
, iface
);
877 return IUnknown_AddRef(This
->outer_unk
);
880 static ULONG WINAPI
VideoWindow_Release(IVideoWindow
*iface
)
882 VideoRendererImpl
*This
= impl_from_IVideoWindow(iface
);
884 TRACE("(%p/%p)->()\n", This
, iface
);
886 return IUnknown_Release(This
->outer_unk
);
889 static HRESULT WINAPI
VideoWindow_get_FullScreenMode(IVideoWindow
*iface
,
890 LONG
*FullScreenMode
)
892 VideoRendererImpl
*This
= impl_from_IVideoWindow(iface
);
894 TRACE("(%p/%p)->(%p): %d\n", This
, iface
, FullScreenMode
, This
->FullScreenMode
);
899 *FullScreenMode
= This
->FullScreenMode
;
904 static HRESULT WINAPI
VideoWindow_put_FullScreenMode(IVideoWindow
*iface
,
907 VideoRendererImpl
*This
= impl_from_IVideoWindow(iface
);
909 FIXME("(%p/%p)->(%d): stub !!!\n", This
, iface
, FullScreenMode
);
911 if (FullScreenMode
) {
912 This
->baseControlWindow
.baseWindow
.WindowStyles
= GetWindowLongW(This
->baseControlWindow
.baseWindow
.hWnd
, GWL_STYLE
);
913 ShowWindow(This
->baseControlWindow
.baseWindow
.hWnd
, SW_HIDE
);
914 SetParent(This
->baseControlWindow
.baseWindow
.hWnd
, 0);
915 SetWindowLongW(This
->baseControlWindow
.baseWindow
.hWnd
, GWL_STYLE
, WS_POPUP
);
916 SetWindowPos(This
->baseControlWindow
.baseWindow
.hWnd
,HWND_TOP
,0,0,GetSystemMetrics(SM_CXSCREEN
),GetSystemMetrics(SM_CYSCREEN
),SWP_SHOWWINDOW
);
917 GetWindowRect(This
->baseControlWindow
.baseWindow
.hWnd
, &This
->DestRect
);
918 This
->WindowPos
= This
->DestRect
;
920 ShowWindow(This
->baseControlWindow
.baseWindow
.hWnd
, SW_HIDE
);
921 SetParent(This
->baseControlWindow
.baseWindow
.hWnd
, This
->baseControlWindow
.hwndOwner
);
922 SetWindowLongW(This
->baseControlWindow
.baseWindow
.hWnd
, GWL_STYLE
, This
->baseControlWindow
.baseWindow
.WindowStyles
);
923 GetClientRect(This
->baseControlWindow
.baseWindow
.hWnd
, &This
->DestRect
);
924 SetWindowPos(This
->baseControlWindow
.baseWindow
.hWnd
,0,This
->DestRect
.left
,This
->DestRect
.top
,This
->DestRect
.right
,This
->DestRect
.bottom
,SWP_NOZORDER
|SWP_SHOWWINDOW
);
925 This
->WindowPos
= This
->DestRect
;
927 This
->FullScreenMode
= FullScreenMode
;
932 static const IVideoWindowVtbl IVideoWindow_VTable
=
934 VideoWindow_QueryInterface
,
937 BaseControlWindowImpl_GetTypeInfoCount
,
938 BaseControlWindowImpl_GetTypeInfo
,
939 BaseControlWindowImpl_GetIDsOfNames
,
940 BaseControlWindowImpl_Invoke
,
941 BaseControlWindowImpl_put_Caption
,
942 BaseControlWindowImpl_get_Caption
,
943 BaseControlWindowImpl_put_WindowStyle
,
944 BaseControlWindowImpl_get_WindowStyle
,
945 BaseControlWindowImpl_put_WindowStyleEx
,
946 BaseControlWindowImpl_get_WindowStyleEx
,
947 BaseControlWindowImpl_put_AutoShow
,
948 BaseControlWindowImpl_get_AutoShow
,
949 BaseControlWindowImpl_put_WindowState
,
950 BaseControlWindowImpl_get_WindowState
,
951 BaseControlWindowImpl_put_BackgroundPalette
,
952 BaseControlWindowImpl_get_BackgroundPalette
,
953 BaseControlWindowImpl_put_Visible
,
954 BaseControlWindowImpl_get_Visible
,
955 BaseControlWindowImpl_put_Left
,
956 BaseControlWindowImpl_get_Left
,
957 BaseControlWindowImpl_put_Width
,
958 BaseControlWindowImpl_get_Width
,
959 BaseControlWindowImpl_put_Top
,
960 BaseControlWindowImpl_get_Top
,
961 BaseControlWindowImpl_put_Height
,
962 BaseControlWindowImpl_get_Height
,
963 BaseControlWindowImpl_put_Owner
,
964 BaseControlWindowImpl_get_Owner
,
965 BaseControlWindowImpl_put_MessageDrain
,
966 BaseControlWindowImpl_get_MessageDrain
,
967 BaseControlWindowImpl_get_BorderColor
,
968 BaseControlWindowImpl_put_BorderColor
,
969 VideoWindow_get_FullScreenMode
,
970 VideoWindow_put_FullScreenMode
,
971 BaseControlWindowImpl_SetWindowForeground
,
972 BaseControlWindowImpl_NotifyOwnerMessage
,
973 BaseControlWindowImpl_SetWindowPosition
,
974 BaseControlWindowImpl_GetWindowPosition
,
975 BaseControlWindowImpl_GetMinIdealImageSize
,
976 BaseControlWindowImpl_GetMaxIdealImageSize
,
977 BaseControlWindowImpl_GetRestorePosition
,
978 BaseControlWindowImpl_HideCursor
,
979 BaseControlWindowImpl_IsCursorHidden
982 static VideoRendererImpl
*impl_from_IAMFilterMiscFlags(IAMFilterMiscFlags
*iface
)
984 return CONTAINING_RECORD(iface
, VideoRendererImpl
, IAMFilterMiscFlags_iface
);
987 static HRESULT WINAPI
AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags
*iface
, REFIID riid
,
990 VideoRendererImpl
*This
= impl_from_IAMFilterMiscFlags(iface
);
991 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
994 static ULONG WINAPI
AMFilterMiscFlags_AddRef(IAMFilterMiscFlags
*iface
)
996 VideoRendererImpl
*This
= impl_from_IAMFilterMiscFlags(iface
);
997 return IUnknown_AddRef(This
->outer_unk
);
1000 static ULONG WINAPI
AMFilterMiscFlags_Release(IAMFilterMiscFlags
*iface
)
1002 VideoRendererImpl
*This
= impl_from_IAMFilterMiscFlags(iface
);
1003 return IUnknown_Release(This
->outer_unk
);
1006 static ULONG WINAPI
AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags
*iface
)
1008 return AM_FILTER_MISC_FLAGS_IS_RENDERER
;
1011 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl
= {
1012 AMFilterMiscFlags_QueryInterface
,
1013 AMFilterMiscFlags_AddRef
,
1014 AMFilterMiscFlags_Release
,
1015 AMFilterMiscFlags_GetMiscFlags
1018 HRESULT
VideoRenderer_create(IUnknown
*pUnkOuter
, void **ppv
)
1021 VideoRendererImpl
* pVideoRenderer
;
1023 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
1027 pVideoRenderer
= CoTaskMemAlloc(sizeof(VideoRendererImpl
));
1028 pVideoRenderer
->IUnknown_inner
.lpVtbl
= &IInner_VTable
;
1029 pVideoRenderer
->IAMFilterMiscFlags_iface
.lpVtbl
= &IAMFilterMiscFlags_Vtbl
;
1031 pVideoRenderer
->init
= FALSE
;
1032 ZeroMemory(&pVideoRenderer
->SourceRect
, sizeof(RECT
));
1033 ZeroMemory(&pVideoRenderer
->DestRect
, sizeof(RECT
));
1034 ZeroMemory(&pVideoRenderer
->WindowPos
, sizeof(RECT
));
1035 pVideoRenderer
->FullScreenMode
= OAFALSE
;
1038 pVideoRenderer
->outer_unk
= pUnkOuter
;
1040 pVideoRenderer
->outer_unk
= &pVideoRenderer
->IUnknown_inner
;
1042 hr
= BaseRenderer_Init(&pVideoRenderer
->renderer
, &VideoRenderer_Vtbl
, pUnkOuter
,
1043 &CLSID_VideoRenderer
, (DWORD_PTR
)(__FILE__
": VideoRendererImpl.csFilter"),
1049 hr
= BaseControlWindow_Init(&pVideoRenderer
->baseControlWindow
, &IVideoWindow_VTable
,
1050 &pVideoRenderer
->renderer
.filter
, &pVideoRenderer
->renderer
.filter
.csFilter
,
1051 &pVideoRenderer
->renderer
.pInputPin
->pin
, &renderer_BaseWindowFuncTable
);
1055 hr
= BaseControlVideo_Init(&pVideoRenderer
->baseControlVideo
, &IBasicVideo_VTable
,
1056 &pVideoRenderer
->renderer
.filter
, &pVideoRenderer
->renderer
.filter
.csFilter
,
1057 &pVideoRenderer
->renderer
.pInputPin
->pin
, &renderer_BaseControlVideoFuncTable
);
1061 if (!CreateRenderingSubsystem(pVideoRenderer
)) {
1066 *ppv
= &pVideoRenderer
->IUnknown_inner
;
1070 BaseRendererImpl_Release(&pVideoRenderer
->renderer
.filter
.IBaseFilter_iface
);
1071 CoTaskMemFree(pVideoRenderer
);
1075 HRESULT
VideoRendererDefault_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
1077 /* TODO: Attempt to use the VMR-7 renderer instead when possible */
1078 return VideoRenderer_create(pUnkOuter
, ppv
);