2010-10-07 21:47:33 +02:00
|
|
|
/*
|
|
|
|
* Generic Implementation of IBaseFilter Interface
|
|
|
|
*
|
|
|
|
* Copyright 2010 Aric Stewart, CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-09 17:12:32 +02:00
|
|
|
#include "strmbase_private.h"
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
|
|
|
|
|
2012-03-24 17:42:27 +01:00
|
|
|
static inline BaseFilter *impl_from_IBaseFilter(IBaseFilter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BaseFilter, IBaseFilter_iface);
|
|
|
|
}
|
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
HRESULT WINAPI BaseFilterImpl_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
2014-02-20 00:10:51 +01:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IPersist) ||
|
|
|
|
IsEqualIID(riid, &IID_IMediaFilter) || IsEqualIID(riid, &IID_IBaseFilter))
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2014-02-20 00:10:51 +01:00
|
|
|
*ppv = iface;
|
|
|
|
IBaseFilter_AddRef(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI BaseFilterImpl_AddRef(IBaseFilter * iface)
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->refCount);
|
|
|
|
|
|
|
|
TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
|
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI BaseFilterImpl_Release(IBaseFilter * iface)
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->refCount);
|
|
|
|
|
|
|
|
TRACE("(%p)->() Release from %d\n", This, refCount + 1);
|
|
|
|
|
|
|
|
if (!refCount)
|
2019-05-22 07:02:12 +02:00
|
|
|
strmbase_filter_cleanup(This);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseFilterImpl_GetClassID(IBaseFilter * iface, CLSID * pClsid)
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pClsid);
|
|
|
|
|
|
|
|
*pClsid = This->clsid;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseFilterImpl_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState )
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
TRACE("(%p)->(%d, %p)\n", This, dwMilliSecsTimeout, pState);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->csFilter);
|
|
|
|
{
|
|
|
|
*pState = This->state;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->csFilter);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseFilterImpl_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pClock);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->csFilter);
|
|
|
|
{
|
|
|
|
if (This->pClock)
|
|
|
|
IReferenceClock_Release(This->pClock);
|
|
|
|
This->pClock = pClock;
|
|
|
|
if (This->pClock)
|
|
|
|
IReferenceClock_AddRef(This->pClock);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->csFilter);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseFilterImpl_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, ppClock);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->csFilter);
|
|
|
|
{
|
|
|
|
*ppClock = This->pClock;
|
|
|
|
if (This->pClock)
|
|
|
|
IReferenceClock_AddRef(This->pClock);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->csFilter);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
HRESULT WINAPI BaseFilterImpl_EnumPins(IBaseFilter *iface, IEnumPins **enum_pins)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2019-05-14 05:17:54 +02:00
|
|
|
BaseFilter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
TRACE("iface %p, enum_pins %p.\n", iface, enum_pins);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
return enum_pins_create(filter, enum_pins);
|
2010-10-07 21:48:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 23:56:51 +02:00
|
|
|
HRESULT WINAPI BaseFilterImpl_FindPin(IBaseFilter *iface, const WCHAR *id, IPin **ret)
|
|
|
|
{
|
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
|
|
|
PIN_INFO info;
|
|
|
|
HRESULT hr;
|
|
|
|
IPin *pin;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_w(id), ret);
|
|
|
|
|
2019-05-14 05:17:57 +02:00
|
|
|
for (i = 0; (pin = This->pFuncsTable->pfnGetPin(This, i)); ++i)
|
2018-07-03 23:56:51 +02:00
|
|
|
{
|
|
|
|
hr = IPin_QueryPinInfo(pin, &info);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPin_Release(pin);
|
|
|
|
return hr;
|
|
|
|
}
|
2018-07-05 20:02:39 +02:00
|
|
|
if (info.pFilter) IBaseFilter_Release(info.pFilter);
|
2018-07-03 23:56:51 +02:00
|
|
|
|
2019-05-03 12:32:45 +02:00
|
|
|
if (!lstrcmpW(id, info.achName))
|
2018-07-03 23:56:51 +02:00
|
|
|
{
|
|
|
|
*ret = pin;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPin_Release(pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return VFW_E_NOT_FOUND;
|
|
|
|
}
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
HRESULT WINAPI BaseFilterImpl_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pInfo);
|
|
|
|
|
2019-05-03 12:32:45 +02:00
|
|
|
lstrcpyW(pInfo->achName, This->filterInfo.achName);
|
2010-10-07 21:47:33 +02:00
|
|
|
pInfo->pGraph = This->filterInfo.pGraph;
|
|
|
|
|
|
|
|
if (pInfo->pGraph)
|
|
|
|
IFilterGraph_AddRef(pInfo->pGraph);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseFilterImpl_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName )
|
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
BaseFilter *This = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %s)\n", This, pGraph, debugstr_w(pName));
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->csFilter);
|
|
|
|
{
|
|
|
|
if (pName)
|
2019-05-03 12:32:45 +02:00
|
|
|
lstrcpyW(This->filterInfo.achName, pName);
|
2010-10-07 21:47:33 +02:00
|
|
|
else
|
|
|
|
*This->filterInfo.achName = '\0';
|
|
|
|
This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->csFilter);
|
|
|
|
|
2015-10-19 10:57:50 +02:00
|
|
|
return S_OK;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseFilterImpl_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%p)\n", iface, pVendorInfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
VOID WINAPI BaseFilterImpl_IncrementPinVersion(BaseFilter *filter)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2019-05-14 05:17:54 +02:00
|
|
|
InterlockedIncrement(&filter->pin_version);
|
2010-10-07 21:48:01 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 02:41:59 +02:00
|
|
|
void BaseFilter_Init(BaseFilter *This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid,
|
|
|
|
DWORD_PTR DebugInfo, const BaseFilterFuncTable *pBaseFuncsTable)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
This->IBaseFilter_iface.lpVtbl = Vtbl;
|
2010-10-07 21:47:33 +02:00
|
|
|
This->refCount = 1;
|
|
|
|
InitializeCriticalSection(&This->csFilter);
|
|
|
|
This->state = State_Stopped;
|
|
|
|
This->rtStreamStart = 0;
|
|
|
|
This->pClock = NULL;
|
|
|
|
ZeroMemory(&This->filterInfo, sizeof(FILTER_INFO));
|
|
|
|
This->clsid = *pClsid;
|
|
|
|
This->csFilter.DebugInfo->Spare[0] = DebugInfo;
|
2019-05-14 05:17:54 +02:00
|
|
|
This->pin_version = 1;
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2010-10-13 18:02:01 +02:00
|
|
|
This->pFuncsTable = pBaseFuncsTable;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
2014-07-18 22:19:40 +02:00
|
|
|
|
2019-05-22 07:02:13 +02:00
|
|
|
void strmbase_filter_cleanup(BaseFilter *This)
|
2014-07-18 22:19:40 +02:00
|
|
|
{
|
|
|
|
if (This->pClock)
|
|
|
|
IReferenceClock_Release(This->pClock);
|
|
|
|
|
|
|
|
This->IBaseFilter_iface.lpVtbl = NULL;
|
|
|
|
This->csFilter.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->csFilter);
|
|
|
|
}
|