2 * Implementation of IEnumPins Interface
4 * Copyright 2003 Robert Shearman
5 * Copyright 2010 Aric Stewart, CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/strmbase.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(strmbase
);
30 typedef struct IEnumPinsImpl
32 IEnumPins IEnumPins_iface
;
36 BaseFilter_GetPin receive_pin
;
37 BaseFilter_GetPinCount receive_pincount
;
38 BaseFilter_GetPinVersion receive_version
;
42 static inline IEnumPinsImpl
*impl_from_IEnumPins(IEnumPins
*iface
)
44 return CONTAINING_RECORD(iface
, IEnumPinsImpl
, IEnumPins_iface
);
47 static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl
;
49 HRESULT WINAPI
EnumPins_Construct(BaseFilter
*base
, BaseFilter_GetPin receive_pin
, BaseFilter_GetPinCount receive_pincount
, BaseFilter_GetPinVersion receive_version
, IEnumPins
** ppEnum
)
51 IEnumPinsImpl
* pEnumPins
;
56 pEnumPins
= CoTaskMemAlloc(sizeof(IEnumPinsImpl
));
62 pEnumPins
->IEnumPins_iface
.lpVtbl
= &IEnumPinsImpl_Vtbl
;
63 pEnumPins
->refCount
= 1;
64 pEnumPins
->uIndex
= 0;
65 pEnumPins
->receive_pin
= receive_pin
;
66 pEnumPins
->receive_pincount
= receive_pincount
;
67 pEnumPins
->receive_version
= receive_version
;
68 pEnumPins
->base
= base
;
69 IBaseFilter_AddRef(&base
->IBaseFilter_iface
);
70 *ppEnum
= &pEnumPins
->IEnumPins_iface
;
71 pEnumPins
->Version
= receive_version(base
);
73 TRACE("Created new enumerator (%p)\n", *ppEnum
);
77 static HRESULT WINAPI
IEnumPinsImpl_QueryInterface(IEnumPins
* iface
, REFIID riid
, LPVOID
* ppv
)
79 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
83 if (IsEqualIID(riid
, &IID_IUnknown
))
85 else if (IsEqualIID(riid
, &IID_IEnumPins
))
90 IUnknown_AddRef((IUnknown
*)(*ppv
));
94 FIXME("No interface for %s!\n", debugstr_guid(riid
));
99 static ULONG WINAPI
IEnumPinsImpl_AddRef(IEnumPins
* iface
)
101 IEnumPinsImpl
*This
= impl_from_IEnumPins(iface
);
102 ULONG ref
= InterlockedIncrement(&This
->refCount
);
104 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
109 static ULONG WINAPI
IEnumPinsImpl_Release(IEnumPins
* iface
)
111 IEnumPinsImpl
*This
= impl_from_IEnumPins(iface
);
112 ULONG ref
= InterlockedDecrement(&This
->refCount
);
114 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
118 IBaseFilter_Release(&This
->base
->IBaseFilter_iface
);
125 static HRESULT WINAPI
IEnumPinsImpl_Next(IEnumPins
* iface
, ULONG cPins
, IPin
** ppPins
, ULONG
* pcFetched
)
127 IEnumPinsImpl
*This
= impl_from_IEnumPins(iface
);
130 TRACE("(%p)->(%u, %p, %p)\n", iface
, cPins
, ppPins
, pcFetched
);
135 if (cPins
> 1 && !pcFetched
)
141 if (This
->Version
!= This
->receive_version(This
->base
))
142 return VFW_E_ENUM_OUT_OF_SYNC
;
147 pin
= This
->receive_pin(This
->base
, This
->uIndex
+ i
);
165 static HRESULT WINAPI
IEnumPinsImpl_Skip(IEnumPins
* iface
, ULONG cPins
)
167 IEnumPinsImpl
*This
= impl_from_IEnumPins(iface
);
169 TRACE("(%p)->(%u)\n", iface
, cPins
);
171 if (This
->Version
!= This
->receive_version(This
->base
))
172 return VFW_E_ENUM_OUT_OF_SYNC
;
174 if (This
->receive_pincount(This
->base
) >= This
->uIndex
+ cPins
)
177 This
->uIndex
+= cPins
;
181 static HRESULT WINAPI
IEnumPinsImpl_Reset(IEnumPins
* iface
)
183 IEnumPinsImpl
*This
= impl_from_IEnumPins(iface
);
185 TRACE("(%p)->()\n", iface
);
187 This
->Version
= This
->receive_version(This
->base
);
193 static HRESULT WINAPI
IEnumPinsImpl_Clone(IEnumPins
* iface
, IEnumPins
** ppEnum
)
196 IEnumPinsImpl
*This
= impl_from_IEnumPins(iface
);
198 TRACE("(%p)->(%p)\n", iface
, ppEnum
);
200 hr
= EnumPins_Construct(This
->base
, This
->receive_pin
, This
->receive_pincount
, This
->receive_version
, ppEnum
);
203 return IEnumPins_Skip(*ppEnum
, This
->uIndex
);
206 static const IEnumPinsVtbl IEnumPinsImpl_Vtbl
=
208 IEnumPinsImpl_QueryInterface
,
209 IEnumPinsImpl_AddRef
,
210 IEnumPinsImpl_Release
,