2 * IFilterMapper & IFilterMapper2 Implementations
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 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
31 #include "quartz_private.h"
33 #define COM_NO_WINDOWS_H
37 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
44 typedef struct FilterMapper2Impl
46 ICOM_VFIELD(IFilterMapper2);
47 ICOM_VTABLE(IFilterMapper) * lpVtblFilterMapper;
51 static struct ICOM_VTABLE(IFilterMapper2) fm2vtbl;
52 static struct ICOM_VTABLE(IFilterMapper) fmvtbl;
54 #define _IFilterMapper_Offset ((int)(&(((FilterMapper2Impl*)0)->lpVtblFilterMapper)))
55 #define ICOM_THIS_From_IFilterMapper(impl, iface) impl* This = (impl*)(((char*)iface)-_IFilterMapper_Offset)
57 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
58 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
60 /* CLSID property in media category Moniker */
61 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
62 /* FriendlyName property in media category Moniker */
63 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
64 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
65 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
66 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
67 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
69 /* registry format for REGFILTER2 */
80 BYTE signature[4]; /* e.g. "0pi3" */
85 DWORD bCategory; /* is there a category clsid? */
86 /* optional: dwOffsetCategoryClsid */
91 BYTE signature[4]; /* e.g. "0ty3" */
106 int capacity; /* in bytes */
107 int current; /* pointer to next free byte */
110 /* returns the position it was added at */
111 static int add_data(struct Vector * v, const BYTE * pData, int size)
113 int index = v->current;
114 if (v->current + size > v->capacity)
116 LPBYTE pOldData = v->pData;
117 v->capacity = (v->capacity + size) * 2;
118 v->pData = CoTaskMemAlloc(v->capacity);
119 memcpy(v->pData, pOldData, v->current);
120 CoTaskMemFree(pOldData);
122 memcpy(v->pData + v->current, pData, size);
127 static int find_data(struct Vector * v, const BYTE * pData, int size)
130 for (index = 0; index < v->current; index++)
131 if (!memcmp(v->pData + index, pData, size))
137 static void delete_vector(struct Vector * v)
140 CoTaskMemFree(v->pData);
145 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
147 FilterMapper2Impl * pFM2impl;
149 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
152 return CLASS_E_NOAGGREGATION;
154 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
156 return E_OUTOFMEMORY;
158 pFM2impl->lpVtbl = &fm2vtbl;
159 pFM2impl->lpVtblFilterMapper = &fmvtbl;
160 pFM2impl->refCount = 1;
164 TRACE("-- created at %p\n", pFM2impl);
169 /*** IUnknown methods ***/
171 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
173 ICOM_THIS(FilterMapper2Impl, iface);
175 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
179 if (IsEqualIID(riid, &IID_IUnknown))
181 else if (IsEqualIID(riid, &IID_IFilterMapper2))
183 else if (IsEqualIID(riid, &IID_IFilterMapper))
184 *ppv = &This->lpVtblFilterMapper;
188 IUnknown_AddRef((IUnknown *)*ppv);
192 FIXME("No interface for %s\n", debugstr_guid(riid));
193 return E_NOINTERFACE;
196 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
198 ICOM_THIS(FilterMapper2Impl, iface);
202 return InterlockedIncrement(&This->refCount);
205 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
207 ICOM_THIS(FilterMapper2Impl, iface);
211 if (InterlockedDecrement(&This->refCount) == 0)
216 return This->refCount;
219 /*** IFilterMapper2 methods ***/
221 static HRESULT WINAPI FilterMapper2_CreateCategory(
222 IFilterMapper2 * iface,
223 REFCLSID clsidCategory,
224 DWORD dwCategoryMerit,
225 LPCWSTR szDescription)
227 LPWSTR wClsidAMCat = NULL;
228 LPWSTR wClsidCategory = NULL;
229 WCHAR wszKeyName[strlenW(wszClsidSlash) + strlenW(wszSlashInstance) + (CHARS_IN_GUID-1) * 2 + 1];
233 TRACE("(%s, %lx, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
235 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
239 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
244 strcpyW(wszKeyName, wszClsidSlash);
245 strcatW(wszKeyName, wClsidAMCat);
246 strcatW(wszKeyName, wszSlashInstance);
247 strcatW(wszKeyName, wClsidCategory);
249 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
254 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (LPBYTE)szDescription, strlenW(szDescription) + 1));
259 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, strlenW(wClsidCategory) + 1));
264 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit)));
270 CoTaskMemFree(wClsidCategory);
272 CoTaskMemFree(wClsidAMCat);
277 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
278 IFilterMapper2 * iface,
279 const CLSID *pclsidCategory,
280 const OLECHAR *szInstance,
283 WCHAR wszKeyName[MAX_PATH];
284 LPWSTR wClsidCategory = NULL;
285 LPWSTR wFilter = NULL;
288 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
291 pclsidCategory = &CLSID_LegacyAmFilterCategory;
293 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
297 strcpyW(wszKeyName, wszClsidSlash);
298 strcatW(wszKeyName, wClsidCategory);
299 strcatW(wszKeyName, wszSlashInstance);
301 strcatW(wszKeyName, szInstance);
304 hr = StringFromCLSID(Filter, &wFilter);
306 strcatW(wszKeyName, wFilter);
312 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName));
316 CoTaskMemFree(wClsidCategory);
318 CoTaskMemFree(wFilter);
323 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
327 V_VT(&var) = VT_BSTR;
328 V_UNION(&var, bstrVal) = (BSTR)szName;
330 return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
333 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
335 LPWSTR wszClsid = NULL;
339 hr = StringFromCLSID(clsid, &wszClsid);
343 V_VT(&var) = VT_BSTR;
344 V_UNION(&var, bstrVal) = wszClsid;
345 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
348 CoTaskMemFree(wszClsid);
352 static HRESULT FM2_WriteFilterData(IPropertyBag * pPropBag, const REGFILTER2 * prf2)
355 int size = sizeof(struct REG_RF);
357 struct Vector mainStore = {NULL, 0, 0};
358 struct Vector clsidStore = {NULL, 0, 0};
361 SAFEARRAYBOUND saBound;
364 rrf.dwVersion = prf2->dwVersion;
365 rrf.dwMerit = prf2->dwMerit;
366 rrf.dwPins = prf2->u.s1.cPins2;
369 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
371 for (i = 0; i < prf2->u.s1.cPins2; i++)
373 size += sizeof(struct REG_RFP);
374 if (prf2->u.s1.rgPins2[i].clsPinCategory)
375 size += sizeof(DWORD);
376 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
377 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
380 for (i = 0; i < prf2->u.s1.cPins2; i++)
383 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
386 rrfp.signature[0] = '0';
387 rrfp.signature[1] = 'p';
388 rrfp.signature[2] = 'i';
389 rrfp.signature[3] = '3';
390 rrfp.signature[0] += i;
391 rrfp.dwFlags = rgPin2.dwFlags;
392 rrfp.dwInstances = rgPin2.cInstances;
393 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
394 rrfp.dwMediums = rgPin2.nMediums;
395 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
397 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
400 DWORD index = find_data(&clsidStore, (LPBYTE)rgPin2.clsPinCategory, sizeof(CLSID));
402 index = add_data(&clsidStore, (LPBYTE)rgPin2.clsPinCategory, sizeof(CLSID));
405 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
408 for (j = 0; j < rgPin2.nMediaTypes; j++)
411 rt.signature[0] = '0';
412 rt.signature[1] = 't';
413 rt.signature[2] = 'y';
414 rt.signature[3] = '3';
415 rt.signature[0] += j;
418 rt.dwOffsetMajor = find_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
419 if (rt.dwOffsetMajor == -1)
420 rt.dwOffsetMajor = add_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
421 rt.dwOffsetMajor += size;
422 rt.dwOffsetMinor = find_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
423 if (rt.dwOffsetMinor == -1)
424 rt.dwOffsetMinor = add_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
425 rt.dwOffsetMinor += size;
427 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
430 for (j = 0; j < rgPin2.nMediums; j++)
432 DWORD index = find_data(&clsidStore, (LPBYTE)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
434 index = add_data(&clsidStore, (LPBYTE)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
437 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
442 saBound.cElements = mainStore.current + clsidStore.current;
443 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
446 ERR("Couldn't create SAFEARRAY\n");
453 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
456 memcpy(pbSAData, mainStore.pData, mainStore.current);
457 memcpy(pbSAData + mainStore.current, clsidStore.pData, clsidStore.current);
458 hr = SafeArrayUnaccessData(psa);
462 V_VT(&var) = VT_ARRAY | VT_UI1;
463 V_UNION(&var, parray) = psa;
466 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
469 SafeArrayDestroy(psa);
471 delete_vector(&mainStore);
472 delete_vector(&clsidStore);
476 static HRESULT FM2_ReadFilterData(IPropertyBag * pPropBag, REGFILTER2 * prf2)
481 struct REG_RF * prrf;
484 REGFILTERPINS2 * rgPins2;
487 V_VT(&var) = VT_ARRAY | VT_UI1;
489 hr = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
492 hr = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
496 prrf = (struct REG_RF *)pData;
499 if (prrf->dwVersion != 2)
501 FIXME("Filter registry version %ld not supported\n", prrf->dwVersion);
502 ZeroMemory(prf2, sizeof(*prf2));
509 TRACE("version = %ld, merit = %lx, #pins = %ld, unused = %lx\n",
510 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
512 prf2->dwVersion = prrf->dwVersion;
513 prf2->dwMerit = prrf->dwMerit;
514 prf2->u.s1.cPins2 = prrf->dwPins;
515 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
516 prf2->u.s1.rgPins2 = rgPins2;
517 pCurrent += sizeof(struct REG_RF);
519 for (i = 0; i < prrf->dwPins; i++)
521 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
522 REGPINTYPES * lpMediaType;
523 REGPINMEDIUM * lpMedium;
526 /* FIXME: check signature */
528 TRACE("\tsignature = %s\n", debugstr_an(prrfp->signature, 4));
530 TRACE("\tpin[%ld]: flags = %lx, instances = %ld, media types = %ld, mediums = %ld\n",
531 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
533 rgPins2[i].dwFlags = prrfp->dwFlags;
534 rgPins2[i].cInstances = prrfp->dwInstances;
535 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
536 rgPins2[i].nMediums = prrfp->dwMediums;
537 pCurrent += sizeof(struct REG_RFP);
538 if (prrfp->bCategory)
540 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
541 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
542 pCurrent += sizeof(DWORD);
543 rgPins2[i].clsPinCategory = clsCat;
546 rgPins2[i].clsPinCategory = NULL;
548 if (rgPins2[i].nMediaTypes > 0)
549 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
553 rgPins2[i].lpMediaType = lpMediaType;
555 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
557 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
558 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
559 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
561 /* FIXME: check signature */
562 TRACE("\t\tsignature = %s\n", debugstr_an(prt->signature, 4));
564 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
565 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
567 lpMediaType[j].clsMajorType = clsMajor;
568 lpMediaType[j].clsMinorType = clsMinor;
570 pCurrent += sizeof(*prt);
573 if (rgPins2[i].nMediums > 0)
574 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
578 rgPins2[i].lpMedium = lpMedium;
580 for (j = 0; j < rgPins2[i].nMediums; j++)
582 DWORD dwOffset = *(DWORD *)pCurrent;
584 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
586 pCurrent += sizeof(dwOffset);
593 SafeArrayUnaccessData(V_UNION(&var, parray));
600 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
603 for (i = 0; i < prf2->u.s1.cPins2; i++)
606 if (prf2->u.s1.rgPins2[i].clsPinCategory)
607 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
609 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
611 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
612 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
614 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
618 static HRESULT WINAPI FilterMapper2_RegisterFilter(
619 IFilterMapper2 * iface,
620 REFCLSID clsidFilter,
622 IMoniker **ppMoniker,
623 const CLSID *pclsidCategory,
624 const OLECHAR *szInstance,
625 const REGFILTER2 *prf2)
627 IParseDisplayName * pParser = NULL;
628 IBindCtx * pBindCtx = NULL;
629 IMoniker * pMoniker = NULL;
630 IPropertyBag * pPropBag = NULL;
632 LPWSTR pwszParseName = NULL;
634 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
637 LPWSTR szClsidTemp = NULL;
639 TRACE("(%s, %s, %p, %s, %s, %p)\n",
640 debugstr_guid(clsidFilter),
643 debugstr_guid(pclsidCategory),
644 debugstr_w(szInstance),
648 FIXME("ppMoniker != NULL not supported at the moment\n");
650 if (prf2->dwVersion != 2)
652 FIXME("dwVersion != 2 not supported at the moment\n");
657 pclsidCategory = &CLSID_ActiveMovieCategories;
659 /* sizeof... will include null terminator and
660 * the + 1 is for the separator ('\\'). The -1 is
661 * because CHARS_IN_GUID includes the null terminator
663 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
666 nameLen += strlenW(szInstance);
668 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
670 pwszParseName = CoTaskMemAlloc(nameLen);
671 pCurrent = pwszParseName;
673 return E_OUTOFMEMORY;
675 strcpyW(pwszParseName, wszDevice);
676 pCurrent += strlenW(wszDevice);
678 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
679 strcpyW(pCurrent, szClsidTemp);
680 pCurrent += CHARS_IN_GUID - 1;
686 strcpyW(pCurrent+1, szInstance);
691 CoTaskMemFree(szClsidTemp);
694 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
695 strcpyW(pCurrent+1, szClsidTemp);
700 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
703 hr = CreateBindCtx(0, &pBindCtx);
707 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
711 IBindCtx_Release(pBindCtx); pBindCtx = NULL;
714 IParseDisplayName_Release(pParser); pParser = NULL;
717 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
720 hr = FM2_WriteFriendlyName(pPropBag, szName);
723 hr = FM2_WriteClsid(pPropBag, clsidFilter);
726 hr = FM2_WriteFilterData(pPropBag, prf2);
729 IMoniker_Release(pMoniker); pMoniker = NULL;
732 IPropertyBag_Release(pPropBag); pPropBag = NULL;
735 CoTaskMemFree(szClsidTemp);
737 TRACE("-- returning %lx\n", hr);
742 /* internal helper function */
743 static BOOL MatchTypes(
746 const REGPINTYPES * pPinTypes,
748 const GUID * pMatchTypes)
753 if ((nMatchTypes == 0) && (nPinTypes > 0))
756 for (j = 0; j < nPinTypes; j++)
759 for (i = 0; i < nMatchTypes*2; i+=2)
761 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
762 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
772 /* internal helper function for qsort of MONIKER_MERIT array */
773 static int mm_compare(const void * left, const void * right)
775 const struct MONIKER_MERIT * mmLeft = (struct MONIKER_MERIT *)left;
776 const struct MONIKER_MERIT * mmRight = (struct MONIKER_MERIT *)right;
778 if (mmLeft->dwMerit == mmRight->dwMerit)
780 if (mmLeft->dwMerit > mmRight->dwMerit)
786 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
787 * (GUID_NULL's in input to function automatically treated as wild cards)
788 * Input/Output needed means match only on criteria if TRUE (with zero input types
789 * meaning match any input/output pin as long as one exists), otherwise match any
790 * filter that meets the rest of the requirements.
792 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
793 IFilterMapper2 * iface,
794 IEnumMoniker **ppEnum,
800 const GUID *pInputTypes,
801 const REGPINMEDIUM *pMedIn,
802 const CLSID *pPinCategoryIn,
806 const GUID *pOutputTypes,
807 const REGPINMEDIUM *pMedOut,
808 const CLSID *pPinCategoryOut)
810 ICreateDevEnum * pCreateDevEnum;
811 IMoniker * pMonikerCat;
812 IEnumMoniker * pEnumCat;
814 struct Vector monikers = {NULL, 0, 0};
816 TRACE("(%p, %lx, %s, %lx, %s, %ld, %p, %p, %p, %s, %s, %p, %p, %p)\n",
819 bExactMatch ? "true" : "false",
821 bInputNeeded ? "true" : "false",
826 bRender ? "true" : "false",
827 bOutputNeeded ? "true" : "false",
834 FIXME("dwFlags = %lx not implemented\n", dwFlags);
839 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
842 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
844 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
846 IPropertyBag * pPropBagCat = NULL;
848 HRESULT hrSub; /* this is so that one buggy filter
849 doesn't make the whole lot fail */
853 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
855 if (SUCCEEDED(hrSub))
856 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
858 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
861 IEnumMoniker * pEnum;
866 if (TRACE_ON(quartz))
869 V_VT(&temp) = VT_EMPTY;
870 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
871 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
875 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
877 if (SUCCEEDED(hrSub))
878 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
880 if (SUCCEEDED(hrSub))
881 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
883 if (SUCCEEDED(hrSub))
885 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
887 IPropertyBag * pPropBag = NULL;
890 BOOL bInputMatch = !bInputNeeded;
891 BOOL bOutputMatch = !bOutputNeeded;
893 ZeroMemory(&rf2, sizeof(rf2));
895 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
897 if (SUCCEEDED(hrSub))
898 hrSub = FM2_ReadFilterData(pPropBag, &rf2);
900 /* Logic used for bInputMatch expression:
901 * There exists some pin such that bInputNeeded implies (pin is an input and
902 * (bRender implies pin has render flag) and major/minor types members of
904 * bOutputMatch is similar, but without the "bRender implies ..." part
905 * and substituting variables names containing input for output
908 /* determine whether filter meets requirements */
909 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
911 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
913 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
915 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
916 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
917 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
918 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
919 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
922 if (bInputMatch && bOutputMatch)
924 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
925 IMoniker_AddRef(pMoniker);
926 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
930 FM2_DeleteRegFilter(&rf2);
932 IPropertyBag_Release(pPropBag);
933 IMoniker_Release(pMoniker);
935 IEnumMoniker_Release(pEnum);
941 IPropertyBag_Release(pPropBagCat);
942 IMoniker_Release(pMonikerCat);
948 IMoniker ** ppMoniker;
950 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
952 /* sort the monikers in descending merit order */
953 qsort(monikers.pData, nMonikerCount,
954 sizeof(struct MONIKER_MERIT),
957 /* construct an IEnumMoniker interface */
958 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
959 for (i = 0; i < nMonikerCount; i++)
961 /* no need to AddRef here as already AddRef'd above */
962 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
964 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
965 CoTaskMemFree(ppMoniker);
968 delete_vector(&monikers);
969 IEnumMoniker_Release(pEnumCat);
970 ICreateDevEnum_Release(pCreateDevEnum);
975 static ICOM_VTABLE(IFilterMapper2) fm2vtbl =
977 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
979 FilterMapper2_QueryInterface,
980 FilterMapper2_AddRef,
981 FilterMapper2_Release,
983 FilterMapper2_CreateCategory,
984 FilterMapper2_UnregisterFilter,
985 FilterMapper2_RegisterFilter,
986 FilterMapper2_EnumMatchingFilters
989 /*** IUnknown methods ***/
991 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
993 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
995 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
997 return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1000 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1002 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1004 return FilterMapper2_AddRef((IFilterMapper2*)This);
1007 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1009 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1011 return FilterMapper2_Release((IFilterMapper2*)This);
1014 /*** IFilterMapper methods ***/
1016 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1017 IFilterMapper * iface,
1018 IEnumRegFilters **ppEnum,
1033 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1039 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1045 static HRESULT WINAPI FilterMapper_RegisterPin(
1046 IFilterMapper * iface,
1053 CLSID ConnectsToFilter,
1054 LPCWSTR ConnectsToPin)
1061 static HRESULT WINAPI FilterMapper_RegisterPinType(
1062 IFilterMapper * iface,
1072 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1078 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1084 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1090 static ICOM_VTABLE(IFilterMapper) fmvtbl =
1092 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1094 FilterMapper_QueryInterface,
1095 FilterMapper_AddRef,
1096 FilterMapper_Release,
1098 FilterMapper_RegisterFilter,
1099 FilterMapper_RegisterFilterInstance,
1100 FilterMapper_RegisterPin,
1101 FilterMapper_RegisterPinType,
1102 FilterMapper_UnregisterFilter,
1103 FilterMapper_UnregisterFilterInstance,
1104 FilterMapper_UnregisterPin,
1105 FilterMapper_EnumMatchingFilters