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 HRESULT WINAPI
BaseFilterImpl_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
34 BaseFilter
*This
= (BaseFilter
*)iface
;
35 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
39 if (IsEqualIID(riid
, &IID_IUnknown
))
41 else if (IsEqualIID(riid
, &IID_IPersist
))
43 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
45 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
50 IUnknown_AddRef((IUnknown
*)(*ppv
));
57 ULONG WINAPI
BaseFilterImpl_AddRef(IBaseFilter
* iface
)
59 BaseFilter
*This
= (BaseFilter
*)iface
;
60 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
62 TRACE("(%p)->() AddRef from %d\n", This
, refCount
- 1);
67 ULONG WINAPI
BaseFilterImpl_Release(IBaseFilter
* iface
)
69 BaseFilter
*This
= (BaseFilter
*)iface
;
70 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
72 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
77 IReferenceClock_Release(This
->pClock
);
80 This
->csFilter
.DebugInfo
->Spare
[0] = 0;
81 DeleteCriticalSection(&This
->csFilter
);
87 HRESULT WINAPI
BaseFilterImpl_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
89 BaseFilter
*This
= (BaseFilter
*)iface
;
90 TRACE("(%p)->(%p)\n", This
, pClsid
);
92 *pClsid
= This
->clsid
;
97 HRESULT WINAPI
BaseFilterImpl_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
99 BaseFilter
*This
= (BaseFilter
*)iface
;
100 TRACE("(%p)->(%d, %p)\n", This
, dwMilliSecsTimeout
, pState
);
102 EnterCriticalSection(&This
->csFilter
);
104 *pState
= This
->state
;
106 LeaveCriticalSection(&This
->csFilter
);
111 HRESULT WINAPI
BaseFilterImpl_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
113 BaseFilter
*This
= (BaseFilter
*)iface
;
114 TRACE("(%p)->(%p)\n", This
, pClock
);
116 EnterCriticalSection(&This
->csFilter
);
119 IReferenceClock_Release(This
->pClock
);
120 This
->pClock
= pClock
;
122 IReferenceClock_AddRef(This
->pClock
);
124 LeaveCriticalSection(&This
->csFilter
);
129 HRESULT WINAPI
BaseFilterImpl_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
131 BaseFilter
*This
= (BaseFilter
*)iface
;
132 TRACE("(%p)->(%p)\n", This
, ppClock
);
134 EnterCriticalSection(&This
->csFilter
);
136 *ppClock
= This
->pClock
;
138 IReferenceClock_AddRef(This
->pClock
);
140 LeaveCriticalSection(&This
->csFilter
);
145 HRESULT WINAPI
BaseFilterImpl_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
147 BaseFilter
*This
= (BaseFilter
*)iface
;
149 TRACE("(%p)->(%p)\n", iface
, ppEnum
);
151 return EnumPins_Construct(iface
, This
->pfnGetPin
, This
->pfnGetPinCount
, BaseFilterImpl_GetPinVersion
, ppEnum
);
155 HRESULT WINAPI
BaseFilterImpl_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
157 BaseFilter
*This
= (BaseFilter
*)iface
;
158 TRACE("(%p)->(%p)\n", This
, pInfo
);
160 strcpyW(pInfo
->achName
, This
->filterInfo
.achName
);
161 pInfo
->pGraph
= This
->filterInfo
.pGraph
;
164 IFilterGraph_AddRef(pInfo
->pGraph
);
169 HRESULT WINAPI
BaseFilterImpl_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
172 BaseFilter
*This
= (BaseFilter
*)iface
;
174 TRACE("(%p)->(%p, %s)\n", This
, pGraph
, debugstr_w(pName
));
176 EnterCriticalSection(&This
->csFilter
);
179 strcpyW(This
->filterInfo
.achName
, pName
);
181 *This
->filterInfo
.achName
= '\0';
182 This
->filterInfo
.pGraph
= pGraph
; /* NOTE: do NOT increase ref. count */
184 LeaveCriticalSection(&This
->csFilter
);
189 HRESULT WINAPI
BaseFilterImpl_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
191 TRACE("(%p)->(%p)\n", iface
, pVendorInfo
);
195 LONG WINAPI
BaseFilterImpl_GetPinVersion(IBaseFilter
* iface
)
197 BaseFilter
* This
= (BaseFilter
*)iface
;
198 TRACE("(%p)\n", This
);
199 return This
->pinVersion
;
202 VOID WINAPI
BaseFilterImpl_IncrementPinVersion(IBaseFilter
* iface
)
204 BaseFilter
* This
= (BaseFilter
*)iface
;
205 InterlockedIncrement(&This
->pinVersion
);
206 TRACE("(%p) -> New pinVersion %i\n", This
,This
->pinVersion
);
209 HRESULT WINAPI
BaseFilter_Init(BaseFilter
* This
, const IBaseFilterVtbl
*Vtbl
, const CLSID
*pClsid
, DWORD_PTR DebugInfo
, BaseFilter_GetPin pfGetPin
, BaseFilter_GetPinCount pfGetPinCount
)
213 InitializeCriticalSection(&This
->csFilter
);
214 This
->state
= State_Stopped
;
215 This
->rtStreamStart
= 0;
217 ZeroMemory(&This
->filterInfo
, sizeof(FILTER_INFO
));
218 This
->clsid
= *pClsid
;
219 This
->csFilter
.DebugInfo
->Spare
[0] = DebugInfo
;
220 This
->pinVersion
= 1;
222 This
->pfnGetPin
= pfGetPin
;
223 This
->pfnGetPinCount
= pfGetPinCount
;