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
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
26 #include "wine/strmbase.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
);
44 if (IsEqualIID(riid
, &IID_IUnknown
))
46 else if (IsEqualIID(riid
, &IID_IPersist
))
48 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
50 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
55 IUnknown_AddRef((IUnknown
*)(*ppv
));
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);
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);
82 IReferenceClock_Release(This
->pClock
);
84 This
->IBaseFilter_iface
.lpVtbl
= NULL
;
85 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
86 DeleteCriticalSection(&This
->csFilter
);
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
;
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
);
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
);
124 IReferenceClock_Release(This
->pClock
);
125 This
->pClock
= pClock
;
127 IReferenceClock_AddRef(This
->pClock
);
129 LeaveCriticalSection(&This
->csFilter
);
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
;
143 IReferenceClock_AddRef(This
->pClock
);
145 LeaveCriticalSection(&This
->csFilter
);
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
;
169 IFilterGraph_AddRef(pInfo
->pGraph
);
174 HRESULT WINAPI
BaseFilterImpl_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
177 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
179 TRACE("(%p)->(%p, %s)\n", This
, pGraph
, debugstr_w(pName
));
181 EnterCriticalSection(&This
->csFilter
);
184 strcpyW(This
->filterInfo
.achName
, pName
);
186 *This
->filterInfo
.achName
= '\0';
187 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
189 LeaveCriticalSection(&This
->csFilter
);
194 HRESULT WINAPI
BaseFilterImpl_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
196 TRACE("(%p)->(%p)\n", iface
, pVendorInfo
);
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
;
216 InitializeCriticalSection(&This
->csFilter
);
217 This
->state
= State_Stopped
;
218 This
->rtStreamStart
= 0;
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
;