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 IPin* WINAPI NullRenderer_GetPin(IBaseFilter *iface, int pos)
404 NullRendererImpl *This = (NullRendererImpl *)iface;
406 if (pos >= 1 || pos < 0)
409 IPin_AddRef((IPin *)This->pInputPin);
410 return (IPin *)This->pInputPin;
413 static LONG WINAPI NullRenderer_GetPinCount(IBaseFilter *iface)
418 static LONG WINAPI NullRenderer_GetPinVersion(IBaseFilter *iface)
420 /* Our pins are static, not changing so setting static tick count is ok */
424 static HRESULT WINAPI NullRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
426 NullRendererImpl *This = (NullRendererImpl *)iface;
428 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
430 return EnumPins_Construct(iface, NullRenderer_GetPin, NullRenderer_GetPinCount, NullRenderer_GetPinVersion, ppEnum);
433 static HRESULT WINAPI NullRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
435 NullRendererImpl *This = (NullRendererImpl *)iface;
437 TRACE("(%p/%p)->(%p,%p)\n", This, iface, debugstr_w(Id), ppPin);
442 if (!lstrcmpiW(Id,wcsInputPinName) || !lstrcmpiW(Id,wcsAltInputPinName))
444 *ppPin = (IPin *)This->pInputPin;
449 return VFW_E_NOT_FOUND;
452 static HRESULT WINAPI NullRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
454 NullRendererImpl *This = (NullRendererImpl *)iface;
456 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
458 strcpyW(pInfo->achName, This->filterInfo.achName);
459 pInfo->pGraph = This->filterInfo.pGraph;
462 IFilterGraph_AddRef(pInfo->pGraph);
467 static HRESULT WINAPI NullRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
469 NullRendererImpl *This = (NullRendererImpl *)iface;
471 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
473 EnterCriticalSection(&This->csFilter);
476 strcpyW(This->filterInfo.achName, pName);
478 *This->filterInfo.achName = '\0';
479 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
481 LeaveCriticalSection(&This->csFilter);
486 static HRESULT WINAPI NullRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
488 NullRendererImpl *This = (NullRendererImpl *)iface;
489 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
493 static const IBaseFilterVtbl NullRenderer_Vtbl =
495 NullRenderer_QueryInterface,
497 NullRenderer_Release,
498 NullRenderer_GetClassID,
502 NullRenderer_GetState,
503 NullRenderer_SetSyncSource,
504 NullRenderer_GetSyncSource,
505 NullRenderer_EnumPins,
506 NullRenderer_FindPin,
507 NullRenderer_QueryFilterInfo,
508 NullRenderer_JoinFilterGraph,
509 NullRenderer_QueryVendorInfo
512 static HRESULT WINAPI NullRenderer_InputPin_EndOfStream(IPin * iface)
514 InputPin* This = (InputPin*)iface;
515 IMediaEventSink* pEventSink;
516 NullRendererImpl *pNull;
520 TRACE("(%p/%p)->()\n", This, iface);
522 InputPin_EndOfStream(iface);
523 pNull = (NullRendererImpl*)This->pin.pinInfo.pFilter;
524 graph = pNull->filterInfo.pGraph;
527 hr = IFilterGraph_QueryInterface(((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
530 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
531 IMediaEventSink_Release(pEventSink);
534 MediaSeekingPassThru_EOS(pNull->seekthru_unk);
539 static HRESULT WINAPI NullRenderer_InputPin_EndFlush(IPin * iface)
541 InputPin* This = (InputPin*)iface;
542 NullRendererImpl *pNull;
545 TRACE("(%p/%p)->()\n", This, iface);
547 hr = InputPin_EndOfStream(iface);
548 pNull = (NullRendererImpl*)This->pin.pinInfo.pFilter;
549 MediaSeekingPassThru_ResetMediaTime(pNull->seekthru_unk);
553 static const IPinVtbl NullRenderer_InputPin_Vtbl =
555 InputPin_QueryInterface,
559 InputPin_ReceiveConnection,
560 BasePinImpl_Disconnect,
561 BasePinImpl_ConnectedTo,
562 BasePinImpl_ConnectionMediaType,
563 BasePinImpl_QueryPinInfo,
564 BasePinImpl_QueryDirection,
566 InputPin_QueryAccept,
567 BasePinImpl_EnumMediaTypes,
568 BasePinImpl_QueryInternalConnections,
569 NullRenderer_InputPin_EndOfStream,
571 NullRenderer_InputPin_EndFlush,