2 * Null Renderer (Promiscuous, not rendering anything at all!)
4 * Copyright 2004 Christian Costa
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26 #include "quartz_private.h"
27 #include "control_private.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
45 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
46 static const WCHAR wcsAltInputPinName
[] = {'I','n',0};
48 static const IBaseFilterVtbl NullRenderer_Vtbl
;
49 static const IUnknownVtbl IInner_VTable
;
50 static const IPinVtbl NullRenderer_InputPin_Vtbl
;
52 typedef struct NullRendererImpl
54 const IBaseFilterVtbl
* lpVtbl
;
55 const IUnknownVtbl
* IInner_vtbl
;
56 IUnknown
*seekthru_unk
;
59 CRITICAL_SECTION csFilter
;
61 REFERENCE_TIME rtStreamStart
;
62 IReferenceClock
* pClock
;
63 FILTER_INFO filterInfo
;
71 static HRESULT
NullRenderer_Sample(LPVOID iface
, IMediaSample
* pSample
)
73 NullRendererImpl
*This
= iface
;
75 REFERENCE_TIME start
, stop
;
77 TRACE("%p %p\n", iface
, pSample
);
79 if (SUCCEEDED(IMediaSample_GetTime(pSample
, &start
, &stop
)))
80 MediaSeekingPassThru_RegisterMediaTime(This
->seekthru_unk
, start
);
81 EnterCriticalSection(&This
->csFilter
);
82 if (This
->pInputPin
->flushing
|| This
->pInputPin
->end_of_stream
)
84 LeaveCriticalSection(&This
->csFilter
);
89 static HRESULT
NullRenderer_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
91 TRACE("Not a stub!\n");
95 HRESULT
NullRenderer_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
99 NullRendererImpl
* pNullRenderer
;
101 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
105 pNullRenderer
= CoTaskMemAlloc(sizeof(NullRendererImpl
));
106 pNullRenderer
->pUnkOuter
= pUnkOuter
;
107 pNullRenderer
->bUnkOuterValid
= FALSE
;
108 pNullRenderer
->bAggregatable
= FALSE
;
109 pNullRenderer
->IInner_vtbl
= &IInner_VTable
;
111 pNullRenderer
->lpVtbl
= &NullRenderer_Vtbl
;
112 pNullRenderer
->refCount
= 1;
113 InitializeCriticalSection(&pNullRenderer
->csFilter
);
114 pNullRenderer
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": NullRendererImpl.csFilter");
115 pNullRenderer
->state
= State_Stopped
;
116 pNullRenderer
->pClock
= NULL
;
117 ZeroMemory(&pNullRenderer
->filterInfo
, sizeof(FILTER_INFO
));
119 /* construct input pin */
120 piInput
.dir
= PINDIR_INPUT
;
121 piInput
.pFilter
= (IBaseFilter
*)pNullRenderer
;
122 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
124 hr
= InputPin_Construct(&NullRenderer_InputPin_Vtbl
, &piInput
, NullRenderer_Sample
, (LPVOID
)pNullRenderer
, NullRenderer_QueryAccept
, NULL
, &pNullRenderer
->csFilter
, NULL
, (IPin
**)&pNullRenderer
->pInputPin
);
128 ISeekingPassThru
*passthru
;
129 hr
= CoCreateInstance(&CLSID_SeekingPassThru
, pUnkOuter
? pUnkOuter
: (IUnknown
*)&pNullRenderer
->IInner_vtbl
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void**)&pNullRenderer
->seekthru_unk
);
131 IUnknown_Release((IUnknown
*)pNullRenderer
);
134 IUnknown_QueryInterface(pNullRenderer
->seekthru_unk
, &IID_ISeekingPassThru
, (void**)&passthru
);
135 ISeekingPassThru_Init(passthru
, TRUE
, (IPin
*)pNullRenderer
->pInputPin
);
136 ISeekingPassThru_Release(passthru
);
137 *ppv
= pNullRenderer
;
141 pNullRenderer
->csFilter
.DebugInfo
->Spare
[0] = 0;
142 DeleteCriticalSection(&pNullRenderer
->csFilter
);
143 CoTaskMemFree(pNullRenderer
);
149 static HRESULT WINAPI
NullRendererInner_QueryInterface(IUnknown
* iface
, REFIID riid
, LPVOID
* ppv
)
151 ICOM_THIS_MULTI(NullRendererImpl
, IInner_vtbl
, iface
);
152 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
154 if (This
->bAggregatable
)
155 This
->bUnkOuterValid
= TRUE
;
159 if (IsEqualIID(riid
, &IID_IUnknown
))
160 *ppv
= &This
->IInner_vtbl
;
161 else if (IsEqualIID(riid
, &IID_IPersist
))
163 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
165 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
167 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
168 return IUnknown_QueryInterface(This
->seekthru_unk
, riid
, ppv
);
172 IUnknown_AddRef((IUnknown
*)(*ppv
));
176 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
177 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
179 return E_NOINTERFACE
;
182 static ULONG WINAPI
NullRendererInner_AddRef(IUnknown
* iface
)
184 ICOM_THIS_MULTI(NullRendererImpl
, IInner_vtbl
, iface
);
185 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
187 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
192 static ULONG WINAPI
NullRendererInner_Release(IUnknown
* iface
)
194 ICOM_THIS_MULTI(NullRendererImpl
, IInner_vtbl
, iface
);
195 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
197 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
204 IReferenceClock_Release(This
->pClock
);
206 if (SUCCEEDED(IPin_ConnectedTo((IPin
*)This
->pInputPin
, &pConnectedTo
)))
208 IPin_Disconnect(pConnectedTo
);
209 IPin_Release(pConnectedTo
);
211 IPin_Disconnect((IPin
*)This
->pInputPin
);
212 IPin_Release((IPin
*)This
->pInputPin
);
215 if (This
->seekthru_unk
)
216 IUnknown_Release(This
->seekthru_unk
);
218 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
219 DeleteCriticalSection(&This
->csFilter
);
221 TRACE("Destroying Null Renderer\n");
229 static const IUnknownVtbl IInner_VTable
=
231 NullRendererInner_QueryInterface
,
232 NullRendererInner_AddRef
,
233 NullRendererInner_Release
236 static HRESULT WINAPI
NullRenderer_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
238 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
240 if (This
->bAggregatable
)
241 This
->bUnkOuterValid
= TRUE
;
245 if (This
->bAggregatable
)
246 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppv
);
248 if (IsEqualIID(riid
, &IID_IUnknown
))
252 IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
253 hr
= IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
254 IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
255 This
->bAggregatable
= TRUE
;
260 return E_NOINTERFACE
;
263 return IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
266 static ULONG WINAPI
NullRenderer_AddRef(IBaseFilter
* iface
)
268 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
270 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
271 return IUnknown_AddRef(This
->pUnkOuter
);
272 return IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
275 static ULONG WINAPI
NullRenderer_Release(IBaseFilter
* iface
)
277 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
279 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
280 return IUnknown_Release(This
->pUnkOuter
);
281 return IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
284 /** IPersist methods **/
286 static HRESULT WINAPI
NullRenderer_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
288 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
290 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
292 *pClsid
= CLSID_NullRenderer
;
297 /** IMediaFilter methods **/
299 static HRESULT WINAPI
NullRenderer_Stop(IBaseFilter
* iface
)
301 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
303 TRACE("(%p/%p)->()\n", This
, iface
);
305 EnterCriticalSection(&This
->csFilter
);
307 This
->state
= State_Stopped
;
308 MediaSeekingPassThru_ResetMediaTime(This
->seekthru_unk
);
310 LeaveCriticalSection(&This
->csFilter
);
315 static HRESULT WINAPI
NullRenderer_Pause(IBaseFilter
* iface
)
317 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
319 TRACE("(%p/%p)->()\n", This
, iface
);
321 EnterCriticalSection(&This
->csFilter
);
323 if (This
->state
== State_Stopped
)
324 This
->pInputPin
->end_of_stream
= 0;
325 This
->state
= State_Paused
;
327 LeaveCriticalSection(&This
->csFilter
);
332 static HRESULT WINAPI
NullRenderer_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
334 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
336 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
338 EnterCriticalSection(&This
->csFilter
);
340 This
->rtStreamStart
= tStart
;
341 This
->state
= State_Running
;
342 This
->pInputPin
->end_of_stream
= 0;
344 LeaveCriticalSection(&This
->csFilter
);
349 static HRESULT WINAPI
NullRenderer_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
351 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
353 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
355 EnterCriticalSection(&This
->csFilter
);
357 *pState
= This
->state
;
359 LeaveCriticalSection(&This
->csFilter
);
364 static HRESULT WINAPI
NullRenderer_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
366 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
368 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
370 EnterCriticalSection(&This
->csFilter
);
373 IReferenceClock_Release(This
->pClock
);
374 This
->pClock
= pClock
;
376 IReferenceClock_AddRef(This
->pClock
);
378 LeaveCriticalSection(&This
->csFilter
);
383 static HRESULT WINAPI
NullRenderer_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
385 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
387 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
389 EnterCriticalSection(&This
->csFilter
);
391 *ppClock
= This
->pClock
;
393 IReferenceClock_AddRef(This
->pClock
);
395 LeaveCriticalSection(&This
->csFilter
);
400 /** IBaseFilter implementation **/
402 static HRESULT
NullRenderer_GetPin(IBaseFilter
*iface
, ULONG pos
, IPin
**pin
, DWORD
*lastsynctick
)
404 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
406 /* Our pins are static, not changing so setting static tick count is ok */
412 *pin
= (IPin
*)This
->pInputPin
;
417 static HRESULT WINAPI
NullRenderer_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
419 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
421 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
423 return IEnumPinsImpl_Construct(ppEnum
, NullRenderer_GetPin
, iface
);
426 static HRESULT WINAPI
NullRenderer_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
428 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
430 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
435 if (!lstrcmpiW(Id
,wcsInputPinName
) || !lstrcmpiW(Id
,wcsAltInputPinName
))
437 *ppPin
= (IPin
*)This
->pInputPin
;
442 return VFW_E_NOT_FOUND
;
445 static HRESULT WINAPI
NullRenderer_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
447 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
449 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
451 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
452 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
455 IFilterGraph_AddRef(pInfo
->pGraph
);
460 static HRESULT WINAPI
NullRenderer_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
462 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
464 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
466 EnterCriticalSection(&This
->csFilter
);
469 strcpyW(This
->filterInfo
.achName
, pName
);
471 *This
->filterInfo
.achName
= '\0';
472 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
474 LeaveCriticalSection(&This
->csFilter
);
479 static HRESULT WINAPI
NullRenderer_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
481 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
482 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
486 static const IBaseFilterVtbl NullRenderer_Vtbl
=
488 NullRenderer_QueryInterface
,
490 NullRenderer_Release
,
491 NullRenderer_GetClassID
,
495 NullRenderer_GetState
,
496 NullRenderer_SetSyncSource
,
497 NullRenderer_GetSyncSource
,
498 NullRenderer_EnumPins
,
499 NullRenderer_FindPin
,
500 NullRenderer_QueryFilterInfo
,
501 NullRenderer_JoinFilterGraph
,
502 NullRenderer_QueryVendorInfo
505 static HRESULT WINAPI
NullRenderer_InputPin_EndOfStream(IPin
* iface
)
507 InputPin
* This
= (InputPin
*)iface
;
508 IMediaEventSink
* pEventSink
;
509 NullRendererImpl
*pNull
;
513 TRACE("(%p/%p)->()\n", This
, iface
);
515 InputPin_EndOfStream(iface
);
516 pNull
= (NullRendererImpl
*)This
->pin
.pinInfo
.pFilter
;
517 graph
= pNull
->filterInfo
.pGraph
;
520 hr
= IFilterGraph_QueryInterface(((NullRendererImpl
*)This
->pin
.pinInfo
.pFilter
)->filterInfo
.pGraph
, &IID_IMediaEventSink
, (LPVOID
*)&pEventSink
);
523 hr
= IMediaEventSink_Notify(pEventSink
, EC_COMPLETE
, S_OK
, 0);
524 IMediaEventSink_Release(pEventSink
);
527 MediaSeekingPassThru_EOS(pNull
->seekthru_unk
);
532 static HRESULT WINAPI
NullRenderer_InputPin_EndFlush(IPin
* iface
)
534 InputPin
* This
= (InputPin
*)iface
;
535 NullRendererImpl
*pNull
;
538 TRACE("(%p/%p)->()\n", This
, iface
);
540 hr
= InputPin_EndOfStream(iface
);
541 pNull
= (NullRendererImpl
*)This
->pin
.pinInfo
.pFilter
;
542 MediaSeekingPassThru_ResetMediaTime(pNull
->seekthru_unk
);
546 static const IPinVtbl NullRenderer_InputPin_Vtbl
=
548 InputPin_QueryInterface
,
552 InputPin_ReceiveConnection
,
554 IPinImpl_ConnectedTo
,
555 IPinImpl_ConnectionMediaType
,
556 IPinImpl_QueryPinInfo
,
557 IPinImpl_QueryDirection
,
559 IPinImpl_QueryAccept
,
560 IPinImpl_EnumMediaTypes
,
561 IPinImpl_QueryInternalConnections
,
562 NullRenderer_InputPin_EndOfStream
,
564 NullRenderer_InputPin_EndFlush
,