ReactOS  0.4.14-dev-614-gbfd8a84
filter.c
Go to the documentation of this file.
1 /*
2  * Generic Implementation of IBaseFilter Interface
3  *
4  * Copyright 2010 Aric Stewart, CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #define COBJMACROS
22 
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>
29 
31 
33 {
34  return CONTAINING_RECORD(iface, BaseFilter, IBaseFilter_iface);
35 }
36 
38 {
39  TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
40 
41  *ppv = NULL;
42 
44  IsEqualIID(riid, &IID_IMediaFilter) || IsEqualIID(riid, &IID_IBaseFilter))
45  {
46  *ppv = iface;
47  IBaseFilter_AddRef(iface);
48  return S_OK;
49  }
50 
51  return E_NOINTERFACE;
52 }
53 
55 {
57  ULONG refCount = InterlockedIncrement(&This->refCount);
58 
59  TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
60 
61  return refCount;
62 }
63 
65 {
67  ULONG refCount = InterlockedDecrement(&This->refCount);
68 
69  TRACE("(%p)->() Release from %d\n", This, refCount + 1);
70 
71  if (!refCount)
73 
74  return refCount;
75 }
76 
78 {
80  TRACE("(%p)->(%p)\n", This, pClsid);
81 
82  *pClsid = This->clsid;
83 
84  return S_OK;
85 }
86 
87 HRESULT WINAPI BaseFilterImpl_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState )
88 {
90  TRACE("(%p)->(%d, %p)\n", This, dwMilliSecsTimeout, pState);
91 
92  EnterCriticalSection(&This->csFilter);
93  {
94  *pState = This->state;
95  }
96  LeaveCriticalSection(&This->csFilter);
97 
98  return S_OK;
99 }
100 
102 {
104  TRACE("(%p)->(%p)\n", This, pClock);
105 
106  EnterCriticalSection(&This->csFilter);
107  {
108  if (This->pClock)
109  IReferenceClock_Release(This->pClock);
110  This->pClock = pClock;
111  if (This->pClock)
112  IReferenceClock_AddRef(This->pClock);
113  }
114  LeaveCriticalSection(&This->csFilter);
115 
116  return S_OK;
117 }
118 
120 {
122  TRACE("(%p)->(%p)\n", This, ppClock);
123 
124  EnterCriticalSection(&This->csFilter);
125  {
126  *ppClock = This->pClock;
127  if (This->pClock)
128  IReferenceClock_AddRef(This->pClock);
129  }
130  LeaveCriticalSection(&This->csFilter);
131 
132  return S_OK;
133 }
134 
136 {
138 
139  TRACE("(%p)->(%p)\n", iface, ppEnum);
140 
141  return EnumPins_Construct(This, This->pFuncsTable->pfnGetPin, This->pFuncsTable->pfnGetPinCount, BaseFilterImpl_GetPinVersion, ppEnum);
142 }
143 
144 
146 {
148  TRACE("(%p)->(%p)\n", This, pInfo);
149 
150  strcpyW(pInfo->achName, This->filterInfo.achName);
151  pInfo->pGraph = This->filterInfo.pGraph;
152 
153  if (pInfo->pGraph)
154  IFilterGraph_AddRef(pInfo->pGraph);
155 
156  return S_OK;
157 }
158 
160 {
162 
163  TRACE("(%p)->(%p, %s)\n", This, pGraph, debugstr_w(pName));
164 
165  EnterCriticalSection(&This->csFilter);
166  {
167  if (pName)
168  strcpyW(This->filterInfo.achName, pName);
169  else
170  *This->filterInfo.achName = '\0';
171  This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
172  }
173  LeaveCriticalSection(&This->csFilter);
174 
175  return S_OK;
176 }
177 
179 {
180  TRACE("(%p)->(%p)\n", iface, pVendorInfo);
181  return E_NOTIMPL;
182 }
183 
185 {
186  TRACE("(%p)\n", This);
187  return This->pinVersion;
188 }
189 
191 {
192  InterlockedIncrement(&This->pinVersion);
193  TRACE("(%p) -> New pinVersion %i\n", This,This->pinVersion);
194 }
195 
196 HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseFilterFuncTable* pBaseFuncsTable)
197 {
198  This->IBaseFilter_iface.lpVtbl = Vtbl;
199  This->refCount = 1;
200  InitializeCriticalSection(&This->csFilter);
201  This->state = State_Stopped;
202  This->rtStreamStart = 0;
203  This->pClock = NULL;
204  ZeroMemory(&This->filterInfo, sizeof(FILTER_INFO));
205  This->clsid = *pClsid;
206  This->csFilter.DebugInfo->Spare[0] = DebugInfo;
207  This->pinVersion = 1;
208 
209  This->pFuncsTable = pBaseFuncsTable;
210 
211  return S_OK;
212 }
213 
215 {
216  if (This->pClock)
217  IReferenceClock_Release(This->pClock);
218 
219  This->IBaseFilter_iface.lpVtbl = NULL;
220  This->csFilter.DebugInfo->Spare[0] = 0;
221  DeleteCriticalSection(&This->csFilter);
222 
223  return S_OK;
224 }
HRESULT WINAPI BaseFilter_Destroy(BaseFilter *This)
Definition: filter.c:214
const GUID IID_IBaseFilter
VOID WINAPI BaseFilterImpl_IncrementPinVersion(BaseFilter *This)
Definition: filter.c:190
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static BaseFilter * impl_from_IBaseFilter(IBaseFilter *iface)
Definition: filter.c:32
REFIID riid
Definition: precomp.h:44
ULONG WINAPI BaseFilterImpl_Release(IBaseFilter *iface)
Definition: filter.c:64
const GUID IID_IPersist
Definition: proxy.cpp:14
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT WINAPI BaseFilterImpl_SetSyncSource(IBaseFilter *iface, IReferenceClock *pClock)
Definition: filter.c:101
#define ZeroMemory
Definition: winbase.h:1642
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
HRESULT WINAPI BaseFilterImpl_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *pInfo)
Definition: filter.c:145
long LONG
Definition: pedump.c:60
HRESULT WINAPI BaseFilter_Init(BaseFilter *This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseFilterFuncTable *pBaseFuncsTable)
Definition: filter.c:196
#define debugstr_w
Definition: kernel32.h:32
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
HRESULT WINAPI BaseFilterImpl_GetSyncSource(IBaseFilter *iface, IReferenceClock **ppClock)
Definition: filter.c:119
#define TRACE(s)
Definition: solgame.cpp:4
static LPSTR pName
Definition: security.c:75
HRESULT WINAPI BaseFilterImpl_JoinFilterGraph(IBaseFilter *iface, IFilterGraph *pGraph, LPCWSTR pName)
Definition: filter.c:159
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT WINAPI BaseFilterImpl_GetClassID(IBaseFilter *iface, CLSID *pClsid)
Definition: filter.c:77
HRESULT WINAPI BaseFilterImpl_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
Definition: filter.c:87
WINE_DEFAULT_DEBUG_CHANNEL(msacm)
HRESULT WINAPI BaseFilterImpl_EnumPins(IBaseFilter *iface, IEnumPins **ppEnum)
Definition: filter.c:135
#define InterlockedDecrement
Definition: armddk.h:52
HRESULT WINAPI BaseFilterImpl_QueryInterface(IBaseFilter *iface, REFIID riid, LPVOID *ppv)
Definition: filter.c:37
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define S_OK
Definition: intsafe.h:59
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
#define InterlockedIncrement
Definition: armddk.h:53
#define IReferenceClock_Release(p)
Definition: dmusicc.h:752
HRESULT WINAPI EnumPins_Construct(BaseFilter *base, BaseFilter_GetPin receive_pin, BaseFilter_GetPinCount receive_pincount, BaseFilter_GetPinVersion receive_version, IEnumPins **ppEnum)
Definition: enumpins.c:49
#define E_NOTIMPL
Definition: ddrawi.h:99
ULONG WINAPI BaseFilterImpl_AddRef(IBaseFilter *iface)
Definition: filter.c:54
LONG WINAPI BaseFilterImpl_GetPinVersion(BaseFilter *This)
Definition: filter.c:184
HRESULT WINAPI BaseFilterImpl_QueryVendorInfo(IBaseFilter *iface, LPWSTR *pVendorInfo)
Definition: filter.c:178
unsigned int ULONG
Definition: retypes.h:1
#define IReferenceClock_AddRef(p)
Definition: dmusicc.h:751
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95