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 HRESULT
NullRenderer_Sample(LPVOID iface
, IMediaSample
* pSample
)
72 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
75 TRACE("%p %p\n", iface
, pSample
);
77 EnterCriticalSection(&This
->csFilter
);
78 if (This
->pInputPin
->flushing
|| This
->pInputPin
->end_of_stream
)
80 LeaveCriticalSection(&This
->csFilter
);
85 static HRESULT
NullRenderer_QueryAccept(LPVOID iface
, const AM_MEDIA_TYPE
* pmt
)
87 TRACE("Not a stub!\n");
91 static inline NullRendererImpl
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
93 return (NullRendererImpl
*)((char*)iface
- FIELD_OFFSET(NullRendererImpl
, mediaSeeking
.lpVtbl
));
96 static HRESULT WINAPI
NullRendererImpl_Seeking_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
98 NullRendererImpl
*This
= impl_from_IMediaSeeking(iface
);
100 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
103 static ULONG WINAPI
NullRendererImpl_Seeking_AddRef(IMediaSeeking
* iface
)
105 NullRendererImpl
*This
= impl_from_IMediaSeeking(iface
);
107 return IUnknown_AddRef((IUnknown
*)This
);
110 static ULONG WINAPI
NullRendererImpl_Seeking_Release(IMediaSeeking
* iface
)
112 NullRendererImpl
*This
= impl_from_IMediaSeeking(iface
);
114 return IUnknown_Release((IUnknown
*)This
);
117 static const IMediaSeekingVtbl TransformFilter_Seeking_Vtbl
=
119 NullRendererImpl_Seeking_QueryInterface
,
120 NullRendererImpl_Seeking_AddRef
,
121 NullRendererImpl_Seeking_Release
,
122 MediaSeekingImpl_GetCapabilities
,
123 MediaSeekingImpl_CheckCapabilities
,
124 MediaSeekingImpl_IsFormatSupported
,
125 MediaSeekingImpl_QueryPreferredFormat
,
126 MediaSeekingImpl_GetTimeFormat
,
127 MediaSeekingImpl_IsUsingTimeFormat
,
128 MediaSeekingImpl_SetTimeFormat
,
129 MediaSeekingImpl_GetDuration
,
130 MediaSeekingImpl_GetStopPosition
,
131 MediaSeekingImpl_GetCurrentPosition
,
132 MediaSeekingImpl_ConvertTimeFormat
,
133 MediaSeekingImpl_SetPositions
,
134 MediaSeekingImpl_GetPositions
,
135 MediaSeekingImpl_GetAvailable
,
136 MediaSeekingImpl_SetRate
,
137 MediaSeekingImpl_GetRate
,
138 MediaSeekingImpl_GetPreroll
141 static HRESULT
NullRendererImpl_Change(IBaseFilter
*iface
)
143 TRACE("(%p)\n", iface
);
147 HRESULT
NullRenderer_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
151 NullRendererImpl
* pNullRenderer
;
153 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
157 pNullRenderer
= CoTaskMemAlloc(sizeof(NullRendererImpl
));
158 pNullRenderer
->pUnkOuter
= pUnkOuter
;
159 pNullRenderer
->bUnkOuterValid
= FALSE
;
160 pNullRenderer
->bAggregatable
= FALSE
;
161 pNullRenderer
->IInner_vtbl
= &IInner_VTable
;
163 pNullRenderer
->lpVtbl
= &NullRenderer_Vtbl
;
164 pNullRenderer
->refCount
= 1;
165 InitializeCriticalSection(&pNullRenderer
->csFilter
);
166 pNullRenderer
->csFilter
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": NullRendererImpl.csFilter");
167 pNullRenderer
->state
= State_Stopped
;
168 pNullRenderer
->pClock
= NULL
;
169 ZeroMemory(&pNullRenderer
->filterInfo
, sizeof(FILTER_INFO
));
171 /* construct input pin */
172 piInput
.dir
= PINDIR_INPUT
;
173 piInput
.pFilter
= (IBaseFilter
*)pNullRenderer
;
174 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
176 hr
= InputPin_Construct(&NullRenderer_InputPin_Vtbl
, &piInput
, NullRenderer_Sample
, (LPVOID
)pNullRenderer
, NullRenderer_QueryAccept
, NULL
, &pNullRenderer
->csFilter
, NULL
, (IPin
**)&pNullRenderer
->pInputPin
);
180 MediaSeekingImpl_Init((IBaseFilter
*)pNullRenderer
, NullRendererImpl_Change
, NullRendererImpl_Change
, NullRendererImpl_Change
, &pNullRenderer
->mediaSeeking
, &pNullRenderer
->csFilter
);
181 pNullRenderer
->mediaSeeking
.lpVtbl
= &TransformFilter_Seeking_Vtbl
;
183 *ppv
= (LPVOID
)pNullRenderer
;
187 pNullRenderer
->csFilter
.DebugInfo
->Spare
[0] = 0;
188 DeleteCriticalSection(&pNullRenderer
->csFilter
);
189 CoTaskMemFree(pNullRenderer
);
195 static HRESULT WINAPI
NullRendererInner_QueryInterface(IUnknown
* iface
, REFIID riid
, LPVOID
* ppv
)
197 ICOM_THIS_MULTI(NullRendererImpl
, IInner_vtbl
, iface
);
198 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
200 if (This
->bAggregatable
)
201 This
->bUnkOuterValid
= TRUE
;
205 if (IsEqualIID(riid
, &IID_IUnknown
))
206 *ppv
= (LPVOID
)&(This
->IInner_vtbl
);
207 else if (IsEqualIID(riid
, &IID_IPersist
))
209 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
211 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
213 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
214 *ppv
= &This
->mediaSeeking
;
218 IUnknown_AddRef((IUnknown
*)(*ppv
));
222 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
223 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
225 return E_NOINTERFACE
;
228 static ULONG WINAPI
NullRendererInner_AddRef(IUnknown
* iface
)
230 ICOM_THIS_MULTI(NullRendererImpl
, IInner_vtbl
, iface
);
231 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
233 TRACE("(%p/%p)->() AddRef from %d\n", This
, iface
, refCount
- 1);
238 static ULONG WINAPI
NullRendererInner_Release(IUnknown
* iface
)
240 ICOM_THIS_MULTI(NullRendererImpl
, IInner_vtbl
, iface
);
241 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
243 TRACE("(%p/%p)->() Release from %d\n", This
, iface
, refCount
+ 1);
250 IReferenceClock_Release(This
->pClock
);
252 if (SUCCEEDED(IPin_ConnectedTo((IPin
*)This
->pInputPin
, &pConnectedTo
)))
254 IPin_Disconnect(pConnectedTo
);
255 IPin_Release(pConnectedTo
);
257 IPin_Disconnect((IPin
*)This
->pInputPin
);
258 IPin_Release((IPin
*)This
->pInputPin
);
262 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
263 DeleteCriticalSection(&This
->csFilter
);
265 TRACE("Destroying Null Renderer\n");
273 static const IUnknownVtbl IInner_VTable
=
275 NullRendererInner_QueryInterface
,
276 NullRendererInner_AddRef
,
277 NullRendererInner_Release
280 static HRESULT WINAPI
NullRenderer_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
282 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
284 if (This
->bAggregatable
)
285 This
->bUnkOuterValid
= TRUE
;
289 if (This
->bAggregatable
)
290 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppv
);
292 if (IsEqualIID(riid
, &IID_IUnknown
))
296 IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
297 hr
= IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
298 IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
299 This
->bAggregatable
= TRUE
;
304 return E_NOINTERFACE
;
307 return IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
310 static ULONG WINAPI
NullRenderer_AddRef(IBaseFilter
* iface
)
312 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
314 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
315 return IUnknown_AddRef(This
->pUnkOuter
);
316 return IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
319 static ULONG WINAPI
NullRenderer_Release(IBaseFilter
* iface
)
321 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
323 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
324 return IUnknown_Release(This
->pUnkOuter
);
325 return IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
328 /** IPersist methods **/
330 static HRESULT WINAPI
NullRenderer_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
332 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
334 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClsid
);
336 *pClsid
= CLSID_NullRenderer
;
341 /** IMediaFilter methods **/
343 static HRESULT WINAPI
NullRenderer_Stop(IBaseFilter
* iface
)
345 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
347 TRACE("(%p/%p)->()\n", This
, iface
);
349 EnterCriticalSection(&This
->csFilter
);
351 This
->state
= State_Stopped
;
353 LeaveCriticalSection(&This
->csFilter
);
358 static HRESULT WINAPI
NullRenderer_Pause(IBaseFilter
* iface
)
360 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
362 TRACE("(%p/%p)->()\n", This
, iface
);
364 EnterCriticalSection(&This
->csFilter
);
366 if (This
->state
== State_Stopped
)
367 This
->pInputPin
->end_of_stream
= 0;
368 This
->state
= State_Paused
;
370 LeaveCriticalSection(&This
->csFilter
);
375 static HRESULT WINAPI
NullRenderer_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
377 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
379 TRACE("(%p/%p)->(%s)\n", This
, iface
, wine_dbgstr_longlong(tStart
));
381 EnterCriticalSection(&This
->csFilter
);
383 This
->rtStreamStart
= tStart
;
384 This
->state
= State_Running
;
385 This
->pInputPin
->end_of_stream
= 0;
387 LeaveCriticalSection(&This
->csFilter
);
392 static HRESULT WINAPI
NullRenderer_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
394 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
396 TRACE("(%p/%p)->(%d, %p)\n", This
, iface
, dwMilliSecsTimeout
, pState
);
398 EnterCriticalSection(&This
->csFilter
);
400 *pState
= This
->state
;
402 LeaveCriticalSection(&This
->csFilter
);
407 static HRESULT WINAPI
NullRenderer_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
409 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
411 TRACE("(%p/%p)->(%p)\n", This
, iface
, pClock
);
413 EnterCriticalSection(&This
->csFilter
);
416 IReferenceClock_Release(This
->pClock
);
417 This
->pClock
= pClock
;
419 IReferenceClock_AddRef(This
->pClock
);
421 LeaveCriticalSection(&This
->csFilter
);
426 static HRESULT WINAPI
NullRenderer_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
428 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
430 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppClock
);
432 EnterCriticalSection(&This
->csFilter
);
434 *ppClock
= This
->pClock
;
436 IReferenceClock_AddRef(This
->pClock
);
438 LeaveCriticalSection(&This
->csFilter
);
443 /** IBaseFilter implementation **/
445 static HRESULT
NullRenderer_GetPin(IBaseFilter
*iface
, ULONG pos
, IPin
**pin
, DWORD
*lastsynctick
)
447 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
449 /* Our pins are static, not changing so setting static tick count is ok */
455 *pin
= (IPin
*)This
->pInputPin
;
460 static HRESULT WINAPI
NullRenderer_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
462 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
464 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
466 return IEnumPinsImpl_Construct(ppEnum
, NullRenderer_GetPin
, iface
);
469 static HRESULT WINAPI
NullRenderer_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
471 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
473 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, debugstr_w(Id
), ppPin
);
475 FIXME("NullRenderer::FindPin(...)\n");
477 /* FIXME: critical section */
482 static HRESULT WINAPI
NullRenderer_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
484 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
486 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
488 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
489 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
492 IFilterGraph_AddRef(pInfo
->pGraph
);
497 static HRESULT WINAPI
NullRenderer_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
499 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
501 TRACE("(%p/%p)->(%p, %s)\n", This
, iface
, pGraph
, debugstr_w(pName
));
503 EnterCriticalSection(&This
->csFilter
);
506 strcpyW(This
->filterInfo
.achName
, pName
);
508 *This
->filterInfo
.achName
= '\0';
509 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
511 LeaveCriticalSection(&This
->csFilter
);
516 static HRESULT WINAPI
NullRenderer_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
518 NullRendererImpl
*This
= (NullRendererImpl
*)iface
;
519 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVendorInfo
);
523 static const IBaseFilterVtbl NullRenderer_Vtbl
=
525 NullRenderer_QueryInterface
,
527 NullRenderer_Release
,
528 NullRenderer_GetClassID
,
532 NullRenderer_GetState
,
533 NullRenderer_SetSyncSource
,
534 NullRenderer_GetSyncSource
,
535 NullRenderer_EnumPins
,
536 NullRenderer_FindPin
,
537 NullRenderer_QueryFilterInfo
,
538 NullRenderer_JoinFilterGraph
,
539 NullRenderer_QueryVendorInfo
542 static HRESULT WINAPI
NullRenderer_InputPin_EndOfStream(IPin
* iface
)
544 InputPin
* This
= (InputPin
*)iface
;
545 IMediaEventSink
* pEventSink
;
549 TRACE("(%p/%p)->()\n", This
, iface
);
551 InputPin_EndOfStream(iface
);
552 graph
= ((NullRendererImpl
*)This
->pin
.pinInfo
.pFilter
)->filterInfo
.pGraph
;
555 hr
= IFilterGraph_QueryInterface(((NullRendererImpl
*)This
->pin
.pinInfo
.pFilter
)->filterInfo
.pGraph
, &IID_IMediaEventSink
, (LPVOID
*)&pEventSink
);
558 hr
= IMediaEventSink_Notify(pEventSink
, EC_COMPLETE
, S_OK
, 0);
559 IMediaEventSink_Release(pEventSink
);
566 static const IPinVtbl NullRenderer_InputPin_Vtbl
=
568 InputPin_QueryInterface
,
572 InputPin_ReceiveConnection
,
574 IPinImpl_ConnectedTo
,
575 IPinImpl_ConnectionMediaType
,
576 IPinImpl_QueryPinInfo
,
577 IPinImpl_QueryDirection
,
579 IPinImpl_QueryAccept
,
580 IPinImpl_EnumMediaTypes
,
581 IPinImpl_QueryInternalConnections
,
582 NullRenderer_InputPin_EndOfStream
,