msi: Fix handling of buffer sizes in MsiEnumPatchesA and avoid a redundant call to...
[wine/multimedia.git] / dlls / quartz / nullrenderer.c
blobf7740121eac4ecc733b8e655fa71f119d77cad6c
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 HRESULT NullRenderer_Sample(LPVOID iface, IMediaSample * pSample)
72 NullRendererImpl *This = iface;
73 HRESULT hr = S_OK;
75 TRACE("%p %p\n", iface, pSample);
77 EnterCriticalSection(&This->csFilter);
78 if (This->pInputPin->flushing || This->pInputPin->end_of_stream)
79 hr = S_FALSE;
80 LeaveCriticalSection(&This->csFilter);
82 return hr;
85 static HRESULT NullRenderer_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
87 TRACE("Not a stub!\n");
88 return S_OK;
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);
144 return S_OK;
147 HRESULT NullRenderer_create(IUnknown * pUnkOuter, LPVOID * ppv)
149 HRESULT hr;
150 PIN_INFO piInput;
151 NullRendererImpl * pNullRenderer;
153 TRACE("(%p, %p)\n", pUnkOuter, ppv);
155 *ppv = NULL;
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);
178 if (SUCCEEDED(hr))
180 MediaSeekingImpl_Init((IBaseFilter*)pNullRenderer, NullRendererImpl_Change, NullRendererImpl_Change, NullRendererImpl_Change, &pNullRenderer->mediaSeeking, &pNullRenderer->csFilter);
181 pNullRenderer->mediaSeeking.lpVtbl = &TransformFilter_Seeking_Vtbl;
183 *ppv = pNullRenderer;
185 else
187 pNullRenderer->csFilter.DebugInfo->Spare[0] = 0;
188 DeleteCriticalSection(&pNullRenderer->csFilter);
189 CoTaskMemFree(pNullRenderer);
192 return hr;
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;
203 *ppv = NULL;
205 if (IsEqualIID(riid, &IID_IUnknown))
206 *ppv = &This->IInner_vtbl;
207 else if (IsEqualIID(riid, &IID_IPersist))
208 *ppv = This;
209 else if (IsEqualIID(riid, &IID_IMediaFilter))
210 *ppv = This;
211 else if (IsEqualIID(riid, &IID_IBaseFilter))
212 *ppv = This;
213 else if (IsEqualIID(riid, &IID_IMediaSeeking))
214 *ppv = &This->mediaSeeking;
216 if (*ppv)
218 IUnknown_AddRef((IUnknown *)(*ppv));
219 return S_OK;
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);
235 return refCount;
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);
245 if (!refCount)
247 IPin *pConnectedTo;
249 if (This->pClock)
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);
260 This->lpVtbl = NULL;
262 This->csFilter.DebugInfo->Spare[0] = 0;
263 DeleteCriticalSection(&This->csFilter);
265 TRACE("Destroying Null Renderer\n");
266 CoTaskMemFree(This);
267 return 0;
269 else
270 return refCount;
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;
287 if (This->pUnkOuter)
289 if (This->bAggregatable)
290 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
292 if (IsEqualIID(riid, &IID_IUnknown))
294 HRESULT hr;
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;
300 return hr;
303 *ppv = NULL;
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;
338 return S_OK;
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);
355 return S_OK;
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);
372 return S_OK;
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);
389 return S_OK;
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);
404 return S_OK;
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);
415 if (This->pClock)
416 IReferenceClock_Release(This->pClock);
417 This->pClock = pClock;
418 if (This->pClock)
419 IReferenceClock_AddRef(This->pClock);
421 LeaveCriticalSection(&This->csFilter);
423 return S_OK;
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;
435 if (This->pClock)
436 IReferenceClock_AddRef(This->pClock);
438 LeaveCriticalSection(&This->csFilter);
440 return S_OK;
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 */
450 *lastsynctick = 0;
452 if (pos >= 1)
453 return S_FALSE;
455 *pin = (IPin *)This->pInputPin;
456 IPin_AddRef(*pin);
457 return S_OK;
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 */
479 return E_NOTIMPL;
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;
491 if (pInfo->pGraph)
492 IFilterGraph_AddRef(pInfo->pGraph);
494 return S_OK;
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);
505 if (pName)
506 strcpyW(This->filterInfo.achName, pName);
507 else
508 *This->filterInfo.achName = '\0';
509 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
511 LeaveCriticalSection(&This->csFilter);
513 return S_OK;
516 static HRESULT WINAPI NullRenderer_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
518 NullRendererImpl *This = (NullRendererImpl *)iface;
519 TRACE("(%p/%p)->(%p)\n", This, iface, pVendorInfo);
520 return E_NOTIMPL;
523 static const IBaseFilterVtbl NullRenderer_Vtbl =
525 NullRenderer_QueryInterface,
526 NullRenderer_AddRef,
527 NullRenderer_Release,
528 NullRenderer_GetClassID,
529 NullRenderer_Stop,
530 NullRenderer_Pause,
531 NullRenderer_Run,
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;
546 IFilterGraph *graph;
547 HRESULT hr = S_OK;
549 TRACE("(%p/%p)->()\n", This, iface);
551 InputPin_EndOfStream(iface);
552 graph = ((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph;
553 if (graph)
555 hr = IFilterGraph_QueryInterface(((NullRendererImpl*)This->pin.pinInfo.pFilter)->filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
556 if (SUCCEEDED(hr))
558 hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, 0);
559 IMediaEventSink_Release(pEventSink);
563 return hr;
566 static const IPinVtbl NullRenderer_InputPin_Vtbl =
568 InputPin_QueryInterface,
569 IPinImpl_AddRef,
570 InputPin_Release,
571 InputPin_Connect,
572 InputPin_ReceiveConnection,
573 IPinImpl_Disconnect,
574 IPinImpl_ConnectedTo,
575 IPinImpl_ConnectionMediaType,
576 IPinImpl_QueryPinInfo,
577 IPinImpl_QueryDirection,
578 IPinImpl_QueryId,
579 IPinImpl_QueryAccept,
580 IPinImpl_EnumMediaTypes,
581 IPinImpl_QueryInternalConnections,
582 NullRenderer_InputPin_EndOfStream,
583 InputPin_BeginFlush,
584 InputPin_EndFlush,
585 InputPin_NewSegment