vbscript: Don't try to convert int to short in return_int.
[wine.git] / dlls / strmbase / filter.c
blob697b2439e9839ad0a9783b7b8b3e5c66b2235bd0
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 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
41 *ppv = NULL;
43 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IPersist) ||
44 IsEqualIID(riid, &IID_IMediaFilter) || IsEqualIID(riid, &IID_IBaseFilter))
46 *ppv = iface;
47 IBaseFilter_AddRef(iface);
48 return S_OK;
51 return E_NOINTERFACE;
54 ULONG WINAPI BaseFilterImpl_AddRef(IBaseFilter * iface)
56 BaseFilter *This = impl_from_IBaseFilter(iface);
57 ULONG refCount = InterlockedIncrement(&This->refCount);
59 TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
61 return refCount;
64 ULONG WINAPI BaseFilterImpl_Release(IBaseFilter * iface)
66 BaseFilter *This = impl_from_IBaseFilter(iface);
67 ULONG refCount = InterlockedDecrement(&This->refCount);
69 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
71 if (!refCount)
72 BaseFilter_Destroy(This);
74 return refCount;
77 HRESULT WINAPI BaseFilterImpl_GetClassID(IBaseFilter * iface, CLSID * pClsid)
79 BaseFilter *This = impl_from_IBaseFilter(iface);
80 TRACE("(%p)->(%p)\n", This, pClsid);
82 *pClsid = This->clsid;
84 return S_OK;
87 HRESULT WINAPI BaseFilterImpl_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState )
89 BaseFilter *This = impl_from_IBaseFilter(iface);
90 TRACE("(%p)->(%d, %p)\n", This, dwMilliSecsTimeout, pState);
92 EnterCriticalSection(&This->csFilter);
94 *pState = This->state;
96 LeaveCriticalSection(&This->csFilter);
98 return S_OK;
101 HRESULT WINAPI BaseFilterImpl_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
103 BaseFilter *This = impl_from_IBaseFilter(iface);
104 TRACE("(%p)->(%p)\n", This, pClock);
106 EnterCriticalSection(&This->csFilter);
108 if (This->pClock)
109 IReferenceClock_Release(This->pClock);
110 This->pClock = pClock;
111 if (This->pClock)
112 IReferenceClock_AddRef(This->pClock);
114 LeaveCriticalSection(&This->csFilter);
116 return S_OK;
119 HRESULT WINAPI BaseFilterImpl_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
121 BaseFilter *This = impl_from_IBaseFilter(iface);
122 TRACE("(%p)->(%p)\n", This, ppClock);
124 EnterCriticalSection(&This->csFilter);
126 *ppClock = This->pClock;
127 if (This->pClock)
128 IReferenceClock_AddRef(This->pClock);
130 LeaveCriticalSection(&This->csFilter);
132 return S_OK;
135 HRESULT WINAPI BaseFilterImpl_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
137 BaseFilter *This = impl_from_IBaseFilter(iface);
139 TRACE("(%p)->(%p)\n", iface, ppEnum);
141 return EnumPins_Construct(This, This->pFuncsTable->pfnGetPin, This->pFuncsTable->pfnGetPinCount, BaseFilterImpl_GetPinVersion, ppEnum);
145 HRESULT WINAPI BaseFilterImpl_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
147 BaseFilter *This = impl_from_IBaseFilter(iface);
148 TRACE("(%p)->(%p)\n", This, pInfo);
150 strcpyW(pInfo->achName, This->filterInfo.achName);
151 pInfo->pGraph = This->filterInfo.pGraph;
153 if (pInfo->pGraph)
154 IFilterGraph_AddRef(pInfo->pGraph);
156 return S_OK;
159 HRESULT WINAPI BaseFilterImpl_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName )
161 HRESULT hr = S_OK;
162 BaseFilter *This = impl_from_IBaseFilter(iface);
164 TRACE("(%p)->(%p, %s)\n", This, pGraph, debugstr_w(pName));
166 EnterCriticalSection(&This->csFilter);
168 if (pName)
169 strcpyW(This->filterInfo.achName, pName);
170 else
171 *This->filterInfo.achName = '\0';
172 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
174 LeaveCriticalSection(&This->csFilter);
176 return hr;
179 HRESULT WINAPI BaseFilterImpl_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
181 TRACE("(%p)->(%p)\n", iface, pVendorInfo);
182 return E_NOTIMPL;
185 LONG WINAPI BaseFilterImpl_GetPinVersion(BaseFilter * This)
187 TRACE("(%p)\n", This);
188 return This->pinVersion;
191 VOID WINAPI BaseFilterImpl_IncrementPinVersion(BaseFilter * This)
193 InterlockedIncrement(&This->pinVersion);
194 TRACE("(%p) -> New pinVersion %i\n", This,This->pinVersion);
197 HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseFilterFuncTable* pBaseFuncsTable)
199 This->IBaseFilter_iface.lpVtbl = Vtbl;
200 This->refCount = 1;
201 InitializeCriticalSection(&This->csFilter);
202 This->state = State_Stopped;
203 This->rtStreamStart = 0;
204 This->pClock = NULL;
205 ZeroMemory(&This->filterInfo, sizeof(FILTER_INFO));
206 This->clsid = *pClsid;
207 This->csFilter.DebugInfo->Spare[0] = DebugInfo;
208 This->pinVersion = 1;
210 This->pFuncsTable = pBaseFuncsTable;
212 return S_OK;
215 HRESULT WINAPI BaseFilter_Destroy(BaseFilter * This)
217 if (This->pClock)
218 IReferenceClock_Release(This->pClock);
220 This->IBaseFilter_iface.lpVtbl = NULL;
221 This->csFilter.DebugInfo->Spare[0] = 0;
222 DeleteCriticalSection(&This->csFilter);
224 return S_OK;