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
|
|
|
*/
|
|
|
|
|
2019-05-09 17:12:32 +02:00
|
|
|
#include "strmbase_private.h"
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2010-10-06 16:48:07 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
typedef struct IEnumPinsImpl
|
|
|
|
{
|
2010-12-08 22:59:21 +01:00
|
|
|
IEnumPins IEnumPins_iface;
|
2005-07-12 21:21:36 +02:00
|
|
|
LONG refCount;
|
2019-05-14 05:17:56 +02:00
|
|
|
unsigned int uIndex, count;
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *base;
|
2010-10-06 16:48:07 +02:00
|
|
|
DWORD Version;
|
2003-08-07 00:04:45 +02:00
|
|
|
} IEnumPinsImpl;
|
|
|
|
|
2010-12-08 22:59:21 +01:00
|
|
|
static inline IEnumPinsImpl *impl_from_IEnumPins(IEnumPins *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IEnumPinsImpl, IEnumPins_iface);
|
|
|
|
}
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
HRESULT enum_pins_create(struct strmbase_filter *base, IEnumPins **out)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2019-05-15 02:41:56 +02:00
|
|
|
IEnumPinsImpl *object;
|
2008-04-20 00:19:32 +02:00
|
|
|
|
2019-05-15 02:41:56 +02:00
|
|
|
if (!out)
|
2008-04-20 00:19:32 +02:00
|
|
|
return E_POINTER;
|
|
|
|
|
2019-05-15 02:41:56 +02:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2019-05-15 02:41:56 +02:00
|
|
|
*out = NULL;
|
2003-08-07 00:04:45 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2019-05-15 02:41:56 +02:00
|
|
|
|
|
|
|
object->IEnumPins_iface.lpVtbl = &IEnumPinsImpl_Vtbl;
|
|
|
|
object->refCount = 1;
|
|
|
|
object->base = base;
|
2012-03-24 17:42:27 +01:00
|
|
|
IBaseFilter_AddRef(&base->IBaseFilter_iface);
|
2019-05-15 02:41:56 +02:00
|
|
|
object->Version = base->pin_version;
|
2019-05-14 05:17:56 +02:00
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
while (base->ops->filter_get_pin(base, object->count))
|
2019-05-15 02:41:56 +02:00
|
|
|
++object->count;
|
2008-04-25 23:25:49 +02:00
|
|
|
|
2019-05-15 02:41:56 +02:00
|
|
|
TRACE("Created enumerator %p.\n", object);
|
|
|
|
*out = &object->IEnumPins_iface;
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2013-06-04 09:33:57 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, 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)
|
|
|
|
{
|
2010-12-08 22:59:21 +01:00
|
|
|
IEnumPinsImpl *This = impl_from_IEnumPins(iface);
|
2013-06-04 09:33:57 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->refCount);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2013-06-04 09:33:57 +02:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2013-06-04 09:33:57 +02:00
|
|
|
return ref;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
|
|
|
|
{
|
2010-12-08 22:59:21 +01:00
|
|
|
IEnumPinsImpl *This = impl_from_IEnumPins(iface);
|
2013-06-04 09:33:57 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->refCount);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2013-06-04 09:33:57 +02:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2008-04-25 23:25:49 +02:00
|
|
|
|
2013-06-04 09:33:57 +02:00
|
|
|
if (!ref)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2012-03-24 17:42:27 +01:00
|
|
|
IBaseFilter_Release(&This->base->IBaseFilter_iface);
|
2019-05-15 02:41:56 +02:00
|
|
|
heap_free(This);
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
2013-06-04 09:33:57 +02:00
|
|
|
|
|
|
|
return ref;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
|
|
|
|
{
|
2010-12-08 22:59:21 +01:00
|
|
|
IEnumPinsImpl *This = impl_from_IEnumPins(iface);
|
2019-06-11 16:42:16 +02:00
|
|
|
ULONG i;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2013-06-04 09:33:57 +02:00
|
|
|
TRACE("(%p)->(%u, %p, %p)\n", iface, 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;
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
if (This->Version != This->base->pin_version)
|
2010-10-06 16:48:07 +02:00
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
|
|
|
|
2019-06-11 16:42:16 +02:00
|
|
|
for (i = 0; i < cPins; ++i)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2019-11-23 04:13:59 +01:00
|
|
|
struct strmbase_pin *pin = This->base->ops->filter_get_pin(This->base, This->uIndex + i);
|
2019-06-11 16:42:16 +02:00
|
|
|
|
|
|
|
if (!pin)
|
|
|
|
break;
|
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
IPin_AddRef(ppPins[i] = &pin->IPin_iface);
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-27 06:36:23 +02:00
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins *iface, ULONG count)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2018-09-27 06:36:23 +02:00
|
|
|
IEnumPinsImpl *enum_pins = impl_from_IEnumPins(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2018-09-27 06:36:23 +02:00
|
|
|
TRACE("enum_pins %p, count %u.\n", enum_pins, count);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
if (enum_pins->Version != enum_pins->base->pin_version)
|
2008-04-25 23:25:49 +02:00
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
|
|
|
|
2019-05-14 05:17:56 +02:00
|
|
|
if (enum_pins->uIndex + count > enum_pins->count)
|
2010-10-06 16:48:07 +02:00
|
|
|
return S_FALSE;
|
2008-04-25 23:25:49 +02:00
|
|
|
|
2018-09-27 06:36:23 +02:00
|
|
|
enum_pins->uIndex += count;
|
2010-10-06 16:48:07 +02:00
|
|
|
return S_OK;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins *iface)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2019-05-14 05:17:54 +02:00
|
|
|
IEnumPinsImpl *enum_pins = impl_from_IEnumPins(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
2013-06-04 09:33:57 +02:00
|
|
|
|
2019-05-14 05:17:56 +02:00
|
|
|
if (enum_pins->Version != enum_pins->base->pin_version)
|
|
|
|
{
|
|
|
|
enum_pins->count = 0;
|
2019-11-23 04:13:59 +01:00
|
|
|
while (enum_pins->base->ops->filter_get_pin(enum_pins->base, enum_pins->count))
|
2019-05-14 05:17:56 +02:00
|
|
|
++enum_pins->count;
|
|
|
|
}
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
enum_pins->Version = enum_pins->base->pin_version;
|
|
|
|
enum_pins->uIndex = 0;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins *iface, IEnumPins **out)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2019-05-14 05:17:54 +02:00
|
|
|
IEnumPinsImpl *enum_pins = impl_from_IEnumPins(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
TRACE("iface %p, out %p.\n", iface, out);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
if (FAILED(hr = enum_pins_create(enum_pins->base, out)))
|
2003-08-07 00:04:45 +02:00
|
|
|
return hr;
|
2019-05-14 05:17:54 +02:00
|
|
|
return IEnumPins_Skip(*out, enum_pins->uIndex);
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
|
|
|
|
{
|
|
|
|
IEnumPinsImpl_QueryInterface,
|
|
|
|
IEnumPinsImpl_AddRef,
|
|
|
|
IEnumPinsImpl_Release,
|
|
|
|
IEnumPinsImpl_Next,
|
|
|
|
IEnumPinsImpl_Skip,
|
|
|
|
IEnumPinsImpl_Reset,
|
|
|
|
IEnumPinsImpl_Clone
|
|
|
|
};
|