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 #include "strmbase_private.h"
23 static inline BaseFilter
*impl_from_IBaseFilter(IBaseFilter
*iface
)
25 return CONTAINING_RECORD(iface
, BaseFilter
, IBaseFilter_iface
);
28 HRESULT WINAPI
BaseFilterImpl_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
30 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
34 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IPersist
) ||
35 IsEqualIID(riid
, &IID_IMediaFilter
) || IsEqualIID(riid
, &IID_IBaseFilter
))
38 IBaseFilter_AddRef(iface
);
45 ULONG WINAPI
BaseFilterImpl_AddRef(IBaseFilter
* iface
)
47 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
48 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
50 TRACE("(%p)->() AddRef from %d\n", This
, refCount
- 1);
55 ULONG WINAPI
BaseFilterImpl_Release(IBaseFilter
* iface
)
57 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
58 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
60 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
65 IReferenceClock_Release(This
->pClock
);
67 This
->IBaseFilter_iface
.lpVtbl
= NULL
;
68 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
69 DeleteCriticalSection(&This
->csFilter
);
75 HRESULT WINAPI
BaseFilterImpl_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
77 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
78 TRACE("(%p)->(%p)\n", This
, pClsid
);
80 *pClsid
= This
->clsid
;
85 HRESULT WINAPI
BaseFilterImpl_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
87 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
88 TRACE("(%p)->(%d, %p)\n", This
, dwMilliSecsTimeout
, pState
);
90 EnterCriticalSection(&This
->csFilter
);
92 *pState
= This
->state
;
94 LeaveCriticalSection(&This
->csFilter
);
99 HRESULT WINAPI
BaseFilterImpl_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
101 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
102 TRACE("(%p)->(%p)\n", This
, pClock
);
104 EnterCriticalSection(&This
->csFilter
);
107 IReferenceClock_Release(This
->pClock
);
108 This
->pClock
= pClock
;
110 IReferenceClock_AddRef(This
->pClock
);
112 LeaveCriticalSection(&This
->csFilter
);
117 HRESULT WINAPI
BaseFilterImpl_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
119 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
120 TRACE("(%p)->(%p)\n", This
, ppClock
);
122 EnterCriticalSection(&This
->csFilter
);
124 *ppClock
= This
->pClock
;
126 IReferenceClock_AddRef(This
->pClock
);
128 LeaveCriticalSection(&This
->csFilter
);
133 HRESULT WINAPI
BaseFilterImpl_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
135 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
137 TRACE("(%p)->(%p)\n", iface
, ppEnum
);
139 return EnumPins_Construct(This
, This
->pFuncsTable
->pfnGetPin
, This
->pFuncsTable
->pfnGetPinCount
, BaseFilterImpl_GetPinVersion
, ppEnum
);
143 HRESULT WINAPI
BaseFilterImpl_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
145 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
146 TRACE("(%p)->(%p)\n", This
, pInfo
);
148 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
149 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
152 IFilterGraph_AddRef(pInfo
->pGraph
);
157 HRESULT WINAPI
BaseFilterImpl_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
160 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
162 TRACE("(%p)->(%p, %s)\n", This
, pGraph
, debugstr_w(pName
));
164 EnterCriticalSection(&This
->csFilter
);
167 strcpyW(This
->filterInfo
.achName
, pName
);
169 *This
->filterInfo
.achName
= '\0';
170 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
172 LeaveCriticalSection(&This
->csFilter
);
177 HRESULT WINAPI
BaseFilterImpl_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
179 TRACE("(%p)->(%p)\n", iface
, pVendorInfo
);
183 LONG WINAPI
BaseFilterImpl_GetPinVersion(BaseFilter
* This
)
185 TRACE("(%p)\n", This
);
186 return This
->pinVersion
;
189 VOID WINAPI
BaseFilterImpl_IncrementPinVersion(BaseFilter
* This
)
191 InterlockedIncrement(&This
->pinVersion
);
192 TRACE("(%p) -> New pinVersion %i\n", This
,This
->pinVersion
);
195 HRESULT WINAPI
BaseFilter_Init(BaseFilter
* This
, const IBaseFilterVtbl
*Vtbl
, const CLSID
*pClsid
, DWORD_PTR DebugInfo
, const BaseFilterFuncTable
* pBaseFuncsTable
)
197 This
->IBaseFilter_iface
.lpVtbl
= Vtbl
;
199 InitializeCriticalSection(&This
->csFilter
);
200 This
->state
= State_Stopped
;
201 This
->rtStreamStart
= 0;
203 ZeroMemory(&This
->filterInfo
, sizeof(FILTER_INFO
));
204 This
->clsid
= *pClsid
;
205 This
->csFilter
.DebugInfo
->Spare
[0] = DebugInfo
;
206 This
->pinVersion
= 1;
208 This
->pFuncsTable
= pBaseFuncsTable
;