cryptui: Add Norwegian Bokmål translation.
[wine/hacks.git] / dlls / quartz / nullrenderer.c
blobd2aedfa38f4aba000b0a75601391344bd1a5c71c
1 /*
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
22 #include "config.h"
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26 #include "quartz_private.h"
27 #include "control_private.h"
28 #include "pin.h"
30 #include "uuids.h"
31 #include "vfwmsgs.h"
32 #include "amvideo.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "dshow.h"
36 #include "evcode.h"
37 #include "strmif.h"
38 #include "ddraw.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;
57 LONG refCount;
58 CRITICAL_SECTION csFilter;
59 FILTER_STATE state;
60 REFERENCE_TIME rtStreamStart;
61 IReferenceClock * pClock;
62 FILTER_INFO filterInfo;
64 InputPin *pInputPin;
65 IUnknown * pUnkOuter;
66 BOOL bUnkOuterValid;
67 BOOL bAggregatable;
68 MediaSeekingImpl mediaSeeking;
69 } NullRendererImpl;
71 static HRESULT NullRenderer_Sample(LPVOID iface, IMediaSample * pSample)
73 NullRendererImpl *This = iface;
74 HRESULT hr = S_OK;
76 TRACE("%p %p\n", iface, pSample);
78 EnterCriticalSection(&This->csFilter);
79 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
80 hr = S_FALSE;
81 LeaveCriticalSection(&This->csFilter);
83 return hr;
86 static HRESULT NullRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
88 TRACE("Not a stub!\n");
89 return S_OK;
92 static inline NullRendererImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
94 return (NullRendererImpl *)((char*)iface - FIELD_OFFSET(NullRendererImpl, mediaSeeking.lpVtbl));
97 static HRESULT WINAPI NullRendererImpl_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
99 NullRendererImpl *This = impl_from_IMediaSeeking(iface);
101 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
104 static ULONG WINAPI NullRendererImpl_Seeking_AddRef(IMediaSeeking * iface)
106 NullRendererImpl *This = impl_from_IMediaSeeking(iface);
108 return IUnknown_AddRef((IUnknown *)This);
111 static ULONG WINAPI NullRendererImpl_Seeking_Release(IMediaSeeking * iface)
113 NullRendererImpl *This = impl_from_IMediaSeeking(iface);
115 return IUnknown_Release((IUnknown *)This);
118 static const IMediaSeekingVtbl TransformFilter_Seeking_Vtbl =
120 NullRendererImpl_Seeking_QueryInterface,
121 NullRendererImpl_Seeking_AddRef,
122 NullRendererImpl_Seeking_Release,
123 MediaSeekingImpl_GetCapabilities,
124 MediaSeekingImpl_CheckCapabilities,
125 MediaSeekingImpl_IsFormatSupported,
126 MediaSeekingImpl_QueryPreferredFormat,
127 MediaSeekingImpl_GetTimeFormat,
128 MediaSeekingImpl_IsUsingTimeFormat,
129 MediaSeekingImpl_SetTimeFormat,
130 MediaSeekingImpl_GetDuration,
131 MediaSeekingImpl_GetStopPosition,
132 MediaSeekingImpl_GetCurrentPosition,
133 MediaSeekingImpl_ConvertTimeFormat,
134 MediaSeekingImpl_SetPositions,
135 MediaSeekingImpl_GetPositions,
136 MediaSeekingImpl_GetAvailable,
137 MediaSeekingImpl_SetRate,
138 MediaSeekingImpl_GetRate,
139 MediaSeekingImpl_GetPreroll
142 static HRESULT NullRendererImpl_Change(IBaseFilter *iface)
144 TRACE("(%p)\n", iface);
145 return S_OK;
148 HRESULT NullRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
150 HRESULT hr;
151 PIN_INFO piInput;
152 NullRendererImpl * pNullRenderer;
154 TRACE("(%p, %p)\n", pUnkOuter, ppv);
156 *ppv = NULL;
158 pNullRenderer = CoTaskMemAlloc(sizeof(NullRendererImpl));
159 pNullRenderer->pUnkOuter = pUnkOuter;
160 pNullRenderer->bUnkOuterValid = FALSE;
161 pNullRenderer->bAggregatable = FALSE;
162 pNullRenderer->IInner_vtbl = &IInner_VTable;
164 pNullRenderer->lpVtbl = &NullRenderer_Vtbl;
165 pNullRenderer->refCount = 1;
166 InitializeCriticalSection(&pNullRenderer->csFilter);
167 pNullRenderer->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": NullRendererImpl.csFilter");
168 pNullRenderer->state = State_Stopped;
169 pNullRenderer->pClock = NULL;
170 ZeroMemory(&pNullRenderer->filterInfo, sizeof(FILTER_INFO));
172 /* construct input pin */
173 piInput.dir = PINDIR_INPUT;
174 piInput.pFilter = (IBaseFilter *)pNullRenderer;
175 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
177 hr = InputPin_Construct(&NullRenderer_InputPin_Vtbl, &piInput, NullRenderer_Sample, (LPVOID)pNullRenderer, NullRenderer_QueryAccept, NULL, &pNullRenderer->csFilter, NULL, (IPin **)&pNullRenderer->pInputPin);
179 if (SUCCEEDED(hr))
181 MediaSeekingImpl_Init((IBaseFilter*)pNullRenderer, NullRendererImpl_Change, NullRendererImpl_Change, NullRendererImpl_Change, &pNullRenderer->mediaSeeking, &pNullRenderer->csFilter);
182 pNullRenderer->mediaSeeking.lpVtbl = &TransformFilter_Seeking_Vtbl;
184 *ppv = pNullRenderer;
186 else
188 pNullRenderer->csFilter.DebugInfo->Spare[0] = 0;
189 DeleteCriticalSection(&pNullRenderer->csFilter);
190 CoTaskMemFree(pNullRenderer);
193 return hr;
196 static HRESULT WINAPI NullRendererInner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
198 ICOM_THIS_MULTI(NullRendererImpl, IInner_vtbl, iface);
199 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
201 if (This->bAggregatable)
202 This->bUnkOuterValid = TRUE;
204 *ppv = NULL;
206 if (IsEqualIID(riid, &IID_IUnknown))
207 *ppv = &This->IInner_vtbl;
208 else if (IsEqualIID(riid, &IID_IPersist))
209 *ppv = This;
210 else if (IsEqualIID(riid, &IID_IMediaFilter))
211 *ppv = This;
212 else if (IsEqualIID(riid, &IID_IBaseFilter))
213 *ppv = This;
214 else if (IsEqualIID(riid, &IID_IMediaSeeking))
215 *ppv = &This->mediaSeeking;
217 if (*ppv)
219 IUnknown_AddRef((IUnknown *)(*ppv));
220 return S_OK;
223 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
224 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
226 return E_NOINTERFACE;
229 static ULONG WINAPI NullRendererInner_AddRef(IUnknown * iface)
231 ICOM_THIS_MULTI(NullRendererImpl, IInner_vtbl, iface);
232 ULONG refCount = InterlockedIncrement(&This->refCount);
234 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
236 return refCount;
239 static ULONG WINAPI NullRendererInner_Release(IUnknown * iface)
241 ICOM_THIS_MULTI(NullRendererImpl, IInner_vtbl, iface);
242 ULONG refCount = InterlockedDecrement(&This->refCount);
244 TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
246 if (!refCount)
248 IPin *pConnectedTo;
250 if (This->pClock)
251 IReferenceClock_Release(This->pClock);
253 if (SUCCEEDED(IPin_ConnectedTo((IPin *)This->pInputPin, &pConnectedTo)))
255 IPin_Disconnect(pConnectedTo);
256 IPin_Release(pConnectedTo);
258 IPin_Disconnect((IPin *)This->pInputPin);
259 IPin_Release((IPin *)This->pInputPin);
261 This->lpVtbl = NULL;
263 This->csFilter.DebugInfo->Spare[0] = 0;
264 DeleteCriticalSection(&This->csFilter);
266 TRACE("Destroying Null Renderer\n");
267 CoTaskMemFree(This);
268 return 0;
270 else
271 return refCount;
274 static const IUnknownVtbl IInner_VTable =
276 NullRendererInner_QueryInterface,
277 NullRendererInner_AddRef,
278 NullRendererInner_Release
281 static HRESULT WINAPI NullRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
283 NullRendererImpl *This = (NullRendererImpl *)iface;
285 if (This->bAggregatable)
286 This->bUnkOuterValid = TRUE;
288 if (This->pUnkOuter)
290 if (This->bAggregatable)
291 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
293 if (IsEqualIID(riid, &IID_IUnknown))
295 HRESULT hr;
297 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
298 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
299 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
300 This->bAggregatable = TRUE;
301 return hr;
304 *ppv = NULL;
305 return E_NOINTERFACE;
308 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
311 static ULONG WINAPI NullRenderer_AddRef(IBaseFilter * iface)
313 NullRendererImpl *This = (NullRendererImpl *)iface;
315 if (This->pUnkOuter && This->bUnkOuterValid)
316 return IUnknown_AddRef(This->pUnkOuter);
317 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
320 static ULONG WINAPI NullRenderer_Release(IBaseFilter * iface)
322 NullRendererImpl *This = (NullRendererImpl *)iface;
324 if (This->pUnkOuter && This->bUnkOuterValid)
325 return IUnknown_Release(This->pUnkOuter);
326 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
329 /** IPersist methods **/
331 static HRESULT WINAPI NullRenderer_GetClassID(IBaseFilter * iface, CLSID * pClsid)
333 NullRendererImpl *This = (NullRendererImpl *)iface;
335 TRACE("(%p/%p)->(%p)\n", This, iface, pClsid);
337 *pClsid = CLSID_NullRenderer;
339 return S_OK;
342 /** IMediaFilter methods **/
344 static HRESULT WINAPI NullRenderer_Stop(IBaseFilter * iface)
346 NullRendererImpl *This = (NullRendererImpl *)iface;
348 TRACE("(%p/%p)->()\n", This, iface);
350 EnterCriticalSection(&This->csFilter);
352 This->state = State_Stopped;
354 LeaveCriticalSection(&This->csFilter);
356 return S_OK;
359 static HRESULT WINAPI NullRenderer_Pause(IBaseFilter * iface)
361 NullRendererImpl *This = (NullRendererImpl *)iface;
363 TRACE("(%p/%p)->()\n", This, iface);
365 EnterCriticalSection(&This->csFilter);
367 if (This->state == State_Stopped)
368 This->pInputPin->end_of_stream = 0;
369 This->state = State_Paused;
371 LeaveCriticalSection(&This->csFilter);
373 return S_OK;
376 static HRESULT WINAPI NullRenderer_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
378 NullRendererImpl *This = (NullRendererImpl *)iface;
380 TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(tStart));
382 EnterCriticalSection(&This->csFilter);
384 This->rtStreamStart = tStart;
385 This->state = State_Running;
386 This->pInputPin->end_of_stream = 0;
388 LeaveCriticalSection(&This->csFilter);
390 return S_OK;
393 static HRESULT WINAPI NullRenderer_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
395 NullRendererImpl *This = (NullRendererImpl *)iface;
397 TRACE("(%p/%p)->(%d, %p)\n", This, iface, dwMilliSecsTimeout, pState);
399 EnterCriticalSection(&This->csFilter);
401 *pState = This->state;
403 LeaveCriticalSection(&This->csFilter);
405 return S_OK;
408 static HRESULT WINAPI NullRenderer_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
410 NullRendererImpl *This = (NullRendererImpl *)iface;
412 TRACE("(%p/%p)->(%p)\n", This, iface, pClock);
414 EnterCriticalSection(&This->csFilter);
416 if (This->pClock)
417 IReferenceClock_Release(This->pClock);
418 This->pClock = pClock;
419 if (This->pClock)
420 IReferenceClock_AddRef(This->pClock);
422 LeaveCriticalSection(&This->csFilter);
424 return S_OK;
427 static HRESULT WINAPI NullRenderer_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
429 NullRendererImpl *This = (NullRendererImpl *)iface;
431 TRACE("(%p/%p)->(%p)\n", This, iface, ppClock);
433 EnterCriticalSection(&This->csFilter);
435 *ppClock = This->pClock;
436 if (This->pClock)
437 IReferenceClock_AddRef(This->pClock);
439 LeaveCriticalSection(&This->csFilter);
441 return S_OK;
444 /** IBaseFilter implementation **/
446 static HRESULT NullRenderer_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
448 NullRendererImpl *This = (NullRendererImpl *)iface;
450 /* Our pins are static, not changing so setting static tick count is ok */
451 *lastsynctick = 0;
453 if (pos >= 1)
454 return S_FALSE;
456 *pin = (IPin *)This->pInputPin;
457 IPin_AddRef(*pin);
458 return S_OK;
461 static HRESULT WINAPI NullRenderer_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
463 NullRendererImpl *This = (NullRendererImpl *)iface;
465 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
467 return IEnumPinsImpl_Construct(ppEnum, NullRenderer_GetPin, iface);
470 static HRESULT WINAPI NullRenderer_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
472 NullRendererImpl *This = (NullRendererImpl *)iface;
474 TRACE("(%p/%p)->(%p,%p)\n", This, iface, debugstr_w(Id), ppPin);
476 if (!Id || !ppPin)
477 return E_POINTER;
479 if (!lstrcmpiW(Id,wcsInputPinName) || !lstrcmpiW(Id,wcsAltInputPinName))
481 *ppPin = (IPin *)This->pInputPin;
482 IPin_AddRef(*ppPin);
483 return S_OK;
485 *ppPin = NULL;
486 return VFW_E_NOT_FOUND;
489 static HRESULT WINAPI NullRenderer_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
491 NullRendererImpl *This = (NullRendererImpl *)iface;
493 TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
495 strcpyW(pInfo->achName, This->filterInfo.achName);
496 pInfo->pGraph = This->filterInfo.pGraph;
498 if (pInfo->pGraph)
499 IFilterGraph_AddRef(pInfo->pGraph);
501 return S_OK;
504 static HRESULT WINAPI NullRenderer_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
506 NullRendererImpl *This = (NullRendererImpl *)iface;
508 TRACE("(%p/%p)->(%p, %s)\n", This, iface, pGraph, debugstr_w(pName));
510 EnterCriticalSection(&This->csFilter);
512 if (pName)
513 strcpyW(This->filterInfo.achName, pName);
514 else
515 *This->filterInfo.achName = '\0';
516 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
518 LeaveCriticalSection(&This->csFilter);
520 return S_OK;
523 static HRESULT WINAPI NullRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
525 NullRendererImpl *This = (NullRendererImpl *)iface;
526 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
527 return E_NOTIMPL;
530 static const IBaseFilterVtbl NullRenderer_Vtbl =
532 NullRenderer_QueryInterface,
533 NullRenderer_AddRef,
534 NullRenderer_Release,
535 NullRenderer_GetClassID,
536 NullRenderer_Stop,
537 NullRenderer_Pause,
538 NullRenderer_Run,
539 NullRenderer_GetState,
540 NullRenderer_SetSyncSource,
541 NullRenderer_GetSyncSource,
542 NullRenderer_EnumPins,
543 NullRenderer_FindPin,
544 NullRenderer_QueryFilterInfo,
545 NullRenderer_JoinFilterGraph,
546 NullRenderer_QueryVendorInfo
549 static HRESULT WINAPI NullRenderer_InputPin_EndOfStream(IPin * iface)
551 InputPin* This = (InputPin*)iface;
552 IMediaEventSink* pEventSink;
553 IFilterGraph *graph;
554 HRESULT hr = S_OK;
556 TRACE("(%p/%p)->()\n", This, iface);
558 InputPin_EndOfStream(iface);
559 graph = ((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph;
560 if (graph)
562 hr = IFilterGraph_QueryInterface(((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
563 if (SUCCEEDED(hr))
565 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
566 IMediaEventSink_Release(pEventSink);
570 return hr;
573 static const IPinVtbl NullRenderer_InputPin_Vtbl =
575 InputPin_QueryInterface,
576 IPinImpl_AddRef,
577 InputPin_Release,
578 InputPin_Connect,
579 InputPin_ReceiveConnection,
580 IPinImpl_Disconnect,
581 IPinImpl_ConnectedTo,
582 IPinImpl_ConnectionMediaType,
583 IPinImpl_QueryPinInfo,
584 IPinImpl_QueryDirection,
585 IPinImpl_QueryId,
586 IPinImpl_QueryAccept,
587 IPinImpl_EnumMediaTypes,
588 IPinImpl_QueryInternalConnections,
589 NullRenderer_InputPin_EndOfStream,
590 InputPin_BeginFlush,
591 InputPin_EndFlush,
592 InputPin_NewSegment