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 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
43 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IPersist
) ||
44 IsEqualIID(riid
, &IID_IMediaFilter
) || IsEqualIID(riid
, &IID_IBaseFilter
))
47 IBaseFilter_AddRef(iface
);
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);
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);
72 BaseFilter_Destroy(This
);
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
;
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
);
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
);
109 IReferenceClock_Release(This
->pClock
);
110 This
->pClock
= pClock
;
112 IReferenceClock_AddRef(This
->pClock
);
114 LeaveCriticalSection(&This
->csFilter
);
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
;
128 IReferenceClock_AddRef(This
->pClock
);
130 LeaveCriticalSection(&This
->csFilter
);
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
;
154 IFilterGraph_AddRef(pInfo
->pGraph
);
159 HRESULT WINAPI
BaseFilterImpl_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
162 BaseFilter
*This
= impl_from_IBaseFilter(iface
);
164 TRACE("(%p)->(%p, %s)\n", This
, pGraph
, debugstr_w(pName
));
166 EnterCriticalSection(&This
->csFilter
);
169 strcpyW(This
->filterInfo
.achName
, pName
);
171 *This
->filterInfo
.achName
= '\0';
172 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
174 LeaveCriticalSection(&This
->csFilter
);
179 HRESULT WINAPI
BaseFilterImpl_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
181 TRACE("(%p)->(%p)\n", iface
, pVendorInfo
);
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
;
201 InitializeCriticalSection(&This
->csFilter
);
202 This
->state
= State_Stopped
;
203 This
->rtStreamStart
= 0;
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
;
215 HRESULT WINAPI
BaseFilter_Destroy(BaseFilter
* This
)
218 IReferenceClock_Release(This
->pClock
);
220 This
->IBaseFilter_iface
.lpVtbl
= NULL
;
221 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
222 DeleteCriticalSection(&This
->csFilter
);