msi: Use boolean return value in boolean function.
[wine/multimedia.git] / dlls / strmbase / filter.c
blob67f7c9ff226c801aa97c3a4bd5c61a7c4f123820
1 /*
2 * Generic Implementation of IBaseFilter Interface
4 * Copyright 2010 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "dshow.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
26 #include "wine/strmbase.h"
27 #include "uuids.h"
28 #include <assert.h>
30 WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
32 static inline BaseFilter *impl_from_IBaseFilter(IBaseFilter *iface)
34 return CONTAINING_RECORD(iface, BaseFilter, IBaseFilter_iface);
37 HRESULT WINAPI BaseFilterImpl_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
39 BaseFilter *This = impl_from_IBaseFilter(iface);
40 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
42 *ppv = NULL;
44 if (IsEqualIID(riid, &IID_IUnknown))
45 *ppv = This;
46 else if (IsEqualIID(riid, &IID_IPersist))
47 *ppv = This;
48 else if (IsEqualIID(riid, &IID_IMediaFilter))
49 *ppv = This;
50 else if (IsEqualIID(riid, &IID_IBaseFilter))
51 *ppv = This;
53 if (*ppv)
55 IUnknown_AddRef((IUnknown *)(*ppv));
56 return S_OK;
59 return E_NOINTERFACE;
62 ULONG WINAPI BaseFilterImpl_AddRef(IBaseFilter * iface)
64 BaseFilter *This = impl_from_IBaseFilter(iface);
65 ULONG refCount = InterlockedIncrement(&This->refCount);
67 TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
69 return refCount;
72 ULONG WINAPI BaseFilterImpl_Release(IBaseFilter * iface)
74 BaseFilter *This = impl_from_IBaseFilter(iface);
75 ULONG refCount = InterlockedDecrement(&This->refCount);
77 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
79 if (!refCount)
81 if (This->pClock)
82 IReferenceClock_Release(This->pClock);
84 This->IBaseFilter_iface.lpVtbl = NULL;
85 This->csFilter.DebugInfo->Spare[0] = 0;
86 DeleteCriticalSection(&This->csFilter);
89 return refCount;
92 HRESULT WINAPI BaseFilterImpl_GetClassID(IBaseFilter * iface, CLSID * pClsid)
94 BaseFilter *This = impl_from_IBaseFilter(iface);
95 TRACE("(%p)->(%p)\n", This, pClsid);
97 *pClsid = This->clsid;
99 return S_OK;
102 HRESULT WINAPI BaseFilterImpl_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState )
104 BaseFilter *This = impl_from_IBaseFilter(iface);
105 TRACE("(%p)->(%d, %p)\n", This, dwMilliSecsTimeout, pState);
107 EnterCriticalSection(&This->csFilter);
109 *pState = This->state;
111 LeaveCriticalSection(&This->csFilter);
113 return S_OK;
116 HRESULT WINAPI BaseFilterImpl_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
118 BaseFilter *This = impl_from_IBaseFilter(iface);
119 TRACE("(%p)->(%p)\n", This, pClock);
121 EnterCriticalSection(&This->csFilter);
123 if (This->pClock)
124 IReferenceClock_Release(This->pClock);
125 This->pClock = pClock;
126 if (This->pClock)
127 IReferenceClock_AddRef(This->pClock);
129 LeaveCriticalSection(&This->csFilter);
131 return S_OK;
134 HRESULT WINAPI BaseFilterImpl_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
136 BaseFilter *This = impl_from_IBaseFilter(iface);
137 TRACE("(%p)->(%p)\n", This, ppClock);
139 EnterCriticalSection(&This->csFilter);
141 *ppClock = This->pClock;
142 if (This->pClock)
143 IReferenceClock_AddRef(This->pClock);
145 LeaveCriticalSection(&This->csFilter);
147 return S_OK;
150 HRESULT WINAPI BaseFilterImpl_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
152 BaseFilter *This = impl_from_IBaseFilter(iface);
154 TRACE("(%p)->(%p)\n", iface, ppEnum);
156 return EnumPins_Construct(This, This->pFuncsTable->pfnGetPin, This->pFuncsTable->pfnGetPinCount, BaseFilterImpl_GetPinVersion, ppEnum);
160 HRESULT WINAPI BaseFilterImpl_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
162 BaseFilter *This = impl_from_IBaseFilter(iface);
163 TRACE("(%p)->(%p)\n", This, pInfo);
165 strcpyW(pInfo->achName, This->filterInfo.achName);
166 pInfo->pGraph = This->filterInfo.pGraph;
168 if (pInfo->pGraph)
169 IFilterGraph_AddRef(pInfo->pGraph);
171 return S_OK;
174 HRESULT WINAPI BaseFilterImpl_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName )
176 HRESULT hr = S_OK;
177 BaseFilter *This = impl_from_IBaseFilter(iface);
179 TRACE("(%p)->(%p, %s)\n", This, pGraph, debugstr_w(pName));
181 EnterCriticalSection(&This->csFilter);
183 if (pName)
184 strcpyW(This->filterInfo.achName, pName);
185 else
186 *This->filterInfo.achName = '\0';
187 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
189 LeaveCriticalSection(&This->csFilter);
191 return hr;
194 HRESULT WINAPI BaseFilterImpl_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
196 TRACE("(%p)->(%p)\n", iface, pVendorInfo);
197 return E_NOTIMPL;
200 LONG WINAPI BaseFilterImpl_GetPinVersion(BaseFilter * This)
202 TRACE("(%p)\n", This);
203 return This->pinVersion;
206 VOID WINAPI BaseFilterImpl_IncrementPinVersion(BaseFilter * This)
208 InterlockedIncrement(&This->pinVersion);
209 TRACE("(%p) -> New pinVersion %i\n", This,This->pinVersion);
212 HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseFilterFuncTable* pBaseFuncsTable)
214 This->IBaseFilter_iface.lpVtbl = Vtbl;
215 This->refCount = 1;
216 InitializeCriticalSection(&This->csFilter);
217 This->state = State_Stopped;
218 This->rtStreamStart = 0;
219 This->pClock = NULL;
220 ZeroMemory(&This->filterInfo, sizeof(FILTER_INFO));
221 This->clsid = *pClsid;
222 This->csFilter.DebugInfo->Spare[0] = DebugInfo;
223 This->pinVersion = 1;
225 This->pFuncsTable = pBaseFuncsTable;
227 return S_OK;