2 * Implementation of IEnumMediaTypes Interface
4 * Copyright 2003 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "quartz_private.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
27 HRESULT
CopyMediaType(AM_MEDIA_TYPE
* pDest
, const AM_MEDIA_TYPE
*pSrc
)
29 memcpy(pDest
, pSrc
, sizeof(AM_MEDIA_TYPE
));
30 if (!pSrc
->pbFormat
) return S_OK
;
31 if (!(pDest
->pbFormat
= CoTaskMemAlloc(pSrc
->cbFormat
)))
33 memcpy(pDest
->pbFormat
, pSrc
->pbFormat
, pSrc
->cbFormat
);
37 void FreeMediaType(AM_MEDIA_TYPE
* pMediaType
)
39 if (pMediaType
->pbFormat
)
41 CoTaskMemFree(pMediaType
->pbFormat
);
42 pMediaType
->pbFormat
= NULL
;
46 IUnknown_Release(pMediaType
->pUnk
);
47 pMediaType
->pUnk
= NULL
;
51 void DeleteMediaType(AM_MEDIA_TYPE
* pMediaType
)
53 FreeMediaType(pMediaType
);
54 CoTaskMemFree(pMediaType
);
58 BOOL
CompareMediaTypes(const AM_MEDIA_TYPE
* pmt1
, const AM_MEDIA_TYPE
* pmt2
, BOOL bWildcards
)
61 dump_AM_MEDIA_TYPE(pmt1
);
63 dump_AM_MEDIA_TYPE(pmt2
);
64 return (((bWildcards
&& (IsEqualGUID(&pmt1
->majortype
, &GUID_NULL
) || IsEqualGUID(&pmt2
->majortype
, &GUID_NULL
))) || IsEqualGUID(&pmt1
->majortype
, &pmt2
->majortype
)) &&
65 ((bWildcards
&& (IsEqualGUID(&pmt1
->subtype
, &GUID_NULL
) || IsEqualGUID(&pmt2
->subtype
, &GUID_NULL
))) || IsEqualGUID(&pmt1
->subtype
, &pmt2
->subtype
)));
68 void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE
* pmt
)
72 TRACE("\t%s\n\t%s\n\t...\n\t%s\n", qzdebugstr_guid(&pmt
->majortype
), qzdebugstr_guid(&pmt
->subtype
), qzdebugstr_guid(&pmt
->formattype
));
75 typedef struct IEnumMediaTypesImpl
77 const IEnumMediaTypesVtbl
* lpVtbl
;
79 ENUMMEDIADETAILS enumMediaDetails
;
81 } IEnumMediaTypesImpl
;
83 static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl
;
85 HRESULT
IEnumMediaTypesImpl_Construct(const ENUMMEDIADETAILS
* pDetails
, IEnumMediaTypes
** ppEnum
)
88 IEnumMediaTypesImpl
* pEnumMediaTypes
= CoTaskMemAlloc(sizeof(IEnumMediaTypesImpl
));
95 pEnumMediaTypes
->lpVtbl
= &IEnumMediaTypesImpl_Vtbl
;
96 pEnumMediaTypes
->refCount
= 1;
97 pEnumMediaTypes
->uIndex
= 0;
98 pEnumMediaTypes
->enumMediaDetails
.cMediaTypes
= pDetails
->cMediaTypes
;
99 pEnumMediaTypes
->enumMediaDetails
.pMediaTypes
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
) * pDetails
->cMediaTypes
);
100 for (i
= 0; i
< pDetails
->cMediaTypes
; i
++)
101 if (FAILED(CopyMediaType(&pEnumMediaTypes
->enumMediaDetails
.pMediaTypes
[i
], &pDetails
->pMediaTypes
[i
]))) {
103 CoTaskMemFree(pEnumMediaTypes
->enumMediaDetails
.pMediaTypes
[i
].pbFormat
);
104 CoTaskMemFree(pEnumMediaTypes
->enumMediaDetails
.pMediaTypes
);
105 return E_OUTOFMEMORY
;
107 *ppEnum
= (IEnumMediaTypes
*)(&pEnumMediaTypes
->lpVtbl
);
111 static HRESULT WINAPI
IEnumMediaTypesImpl_QueryInterface(IEnumMediaTypes
* iface
, REFIID riid
, LPVOID
* ppv
)
113 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
117 if (IsEqualIID(riid
, &IID_IUnknown
))
118 *ppv
= (LPVOID
)iface
;
119 else if (IsEqualIID(riid
, &IID_IEnumMediaTypes
))
120 *ppv
= (LPVOID
)iface
;
124 IUnknown_AddRef((IUnknown
*)(*ppv
));
128 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
130 return E_NOINTERFACE
;
133 static ULONG WINAPI
IEnumMediaTypesImpl_AddRef(IEnumMediaTypes
* iface
)
135 IEnumMediaTypesImpl
*This
= (IEnumMediaTypesImpl
*)iface
;
136 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
143 static ULONG WINAPI
IEnumMediaTypesImpl_Release(IEnumMediaTypes
* iface
)
145 IEnumMediaTypesImpl
*This
= (IEnumMediaTypesImpl
*)iface
;
146 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
153 for (i
= 0; i
< This
->enumMediaDetails
.cMediaTypes
; i
++)
154 if (This
->enumMediaDetails
.pMediaTypes
[i
].pbFormat
)
155 CoTaskMemFree(This
->enumMediaDetails
.pMediaTypes
[i
].pbFormat
);
156 CoTaskMemFree(This
->enumMediaDetails
.pMediaTypes
);
162 static HRESULT WINAPI
IEnumMediaTypesImpl_Next(IEnumMediaTypes
* iface
, ULONG cMediaTypes
, AM_MEDIA_TYPE
** ppMediaTypes
, ULONG
* pcFetched
)
165 IEnumMediaTypesImpl
*This
= (IEnumMediaTypesImpl
*)iface
;
167 cFetched
= min(This
->enumMediaDetails
.cMediaTypes
, This
->uIndex
+ cMediaTypes
) - This
->uIndex
;
169 TRACE("(%lu, %p, %p)\n", cMediaTypes
, ppMediaTypes
, pcFetched
);
170 TRACE("Next uIndex: %lu, cFetched: %lu\n", This
->uIndex
, cFetched
);
175 *ppMediaTypes
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
) * cFetched
);
176 for (i
= 0; i
< cFetched
; i
++)
177 if (FAILED(CopyMediaType(&(*ppMediaTypes
)[i
], &This
->enumMediaDetails
.pMediaTypes
[This
->uIndex
+ i
]))) {
179 CoTaskMemFree((*ppMediaTypes
)[i
].pbFormat
);
180 CoTaskMemFree(*ppMediaTypes
);
181 *ppMediaTypes
= NULL
;
182 return E_OUTOFMEMORY
;
186 if ((cMediaTypes
!= 1) || pcFetched
)
187 *pcFetched
= cFetched
;
189 This
->uIndex
+= cFetched
;
191 if (cFetched
!= cMediaTypes
)
196 static HRESULT WINAPI
IEnumMediaTypesImpl_Skip(IEnumMediaTypes
* iface
, ULONG cMediaTypes
)
198 IEnumMediaTypesImpl
*This
= (IEnumMediaTypesImpl
*)iface
;
200 TRACE("(%lu)\n", cMediaTypes
);
202 if (This
->uIndex
+ cMediaTypes
< This
->enumMediaDetails
.cMediaTypes
)
204 This
->uIndex
+= cMediaTypes
;
210 static HRESULT WINAPI
IEnumMediaTypesImpl_Reset(IEnumMediaTypes
* iface
)
212 IEnumMediaTypesImpl
*This
= (IEnumMediaTypesImpl
*)iface
;
220 static HRESULT WINAPI
IEnumMediaTypesImpl_Clone(IEnumMediaTypes
* iface
, IEnumMediaTypes
** ppEnum
)
223 IEnumMediaTypesImpl
*This
= (IEnumMediaTypesImpl
*)iface
;
225 TRACE("(%p)\n", ppEnum
);
227 hr
= IEnumMediaTypesImpl_Construct(&This
->enumMediaDetails
, ppEnum
);
230 return IEnumMediaTypes_Skip(*ppEnum
, This
->uIndex
);
233 static const IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl
=
235 IEnumMediaTypesImpl_QueryInterface
,
236 IEnumMediaTypesImpl_AddRef
,
237 IEnumMediaTypesImpl_Release
,
238 IEnumMediaTypesImpl_Next
,
239 IEnumMediaTypesImpl_Skip
,
240 IEnumMediaTypesImpl_Reset
,
241 IEnumMediaTypesImpl_Clone