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};
47 static const IBaseFilterVtbl NullRenderer_Vtbl;
48 static const IUnknownVtbl IInner_VTable;
49 static const IPinVtbl NullRenderer_InputPin_Vtbl;
51 typedef struct NullRendererImpl
53 const IBaseFilterVtbl * lpVtbl;
54 const IUnknownVtbl * IInner_vtbl;
57 CRITICAL_SECTION csFilter;
59 REFERENCE_TIME rtStreamStart;
60 IReferenceClock * pClock;
61 FILTER_INFO filterInfo;
67 MediaSeekingImpl mediaSeeking;
70 static const IMemInputPinVtbl MemInputPin_Vtbl =
72 MemInputPin_QueryInterface,
75 MemInputPin_GetAllocator,
76 MemInputPin_NotifyAllocator,
77 MemInputPin_GetAllocatorRequirements,
79 MemInputPin_ReceiveMultiple,
80 MemInputPin_ReceiveCanBlock
83 static HRESULT NullRenderer_Sample(LPVOID iface, IMediaSample * pSample)
85 NullRendererImpl *This = (NullRendererImpl *)iface;
88 TRACE("%p %p\n", iface, pSample);
90 EnterCriticalSection(&This->csFilter);
91 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
93 LeaveCriticalSection(&This->csFilter);
98 static HRESULT NullRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
100 TRACE("Not a stub!\n");
104 static inline NullRendererImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
106 return (NullRendererImpl *)((char*)iface - FIELD_OFFSET(NullRendererImpl, mediaSeeking.lpVtbl));
109 static HRESULT WINAPI NullRendererImpl_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
111 NullRendererImpl *This = impl_from_IMediaSeeking(iface);
113 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
116 static ULONG WINAPI NullRendererImpl_Seeking_AddRef(IMediaSeeking * iface)
118 NullRendererImpl *This = impl_from_IMediaSeeking(iface);
120 return IUnknown_AddRef((IUnknown *)This);
123 static ULONG WINAPI NullRendererImpl_Seeking_Release(IMediaSeeking * iface)
125 NullRendererImpl *This = impl_from_IMediaSeeking(iface);
127 return IUnknown_Release((IUnknown *)This);
130 static const IMediaSeekingVtbl TransformFilter_Seeking_Vtbl =
132 NullRendererImpl_Seeking_QueryInterface,
133 NullRendererImpl_Seeking_AddRef,
134 NullRendererImpl_Seeking_Release,
135 MediaSeekingImpl_GetCapabilities,
136 MediaSeekingImpl_CheckCapabilities,
137 MediaSeekingImpl_IsFormatSupported,
138 MediaSeekingImpl_QueryPreferredFormat,
139 MediaSeekingImpl_GetTimeFormat,
140 MediaSeekingImpl_IsUsingTimeFormat,
141 MediaSeekingImpl_SetTimeFormat,
142 MediaSeekingImpl_GetDuration,
143 MediaSeekingImpl_GetStopPosition,
144 MediaSeekingImpl_GetCurrentPosition,
145 MediaSeekingImpl_ConvertTimeFormat,
146 MediaSeekingImpl_SetPositions,
147 MediaSeekingImpl_GetPositions,
148 MediaSeekingImpl_GetAvailable,
149 MediaSeekingImpl_SetRate,
150 MediaSeekingImpl_GetRate,
151 MediaSeekingImpl_GetPreroll
154 static HRESULT NullRendererImpl_Change(IBaseFilter *iface)
156 TRACE("(%p)\n", iface);
160 HRESULT NullRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
164 NullRendererImpl * pNullRenderer;
166 TRACE("(%p, %p)\n", pUnkOuter, ppv);
170 pNullRenderer = CoTaskMemAlloc(sizeof(NullRendererImpl));
171 pNullRenderer->pUnkOuter = pUnkOuter;
172 pNullRenderer->bUnkOuterValid = FALSE;
173 pNullRenderer->bAggregatable = FALSE;
174 pNullRenderer->IInner_vtbl = &IInner_VTable;
176 pNullRenderer->lpVtbl = &NullRenderer_Vtbl;
177 pNullRenderer->refCount = 1;
178 InitializeCriticalSection(&pNullRenderer->csFilter);
179 pNullRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": NullRendererImpl.csFilter");
180 pNullRenderer->state = State_Stopped;
181 pNullRenderer->pClock = NULL;
182 ZeroMemory(&pNullRenderer->filterInfo, sizeof(FILTER_INFO));
184 /* construct input pin */
185 piInput.dir = PINDIR_INPUT;
186 piInput.pFilter = (IBaseFilter *)pNullRenderer;
187 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
189 hr = InputPin_Construct(&NullRenderer_InputPin_Vtbl, &piInput, NullRenderer_Sample, (LPVOID)pNullRenderer, NullRenderer_QueryAccept, NULL, &pNullRenderer->csFilter, NULL, (IPin **)&pNullRenderer->pInputPin);
193 MediaSeekingImpl_Init((IBaseFilter*)pNullRenderer, NullRendererImpl_Change, NullRendererImpl_Change, NullRendererImpl_Change, &pNullRenderer->mediaSeeking, &pNullRenderer->csFilter);
194 pNullRenderer->mediaSeeking.lpVtbl = &TransformFilter_Seeking_Vtbl;
196 *ppv = (LPVOID)pNullRenderer;
200 pNullRenderer->csFilter.DebugInfo->Spare[0] = 0;
201 DeleteCriticalSection(&pNullRenderer->csFilter);
202 CoTaskMemFree(pNullRenderer);
208 static HRESULT WINAPI NullRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
210 ICOM_THIS_MULTI(NullRendererImpl, IInner_vtbl, iface);
211 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
213 if (This->bAggregatable)
214 This->bUnkOuterValid = TRUE;
218 if (IsEqualIID(riid, &IID_IUnknown))
219 *ppv = (LPVOID)&(This->IInner_vtbl);
220 else if (IsEqualIID(riid, &IID_IPersist))
222 else if (IsEqualIID(riid, &IID_IMediaFilter))
224 else if (IsEqualIID(riid, &IID_IBaseFilter))
226 else if (IsEqualIID(riid, &IID_IMediaSeeking))
227 *ppv = &This->mediaSeeking;
231 IUnknown_AddRef((IUnknown *)(*ppv));
235 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
236 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
238 return E_NOINTERFACE;
241 static ULONG WINAPI NullRendererInner_AddRef(IUnknown * iface)
243 ICOM_THIS_MULTI(NullRendererImpl, IInner_vtbl, iface);
244 ULONG refCount = InterlockedIncrement(&This->refCount);
246 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
251 static ULONG WINAPI NullRendererInner_Release(IUnknown * iface)
253 ICOM_THIS_MULTI(NullRendererImpl, IInner_vtbl, iface);
254 ULONG refCount = InterlockedDecrement(&This->refCount);
256 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
263 IReferenceClock_Release(This->pClock);
265 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
267 IPin_Disconnect(pConnectedTo);
268 IPin_Release(pConnectedTo);
270 IPin_Disconnect((IPin *)This->pInputPin);
271 IPin_Release((IPin *)This->pInputPin);
275 This->csFilter.DebugInfo->Spare[0] = 0;
276 DeleteCriticalSection(&This->csFilter);
278 TRACE("Destroying Null Renderer\n");
286 static const IUnknownVtbl IInner_VTable =
288 NullRendererInner_QueryInterface,
289 NullRendererInner_AddRef,
290 NullRendererInner_Release
293 static HRESULT WINAPI NullRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
295 NullRendererImpl *This = (NullRendererImpl *)iface;
297 if (This->bAggregatable)
298 This->bUnkOuterValid = TRUE;
302 if (This->bAggregatable)
303 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
305 if (IsEqualIID(riid, &IID_IUnknown))
309 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
310 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
311 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
312 This->bAggregatable = TRUE;
317 return E_NOINTERFACE;
320 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
323 static ULONG WINAPI NullRenderer_AddRef(IBaseFilter * iface)
325 NullRendererImpl *This = (NullRendererImpl *)iface;
327 if (This->pUnkOuter && This->bUnkOuterValid)
328 return IUnknown_AddRef(This->pUnkOuter);
329 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
332 static ULONG WINAPI NullRenderer_Release(IBaseFilter * iface)
334 NullRendererImpl *This = (NullRendererImpl *)iface;
336 if (This->pUnkOuter && This->bUnkOuterValid)
337 return IUnknown_Release(This->pUnkOuter);
338 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
341 /** IPersist methods **/
343 static HRESULT WINAPI NullRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
345 NullRendererImpl *This = (NullRendererImpl *)iface;
347 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
349 *pClsid = CLSID_NullRenderer;
354 /** IMediaFilter methods **/
356 static HRESULT WINAPI NullRenderer_Stop(IBaseFilter * iface)
358 NullRendererImpl *This = (NullRendererImpl *)iface;
360 TRACE("(%p/%p)->()\n", This, iface);
362 EnterCriticalSection(&This->csFilter);
364 This->state = State_Stopped;
366 LeaveCriticalSection(&This->csFilter);
371 static HRESULT WINAPI NullRenderer_Pause(IBaseFilter * iface)
373 NullRendererImpl *This = (NullRendererImpl *)iface;
375 TRACE("(%p/%p)->()\n", This, iface);
377 EnterCriticalSection(&This->csFilter);
379 if (This->state == State_Stopped)
380 This->pInputPin->end_of_stream = 0;
381 This->state = State_Paused;
383 LeaveCriticalSection(&This->csFilter);
388 static HRESULT WINAPI NullRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
390 NullRendererImpl *This = (NullRendererImpl *)iface;
392 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
394 EnterCriticalSection(&This->csFilter);
396 This->rtStreamStart = tStart;
397 This->state = State_Running;
398 This->pInputPin->end_of_stream = 0;
400 LeaveCriticalSection(&This->csFilter);
405 static HRESULT WINAPI NullRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
407 NullRendererImpl *This = (NullRendererImpl *)iface;
409 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
411 EnterCriticalSection(&This->csFilter);
413 *pState = This->state;
415 LeaveCriticalSection(&This->csFilter);
420 static HRESULT WINAPI NullRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
422 NullRendererImpl *This = (NullRendererImpl *)iface;
424 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
426 EnterCriticalSection(&This->csFilter);
429 IReferenceClock_Release(This->pClock);
430 This->pClock = pClock;
432 IReferenceClock_AddRef(This->pClock);
434 LeaveCriticalSection(&This->csFilter);
439 static HRESULT WINAPI NullRenderer_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
441 NullRendererImpl *This = (NullRendererImpl *)iface;
443 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
445 EnterCriticalSection(&This->csFilter);
447 *ppClock = This->pClock;
449 IReferenceClock_AddRef(This->pClock);
451 LeaveCriticalSection(&This->csFilter);
456 /** IBaseFilter implementation **/
458 static HRESULT NullRenderer_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
460 NullRendererImpl *This = (NullRendererImpl *)iface;
462 /* Our pins are static, not changing so setting static tick count is ok */
468 *pin = (IPin *)This->pInputPin;
473 static HRESULT WINAPI NullRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
475 NullRendererImpl *This = (NullRendererImpl *)iface;
477 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
479 return IEnumPinsImpl_Construct(ppEnum, NullRenderer_GetPin, iface);
482 static HRESULT WINAPI NullRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
484 NullRendererImpl *This = (NullRendererImpl *)iface;
486 TRACE("(%p/%p)->(%p,%p)\n", This, iface, debugstr_w(Id), ppPin);
488 FIXME("NullRenderer::FindPin(...)\n");
490 /* FIXME: critical section */
495 static HRESULT WINAPI NullRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
497 NullRendererImpl *This = (NullRendererImpl *)iface;
499 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
501 strcpyW(pInfo->achName, This->filterInfo.achName);
502 pInfo->pGraph = This->filterInfo.pGraph;
505 IFilterGraph_AddRef(pInfo->pGraph);
510 static HRESULT WINAPI NullRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
512 NullRendererImpl *This = (NullRendererImpl *)iface;
514 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
516 EnterCriticalSection(&This->csFilter);
519 strcpyW(This->filterInfo.achName, pName);
521 *This->filterInfo.achName = '\0';
522 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
524 LeaveCriticalSection(&This->csFilter);
529 static HRESULT WINAPI NullRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
531 NullRendererImpl *This = (NullRendererImpl *)iface;
532 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
536 static const IBaseFilterVtbl NullRenderer_Vtbl =
538 NullRenderer_QueryInterface,
540 NullRenderer_Release,
541 NullRenderer_GetClassID,
545 NullRenderer_GetState,
546 NullRenderer_SetSyncSource,
547 NullRenderer_GetSyncSource,
548 NullRenderer_EnumPins,
549 NullRenderer_FindPin,
550 NullRenderer_QueryFilterInfo,
551 NullRenderer_JoinFilterGraph,
552 NullRenderer_QueryVendorInfo
555 static HRESULT WINAPI NullRenderer_InputPin_EndOfStream(IPin * iface)
557 InputPin* This = (InputPin*)iface;
558 IMediaEventSink* pEventSink;
562 TRACE("(%p/%p)->()\n", This, iface);
564 InputPin_EndOfStream(iface);
565 graph = ((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph;
568 hr = IFilterGraph_QueryInterface(((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
571 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
572 IMediaEventSink_Release(pEventSink);
579 static const IPinVtbl NullRenderer_InputPin_Vtbl =
581 InputPin_QueryInterface,
585 InputPin_ReceiveConnection,
587 IPinImpl_ConnectedTo,
588 IPinImpl_ConnectionMediaType,
589 IPinImpl_QueryPinInfo,
590 IPinImpl_QueryDirection,
592 IPinImpl_QueryAccept,
593 IPinImpl_EnumMediaTypes,
594 IPinImpl_QueryInternalConnections,
595 NullRenderer_InputPin_EndOfStream,