2003-08-07 00:04:45 +02:00
|
|
|
/*
|
|
|
|
* Implementation of IEnumPins Interface
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
|
|
|
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;
|
|
|
|
FNOBTAINPIN receive_pin;
|
|
|
|
DWORD synctime;
|
2003-08-07 00:04:45 +02:00
|
|
|
} IEnumPinsImpl;
|
|
|
|
|
|
|
|
static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
|
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
HRESULT IEnumPinsImpl_Construct(IEnumPins ** ppEnum, FNOBTAINPIN receive_pin, IBaseFilter *base)
|
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;
|
|
|
|
pEnumPins->base = base;
|
|
|
|
IBaseFilter_AddRef(base);
|
2003-08-07 00:04:45 +02:00
|
|
|
*ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
|
2007-03-05 15:11:37 +01:00
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
receive_pin(base, ~0, NULL, &pEnumPins->synctime);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
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
|
|
|
DWORD synctime = This->synctime;
|
|
|
|
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;
|
|
|
|
|
|
|
|
while (i < cPins && hr == S_OK)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2008-04-25 23:25:49 +02:00
|
|
|
hr = This->receive_pin(This->base, This->uIndex + i, &ppPins[i], &synctime);
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if (synctime != This->synctime)
|
|
|
|
break;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
if (!i && synctime != This->synctime)
|
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
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;
|
2008-04-25 23:25:49 +02:00
|
|
|
DWORD synctime = This->synctime;
|
|
|
|
HRESULT hr;
|
|
|
|
IPin *pin = NULL;
|
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
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
hr = This->receive_pin(This->base, This->uIndex + cPins, &pin, &synctime);
|
|
|
|
if (pin)
|
|
|
|
IPin_Release(pin);
|
|
|
|
|
|
|
|
if (synctime != This->synctime)
|
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
2003-08-07 00:04:45 +02:00
|
|
|
This->uIndex += cPins;
|
2008-04-25 23:25:49 +02:00
|
|
|
|
|
|
|
return hr;
|
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");
|
2008-04-25 23:25:49 +02:00
|
|
|
This->receive_pin(This->base, ~0, NULL, &This->synctime);
|
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);
|
|
|
|
|
2008-04-25 23:25:49 +02:00
|
|
|
hr = IEnumPinsImpl_Construct(ppEnum, This->receive_pin, This->base);
|
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
|
|
|
|
};
|