server: Initial support for Wow64 registry redirection.
[wine/multimedia.git] / dlls / qcap / enummedia.c
bloba4d84b059e0be86e0d58136b51350a149179f46f
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wtypes.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "dshow.h"
32 #include "qcap_main.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
38 HRESULT CopyMediaType(AM_MEDIA_TYPE * pDest, const AM_MEDIA_TYPE *pSrc)
40 *pDest = *pSrc;
41 if (!pSrc->pbFormat) return S_OK;
42 if (!(pDest->pbFormat = CoTaskMemAlloc(pSrc->cbFormat)))
43 return E_OUTOFMEMORY;
44 memcpy(pDest->pbFormat, pSrc->pbFormat, pSrc->cbFormat);
45 return S_OK;
48 static void FreeMediaType(AM_MEDIA_TYPE * pMediaType)
50 CoTaskMemFree(pMediaType->pbFormat);
51 pMediaType->pbFormat = NULL;
53 if (pMediaType->pUnk)
55 IUnknown_Release(pMediaType->pUnk);
56 pMediaType->pUnk = NULL;
60 void DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
62 FreeMediaType(pMediaType);
63 CoTaskMemFree(pMediaType);
66 BOOL CompareMediaTypes(const AM_MEDIA_TYPE * pmt1, const AM_MEDIA_TYPE * pmt2,
67 BOOL bWildcards)
69 TRACE("pmt1: ");
70 dump_AM_MEDIA_TYPE(pmt1);
71 TRACE("pmt2: ");
72 dump_AM_MEDIA_TYPE(pmt2);
73 return (((bWildcards && (IsEqualGUID(&pmt1->majortype, &GUID_NULL) ||
74 IsEqualGUID(&pmt2->majortype, &GUID_NULL))) ||
75 IsEqualGUID(&pmt1->majortype, &pmt2->majortype)) &&
76 ((bWildcards && (IsEqualGUID(&pmt1->subtype, &GUID_NULL) ||
77 IsEqualGUID(&pmt2->subtype, &GUID_NULL))) ||
78 IsEqualGUID(&pmt1->subtype, &pmt2->subtype)));
81 void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
83 if (!pmt)
84 return;
85 TRACE("\t%s\n\t%s\n\t...\n\t%s\n", debugstr_guid(&pmt->majortype),
86 debugstr_guid(&pmt->subtype), debugstr_guid(&pmt->formattype));
89 typedef struct IEnumMediaTypesImpl
91 const IEnumMediaTypesVtbl * lpVtbl;
92 LONG refCount;
93 ENUMMEDIADETAILS enumMediaDetails;
94 ULONG uIndex;
95 } IEnumMediaTypesImpl;
97 static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl;
99 HRESULT IEnumMediaTypesImpl_Construct(const ENUMMEDIADETAILS * pDetails,
100 IEnumMediaTypes ** ppEnum)
102 ULONG i;
103 IEnumMediaTypesImpl * pEnumMediaTypes = CoTaskMemAlloc(sizeof(IEnumMediaTypesImpl));
105 if (!pEnumMediaTypes)
107 *ppEnum = NULL;
108 return E_OUTOFMEMORY;
110 ObjectRefCount(TRUE);
111 pEnumMediaTypes->lpVtbl = &IEnumMediaTypesImpl_Vtbl;
112 pEnumMediaTypes->refCount = 1;
113 pEnumMediaTypes->uIndex = 0;
114 pEnumMediaTypes->enumMediaDetails.cMediaTypes = pDetails->cMediaTypes;
115 pEnumMediaTypes->enumMediaDetails.pMediaTypes =
116 CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * pDetails->cMediaTypes);
117 for (i = 0; i < pDetails->cMediaTypes; i++)
118 if (FAILED(CopyMediaType(&pEnumMediaTypes->enumMediaDetails.pMediaTypes[i], &pDetails->pMediaTypes[i]))) {
119 while (i--) CoTaskMemFree(pEnumMediaTypes->enumMediaDetails.pMediaTypes[i].pbFormat);
120 CoTaskMemFree(pEnumMediaTypes->enumMediaDetails.pMediaTypes);
121 return E_OUTOFMEMORY;
123 *ppEnum = (IEnumMediaTypes *)(&pEnumMediaTypes->lpVtbl);
124 return S_OK;
127 static HRESULT WINAPI IEnumMediaTypesImpl_QueryInterface(IEnumMediaTypes * iface,
128 REFIID riid,
129 LPVOID * ppv)
131 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
133 *ppv = NULL;
135 if (IsEqualIID(riid, &IID_IUnknown))
136 *ppv = iface;
137 else if (IsEqualIID(riid, &IID_IEnumMediaTypes))
138 *ppv = iface;
140 if (*ppv)
142 IUnknown_AddRef((IUnknown *)(*ppv));
143 return S_OK;
146 FIXME("No interface for %s!\n", debugstr_guid(riid));
148 return E_NOINTERFACE;
151 static ULONG WINAPI IEnumMediaTypesImpl_AddRef(IEnumMediaTypes * iface)
153 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
154 ULONG refCount = InterlockedIncrement(&This->refCount);
156 TRACE("()\n");
158 return refCount;
161 static ULONG WINAPI IEnumMediaTypesImpl_Release(IEnumMediaTypes * iface)
163 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
164 ULONG refCount = InterlockedDecrement(&This->refCount);
166 TRACE("()\n");
168 if (!refCount)
170 ULONG i;
171 for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
172 if (This->enumMediaDetails.pMediaTypes[i].pbFormat)
173 CoTaskMemFree(This->enumMediaDetails.pMediaTypes[i].pbFormat);
174 CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
175 CoTaskMemFree(This);
176 ObjectRefCount(FALSE);
178 return refCount;
181 static HRESULT WINAPI IEnumMediaTypesImpl_Next(IEnumMediaTypes * iface,
182 ULONG cMediaTypes,
183 AM_MEDIA_TYPE ** ppMediaTypes,
184 ULONG * pcFetched)
186 ULONG cFetched;
187 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
189 cFetched = min(This->enumMediaDetails.cMediaTypes,
190 This->uIndex + cMediaTypes) - This->uIndex;
192 TRACE("(%u, %p, %p)\n", cMediaTypes, ppMediaTypes, pcFetched);
193 TRACE("Next uIndex: %u, cFetched: %u\n", This->uIndex, cFetched);
195 if (cFetched > 0)
197 ULONG i;
198 *ppMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * cFetched);
199 for (i = 0; i < cFetched; i++)
200 if (FAILED(CopyMediaType(&(*ppMediaTypes)[i], &This->enumMediaDetails.pMediaTypes[This->uIndex + i]))) {
201 while (i--)
202 CoTaskMemFree((*ppMediaTypes)[i].pbFormat);
203 CoTaskMemFree(*ppMediaTypes);
204 *ppMediaTypes = NULL;
205 return E_OUTOFMEMORY;
209 if ((cMediaTypes != 1) || pcFetched)
210 *pcFetched = cFetched;
212 This->uIndex += cFetched;
214 if (cFetched != cMediaTypes)
215 return S_FALSE;
216 return S_OK;
219 static HRESULT WINAPI IEnumMediaTypesImpl_Skip(IEnumMediaTypes * iface,
220 ULONG cMediaTypes)
222 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
224 TRACE("(%u)\n", cMediaTypes);
226 if (This->uIndex + cMediaTypes < This->enumMediaDetails.cMediaTypes)
228 This->uIndex += cMediaTypes;
229 return S_OK;
231 return S_FALSE;
234 static HRESULT WINAPI IEnumMediaTypesImpl_Reset(IEnumMediaTypes * iface)
236 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
238 TRACE("()\n");
240 This->uIndex = 0;
241 return S_OK;
244 static HRESULT WINAPI IEnumMediaTypesImpl_Clone(IEnumMediaTypes * iface,
245 IEnumMediaTypes ** ppEnum)
247 HRESULT hr;
248 IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
250 TRACE("(%p)\n", ppEnum);
252 hr = IEnumMediaTypesImpl_Construct(&This->enumMediaDetails, ppEnum);
253 if (FAILED(hr))
254 return hr;
255 return IEnumMediaTypes_Skip(*ppEnum, This->uIndex);
258 static const IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl =
260 IEnumMediaTypesImpl_QueryInterface,
261 IEnumMediaTypesImpl_AddRef,
262 IEnumMediaTypesImpl_Release,
263 IEnumMediaTypesImpl_Next,
264 IEnumMediaTypesImpl_Skip,
265 IEnumMediaTypesImpl_Reset,
266 IEnumMediaTypesImpl_Clone