wined3d: Always load glFinish and glFlush from opengl32.dll.
[wine/gsoc_dplay.git] / dlls / quartz / nullrenderer.c
blob2f9ec94b4dea26f9cce219c14aefd2c0487557a5
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};
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;
56 LONG refCount;
57 CRITICAL_SECTION csFilter;
58 FILTER_STATE state;
59 REFERENCE_TIME rtStreamStart;
60 IReferenceClock * pClock;
61 FILTER_INFO filterInfo;
63 InputPin *pInputPin;
64 IUnknown * pUnkOuter;
65 BOOL bUnkOuterValid;
66 BOOL bAggregatable;
67 MediaSeekingImpl mediaSeeking;
68 } NullRendererImpl;
70 static const IMemInputPinVtbl MemInputPin_Vtbl =
72 MemInputPin_QueryInterface,
73 MemInputPin_AddRef,
74 MemInputPin_Release,
75 MemInputPin_GetAllocator,
76 MemInputPin_NotifyAllocator,
77 MemInputPin_GetAllocatorRequirements,
78 MemInputPin_Receive,
79 MemInputPin_ReceiveMultiple,
80 MemInputPin_ReceiveCanBlock
83 static HRESULT NullRenderer_Sample(LPVOID iface, IMediaSample * pSample)
85 NullRendererImpl *This = (NullRendererImpl *)iface;
86 HRESULT hr = S_OK;
88 TRACE("%p %p\n", iface, pSample);
90 EnterCriticalSection(&This->csFilter);
91 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
92 hr = S_FALSE;
93 LeaveCriticalSection(&This->csFilter);
95 return hr;
98 static HRESULT NullRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
100 TRACE("Not a stub!\n");
101 return S_OK;
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);
157 return S_OK;
160 HRESULT NullRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
162 HRESULT hr;
163 PIN_INFO piInput;
164 NullRendererImpl * pNullRenderer;
166 TRACE("(%p, %p)\n", pUnkOuter, ppv);
168 *ppv = NULL;
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);
191 if (SUCCEEDED(hr))
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;
198 else
200 pNullRenderer->csFilter.DebugInfo->Spare[0] = 0;
201 DeleteCriticalSection(&pNullRenderer->csFilter);
202 CoTaskMemFree(pNullRenderer);
205 return hr;
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;
216 *ppv = NULL;
218 if (IsEqualIID(riid, &IID_IUnknown))
219 *ppv = (LPVOID)&(This->IInner_vtbl);
220 else if (IsEqualIID(riid, &IID_IPersist))
221 *ppv = (LPVOID)This;
222 else if (IsEqualIID(riid, &IID_IMediaFilter))
223 *ppv = (LPVOID)This;
224 else if (IsEqualIID(riid, &IID_IBaseFilter))
225 *ppv = (LPVOID)This;
226 else if (IsEqualIID(riid, &IID_IMediaSeeking))
227 *ppv = &This->mediaSeeking;
229 if (*ppv)
231 IUnknown_AddRef((IUnknown *)(*ppv));
232 return S_OK;
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);
248 return refCount;
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);
258 if (!refCount)
260 IPin *pConnectedTo;
262 if (This->pClock)
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);
273 This->lpVtbl = NULL;
275 This->csFilter.DebugInfo->Spare[0] = 0;
276 DeleteCriticalSection(&This->csFilter);
278 TRACE("Destroying Null Renderer\n");
279 CoTaskMemFree(This);
280 return 0;
282 else
283 return refCount;
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;
300 if (This->pUnkOuter)
302 if (This->bAggregatable)
303 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
305 if (IsEqualIID(riid, &IID_IUnknown))
307 HRESULT hr;
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;
313 return hr;
316 *ppv = NULL;
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;
351 return S_OK;
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);
368 return S_OK;
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);
385 return S_OK;
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);
402 return S_OK;
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);
417 return S_OK;
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);
428 if (This->pClock)
429 IReferenceClock_Release(This->pClock);
430 This->pClock = pClock;
431 if (This->pClock)
432 IReferenceClock_AddRef(This->pClock);
434 LeaveCriticalSection(&This->csFilter);
436 return S_OK;
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;
448 if (This->pClock)
449 IReferenceClock_AddRef(This->pClock);
451 LeaveCriticalSection(&This->csFilter);
453 return S_OK;
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 */
463 *lastsynctick = 0;
465 if (pos >= 1)
466 return S_FALSE;
468 *pin = (IPin *)This->pInputPin;
469 IPin_AddRef(*pin);
470 return S_OK;
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 */
492 return E_NOTIMPL;
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;
504 if (pInfo->pGraph)
505 IFilterGraph_AddRef(pInfo->pGraph);
507 return S_OK;
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);
518 if (pName)
519 strcpyW(This->filterInfo.achName, pName);
520 else
521 *This->filterInfo.achName = '\0';
522 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
524 LeaveCriticalSection(&This->csFilter);
526 return S_OK;
529 static HRESULT WINAPI NullRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
531 NullRendererImpl *This = (NullRendererImpl *)iface;
532 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
533 return E_NOTIMPL;
536 static const IBaseFilterVtbl NullRenderer_Vtbl =
538 NullRenderer_QueryInterface,
539 NullRenderer_AddRef,
540 NullRenderer_Release,
541 NullRenderer_GetClassID,
542 NullRenderer_Stop,
543 NullRenderer_Pause,
544 NullRenderer_Run,
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;
559 IFilterGraph *graph;
560 HRESULT hr = S_OK;
562 TRACE("(%p/%p)->()\n", This, iface);
564 InputPin_EndOfStream(iface);
565 graph = ((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph;
566 if (graph)
568 hr = IFilterGraph_QueryInterface(((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
569 if (SUCCEEDED(hr))
571 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
572 IMediaEventSink_Release(pEventSink);
576 return hr;
579 static const IPinVtbl NullRenderer_InputPin_Vtbl =
581 InputPin_QueryInterface,
582 IPinImpl_AddRef,
583 InputPin_Release,
584 InputPin_Connect,
585 InputPin_ReceiveConnection,
586 IPinImpl_Disconnect,
587 IPinImpl_ConnectedTo,
588 IPinImpl_ConnectionMediaType,
589 IPinImpl_QueryPinInfo,
590 IPinImpl_QueryDirection,
591 IPinImpl_QueryId,
592 IPinImpl_QueryAccept,
593 IPinImpl_EnumMediaTypes,
594 IPinImpl_QueryInternalConnections,
595 NullRenderer_InputPin_EndOfStream,
596 InputPin_BeginFlush,
597 InputPin_EndFlush,
598 InputPin_NewSegment