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 (!(pDest->pbFormat = CoTaskMemAlloc(pSrc->cbFormat)))
32 memcpy(pDest->pbFormat, pSrc->pbFormat, pSrc->cbFormat);
36 void DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
38 if (pMediaType->pbFormat)
40 CoTaskMemFree(pMediaType->pbFormat);
41 pMediaType->pbFormat = NULL;
45 IUnknown_Release(pMediaType->pUnk);
46 pMediaType->pUnk = NULL;
50 BOOL CompareMediaTypes(const AM_MEDIA_TYPE * pmt1, const AM_MEDIA_TYPE * pmt2, BOOL bWildcards)
53 dump_AM_MEDIA_TYPE(pmt1);
55 dump_AM_MEDIA_TYPE(pmt2);
56 return (((bWildcards && (IsEqualGUID(&pmt1->majortype, &GUID_NULL) || IsEqualGUID(&pmt2->majortype, &GUID_NULL))) || IsEqualGUID(&pmt1->majortype, &pmt2->majortype)) &&
57 ((bWildcards && (IsEqualGUID(&pmt1->subtype, &GUID_NULL) || IsEqualGUID(&pmt2->subtype, &GUID_NULL))) || IsEqualGUID(&pmt1->subtype, &pmt2->subtype)));
60 void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
64 TRACE("\t%s\n\t%s\n\t...\n\t%s\n", qzdebugstr_guid(&pmt->majortype), qzdebugstr_guid(&pmt->subtype), qzdebugstr_guid(&pmt->formattype));
67 typedef struct IEnumMediaTypesImpl
69 const IEnumMediaTypesVtbl * lpVtbl;
71 ENUMMEDIADETAILS enumMediaDetails;
73 } IEnumMediaTypesImpl;
75 static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl;
77 HRESULT IEnumMediaTypesImpl_Construct(const ENUMMEDIADETAILS * pDetails, IEnumMediaTypes ** ppEnum)
80 IEnumMediaTypesImpl * pEnumMediaTypes = CoTaskMemAlloc(sizeof(IEnumMediaTypesImpl));
87 pEnumMediaTypes->lpVtbl = &IEnumMediaTypesImpl_Vtbl;
88 pEnumMediaTypes->refCount = 1;
89 pEnumMediaTypes->uIndex = 0;
90 pEnumMediaTypes->enumMediaDetails.cMediaTypes = pDetails->cMediaTypes;
91 pEnumMediaTypes->enumMediaDetails.pMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * pDetails->cMediaTypes);
92 for (i = 0; i < pDetails->cMediaTypes; i++)
93 pEnumMediaTypes->enumMediaDetails.pMediaTypes[i] = pDetails->pMediaTypes[i];
94 *ppEnum = (IEnumMediaTypes *)(&pEnumMediaTypes->lpVtbl);
98 static HRESULT WINAPI IEnumMediaTypesImpl_QueryInterface(IEnumMediaTypes * iface, REFIID riid, LPVOID * ppv)
100 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
104 if (IsEqualIID(riid, &IID_IUnknown))
105 *ppv = (LPVOID)iface;
106 else if (IsEqualIID(riid, &IID_IEnumMediaTypes))
107 *ppv = (LPVOID)iface;
111 IUnknown_AddRef((IUnknown *)(*ppv));
115 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
117 return E_NOINTERFACE;
120 static ULONG WINAPI IEnumMediaTypesImpl_AddRef(IEnumMediaTypes * iface)
122 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
123 ULONG refCount = InterlockedIncrement(&This->refCount);
130 static ULONG WINAPI IEnumMediaTypesImpl_Release(IEnumMediaTypes * iface)
132 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
133 ULONG refCount = InterlockedDecrement(&This->refCount);
139 CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
147 static HRESULT WINAPI IEnumMediaTypesImpl_Next(IEnumMediaTypes * iface, ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes, ULONG * pcFetched)
150 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
152 cFetched = min(This->enumMediaDetails.cMediaTypes, This->uIndex + cMediaTypes) - This->uIndex;
154 TRACE("(%lu, %p, %p)\n", cMediaTypes, ppMediaTypes, pcFetched);
155 TRACE("Next uIndex: %lu, cFetched: %lu\n", This->uIndex, cFetched);
160 *ppMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * cFetched);
161 for (i = 0; i < cFetched; i++)
162 (*ppMediaTypes)[i] = This->enumMediaDetails.pMediaTypes[This->uIndex + i];
165 if ((cMediaTypes != 1) || pcFetched)
166 *pcFetched = cFetched;
168 This->uIndex += cFetched;
170 if (cFetched != cMediaTypes)
175 static HRESULT WINAPI IEnumMediaTypesImpl_Skip(IEnumMediaTypes * iface, ULONG cMediaTypes)
177 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
179 TRACE("(%lu)\n", cMediaTypes);
181 if (This->uIndex + cMediaTypes < This->enumMediaDetails.cMediaTypes)
183 This->uIndex += cMediaTypes;
189 static HRESULT WINAPI IEnumMediaTypesImpl_Reset(IEnumMediaTypes * iface)
191 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
199 static HRESULT WINAPI IEnumMediaTypesImpl_Clone(IEnumMediaTypes * iface, IEnumMediaTypes ** ppEnum)
202 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
204 TRACE("(%p)\n", ppEnum);
206 hr = IEnumMediaTypesImpl_Construct(&This->enumMediaDetails, ppEnum);
209 return IEnumMediaTypes_Skip(*ppEnum, This->uIndex);
212 static const IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl =
214 IEnumMediaTypesImpl_QueryInterface,
215 IEnumMediaTypesImpl_AddRef,
216 IEnumMediaTypesImpl_Release,
217 IEnumMediaTypesImpl_Next,
218 IEnumMediaTypesImpl_Skip,
219 IEnumMediaTypesImpl_Reset,
220 IEnumMediaTypesImpl_Clone