2003-08-07 00:04:45 +02:00
|
|
|
/*
|
|
|
|
* Implementation of IEnumPins Interface
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
2010-10-06 16:48:07 +02:00
|
|
|
* Copyright 2010 Aric Stewart, CodeWeavers
|
2003-08-07 00:04:45 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-07 00:04:45 +02:00
|
|
|
*/
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
#define COBJMACROS
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
#include "dshow.h"
|
|
|
|
#include "wine/strmbase.h"
|
2003-08-07 00:04:45 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
typedef struct IEnumPinsImpl
|
|
|
|
{
|
|
|
|
const IEnumPinsVtbl * lpVtbl;
|
2005-07-12 21:21:36 +02:00
|
|
|
LONG refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
ULONG uIndex;
|
2008-04-25 23:25:49 +02:00
|
|
|
IBaseFilter *base;
|
2010-10-06 16:48:07 +02:00
|
|
|
BaseFilter_GetPin receive_pin;
|
|
|
|
BaseFilter_GetPinCount receive_pincount;
|
|
|
|
BaseFilter_GetPinVersion receive_version;
|
|
|
|
DWORD Version;
|
2003-08-07 00:04:45 +02:00
|
|
|
} IEnumPinsImpl;
|
|
|
|
|
|
|
|
static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
HRESULT WINAPI EnumPins_Construct(IBaseFilter *base, BaseFilter_GetPin receive_pin, BaseFilter_GetPinCount receive_pincount, BaseFilter_GetPinVersion receive_version, IEnumPins ** ppEnum)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2008-04-20 00:19:32 +02:00
|
|
|
IEnumPinsImpl * pEnumPins;
|
|
|
|
|
|
|
|
if (!ppEnum)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
pEnumPins = CoTaskMemAlloc(sizeof(IEnumPinsImpl));
|
2003-08-07 00:04:45 +02:00
|
|
|
if (!pEnumPins)
|
|
|
|
{
|
|
|
|
*ppEnum = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
pEnumPins->lpVtbl = &IEnumPinsImpl_Vtbl;
|
|
|
|
pEnumPins->refCount = 1;
|
|
|
|
pEnumPins->uIndex = 0;
|
2008-04-25 23:25:49 +02:00
|
|
|
pEnumPins->receive_pin = receive_pin;
|
2010-10-06 16:48:07 +02:00
|
|
|
pEnumPins->receive_pincount = receive_pincount;
|
|
|
|
pEnumPins->receive_version = receive_version;
|
2008-04-25 23:25:49 +02:00
|
|
|
pEnumPins->base = base;
|
|
|
|
IBaseFilter_AddRef(base);
|
2003-08-07 00:04:45 +02:00
|
|
|
*ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
|
2010-10-06 16:48:07 +02:00
|
|
|
pEnumPins->Version = receive_version(base);
|
2008-04-25 23:25:49 +02:00
|
|
|
|
2007-03-05 15:11:37 +01:00
|
|
|
TRACE("Created new enumerator (%p)\n", *ppEnum);
|
2003-08-07 00:04:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2010-10-06 16:48:07 +02:00
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
2009-01-29 11:14:55 +01:00
|
|
|
*ppv = iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IEnumPins))
|
2009-01-29 11:14:55 +01:00
|
|
|
*ppv = iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
FIXME("No interface for %s!\n", debugstr_guid(riid));
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumPinsImpl_AddRef(IEnumPins * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->refCount);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2007-03-05 15:11:37 +01:00
|
|
|
TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->refCount);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2007-03-05 15:11:37 +01:00
|
|
|
TRACE("(%p)->() Release from %d\n", This, refCount + 1);
|
2008-04-25 23:25:49 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!refCount)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2008-04-25 23:25:49 +02:00
|
|
|
IBaseFilter_Release(This->base);
|
2003-08-07 00:04:45 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
|
2008-04-25 23:25:49 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
ULONG i = 0;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%u, %p, %p)\n", cPins, ppPins, pcFetched);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-04-20 00:19:32 +02:00
|
|
|
if (!ppPins)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (cPins > 1 && !pcFetched)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
if (pcFetched)
|
|
|
|
*pcFetched = 0;
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
if (This->Version != This->receive_version(This->base))
|
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
while (i < cPins && hr == S_OK)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2010-10-06 16:48:07 +02:00
|
|
|
IPin *pin;
|
|
|
|
pin = This->receive_pin(This->base, This->uIndex + i);
|
|
|
|
|
|
|
|
if (!pin)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
ppPins[i] = pin;
|
|
|
|
++i;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
if (pcFetched)
|
|
|
|
*pcFetched = i;
|
|
|
|
This->uIndex += i;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
if (i < cPins)
|
2003-08-07 00:04:45 +02:00
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins * iface, ULONG cPins)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%u)\n", cPins);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
if (This->Version != This->receive_version(This->base))
|
2008-04-25 23:25:49 +02:00
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
if (This->receive_pincount(This->base) >= This->uIndex + cPins)
|
|
|
|
return S_FALSE;
|
2008-04-25 23:25:49 +02:00
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
This->uIndex += cPins;
|
|
|
|
return S_OK;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("IEnumPinsImpl::Reset()\n");
|
2010-10-06 16:48:07 +02:00
|
|
|
This->Version = This->receive_version(This->base);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
This->uIndex = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins * iface, IEnumPins ** ppEnum)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", ppEnum);
|
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
hr = EnumPins_Construct(This->base, This->receive_pin, This->receive_pincount, This->receive_version, ppEnum);
|
2003-08-07 00:04:45 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
return IEnumPins_Skip(*ppEnum, This->uIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
|
|
|
|
{
|
|
|
|
IEnumPinsImpl_QueryInterface,
|
|
|
|
IEnumPinsImpl_AddRef,
|
|
|
|
IEnumPinsImpl_Release,
|
|
|
|
IEnumPinsImpl_Next,
|
|
|
|
IEnumPinsImpl_Skip,
|
|
|
|
IEnumPinsImpl_Reset,
|
|
|
|
IEnumPinsImpl_Clone
|
|
|
|
};
|