2 * IFilterMapper & IFilterMapper2 Implementations
4 * Copyright 2003 Robert Shearman
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
32 #include "quartz_private.h"
34 #define COM_NO_WINDOWS_H
37 #include "wine/obj_property.h"
38 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 typedef struct FilterMapper2Impl
47 ICOM_VFIELD(IFilterMapper2);
48 ICOM_VTABLE(IFilterMapper) * lpVtblFilterMapper;
52 static struct ICOM_VTABLE(IFilterMapper2) fm2vtbl;
53 static struct ICOM_VTABLE(IFilterMapper) fmvtbl;
55 #define _IFilterMapper_Offset ((int)(&(((FilterMapper2Impl*)0)->lpVtblFilterMapper)))
56 #define ICOM_THIS_From_IFilterMapper(impl, iface) impl* This = (impl*)(((char*)iface)-_IFilterMapper_Offset)
58 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
59 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
61 /* CLSID property in media category Moniker */
62 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
63 /* FriendlyName property in media category Moniker */
64 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
65 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
66 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
67 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
68 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
70 /* registry format for REGFILTER2 */
81 BYTE signature[4]; /* e.g. "0pi3" */
86 DWORD bCategory; /* is there a category clsid? */
87 /* optional: dwOffsetCategoryClsid */
92 BYTE signature[4]; /* e.g. "0ty3" */
107 int capacity; /* in bytes */
108 int current; /* pointer to next free byte */
111 /* returns the position it was added at */
112 static int add_data(struct Vector * v, const BYTE * pData, int size)
114 int index = v->current;
115 if (v->current + size > v->capacity)
117 LPBYTE pOldData = v->pData;
118 v->capacity = (v->capacity + size) * 2;
119 v->pData = CoTaskMemAlloc(v->capacity);
120 memcpy(v->pData, pOldData, v->current);
121 CoTaskMemFree(pOldData);
123 memcpy(v->pData + v->current, pData, size);
128 static int find_data(struct Vector * v, const BYTE * pData, int size)
131 for (index = 0; index < v->current; index++)
132 if (!memcmp(v->pData + index, pData, size))
138 static void delete_vector(struct Vector * v)
141 CoTaskMemFree(v->pData);
146 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
148 FilterMapper2Impl * pFM2impl;
150 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
153 return CLASS_E_NOAGGREGATION;
155 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
157 return E_OUTOFMEMORY;
159 pFM2impl->lpVtbl = &fm2vtbl;
160 pFM2impl->lpVtblFilterMapper = &fmvtbl;
161 pFM2impl->refCount = 1;
165 TRACE("-- created at %p\n", pFM2impl);
170 /*** IUnknown methods ***/
172 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
174 ICOM_THIS(FilterMapper2Impl, iface);
176 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
180 if (IsEqualIID(riid, &IID_IUnknown))
182 else if (IsEqualIID(riid, &IID_IFilterMapper2))
184 else if (IsEqualIID(riid, &IID_IFilterMapper))
185 *ppv = &This->lpVtblFilterMapper;
189 IUnknown_AddRef((IUnknown *)*ppv);
193 FIXME("No interface for %s\n", debugstr_guid(riid));
194 return E_NOINTERFACE;
197 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
199 ICOM_THIS(FilterMapper2Impl, iface);
203 return InterlockedIncrement(&This->refCount);
206 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
208 ICOM_THIS(FilterMapper2Impl, iface);
212 if (InterlockedDecrement(&This->refCount) == 0)
217 return This->refCount;
220 /*** IFilterMapper2 methods ***/
222 static HRESULT WINAPI FilterMapper2_CreateCategory(
223 IFilterMapper2 * iface,
224 REFCLSID clsidCategory,
225 DWORD dwCategoryMerit,
226 LPCWSTR szDescription)
228 LPWSTR wClsidAMCat = NULL;
229 LPWSTR wClsidCategory = NULL;
230 WCHAR wszKeyName[strlenW(wszClsidSlash) + strlenW(wszSlashInstance) + (CHARS_IN_GUID-1) * 2 + 1];
234 TRACE("(%s, %lx, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
236 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
240 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
245 strcpyW(wszKeyName, wszClsidSlash);
246 strcatW(wszKeyName, wClsidAMCat);
247 strcatW(wszKeyName, wszSlashInstance);
248 strcatW(wszKeyName, wClsidCategory);
250 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
255 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (LPBYTE)szDescription, strlenW(szDescription) + 1));
260 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, strlenW(wClsidCategory) + 1));
265 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit)));
271 CoTaskMemFree(wClsidCategory);
273 CoTaskMemFree(wClsidAMCat);
278 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
279 IFilterMapper2 * iface,
280 const CLSID *pclsidCategory,
281 const OLECHAR *szInstance,
284 WCHAR wszKeyName[MAX_PATH];
285 LPWSTR wClsidCategory = NULL;
286 LPWSTR wFilter = NULL;
289 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
292 pclsidCategory = &CLSID_LegacyAmFilterCategory;
294 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
298 strcpyW(wszKeyName, wszClsidSlash);
299 strcatW(wszKeyName, wClsidCategory);
300 strcatW(wszKeyName, wszSlashInstance);
302 strcatW(wszKeyName, szInstance);
305 hr = StringFromCLSID(Filter, &wFilter);
307 strcatW(wszKeyName, wFilter);
313 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName));
317 CoTaskMemFree(wClsidCategory);
319 CoTaskMemFree(wFilter);
324 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
328 V_VT(&var) = VT_BSTR;
329 V_UNION(&var, bstrVal) = (BSTR)szName;
331 return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
334 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
336 LPWSTR wszClsid = NULL;
340 hr = StringFromCLSID(clsid, &wszClsid);
344 V_VT(&var) = VT_BSTR;
345 V_UNION(&var, bstrVal) = wszClsid;
346 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
349 CoTaskMemFree(wszClsid);
353 static HRESULT FM2_WriteFilterData(IPropertyBag * pPropBag, const REGFILTER2 * prf2)
356 int size = sizeof(struct REG_RF);
358 struct Vector mainStore = {NULL, 0, 0};
359 struct Vector clsidStore = {NULL, 0, 0};
362 SAFEARRAYBOUND saBound;
365 rrf.dwVersion = prf2->dwVersion;
366 rrf.dwMerit = prf2->dwMerit;
367 rrf.dwPins = prf2->u.s1.cPins2;
370 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
372 for (i = 0; i < prf2->u.s1.cPins2; i++)
374 size += sizeof(struct REG_RFP);
375 if (prf2->u.s1.rgPins2[i].clsPinCategory)
376 size += sizeof(DWORD);
377 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
378 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
381 for (i = 0; i < prf2->u.s1.cPins2; i++)
384 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
387 rrfp.signature[0] = '0';
388 rrfp.signature[1] = 'p';
389 rrfp.signature[2] = 'i';
390 rrfp.signature[3] = '3';
391 rrfp.signature[0] += i;
392 rrfp.dwFlags = rgPin2.dwFlags;
393 rrfp.dwInstances = rgPin2.cInstances;
394 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
395 rrfp.dwMediums = rgPin2.nMediums;
396 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
398 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
401 DWORD index = find_data(&clsidStore, (LPBYTE)rgPin2.clsPinCategory, sizeof(CLSID));
403 index = add_data(&clsidStore, (LPBYTE)rgPin2.clsPinCategory, sizeof(CLSID));
406 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
409 for (j = 0; j < rgPin2.nMediaTypes; j++)
412 rt.signature[0] = '0';
413 rt.signature[1] = 't';
414 rt.signature[2] = 'y';
415 rt.signature[3] = '3';
416 rt.signature[0] += j;
419 rt.dwOffsetMajor = find_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
420 if (rt.dwOffsetMajor == -1)
421 rt.dwOffsetMajor = add_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
422 rt.dwOffsetMajor += size;
423 rt.dwOffsetMinor = find_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
424 if (rt.dwOffsetMinor == -1)
425 rt.dwOffsetMinor = add_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
426 rt.dwOffsetMinor += size;
428 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
431 for (j = 0; j < rgPin2.nMediums; j++)
433 DWORD index = find_data(&clsidStore, (LPBYTE)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
435 index = add_data(&clsidStore, (LPBYTE)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
438 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
443 saBound.cElements = mainStore.current + clsidStore.current;
444 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
447 ERR("Couldn't create SAFEARRAY\n");
454 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
457 memcpy(pbSAData, mainStore.pData, mainStore.current);
458 memcpy(pbSAData + mainStore.current, clsidStore.pData, clsidStore.current);
459 hr = SafeArrayUnaccessData(psa);
463 V_VT(&var) = VT_ARRAY | VT_UI1;
464 V_UNION(&var, parray) = psa;
467 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
470 SafeArrayDestroy(psa);
472 delete_vector(&mainStore);
473 delete_vector(&clsidStore);
477 static HRESULT FM2_ReadFilterData(IPropertyBag * pPropBag, REGFILTER2 * prf2)
482 struct REG_RF * prrf;
485 REGFILTERPINS2 * rgPins2;
488 V_VT(&var) = VT_ARRAY | VT_UI1;
490 hr = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
493 hr = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
497 prrf = (struct REG_RF *)pData;
500 if (prrf->dwVersion != 2)
502 FIXME("Filter registry version %ld not supported\n", prrf->dwVersion);
503 ZeroMemory(prf2, sizeof(*prf2));
510 TRACE("version = %ld, merit = %lx, #pins = %ld, unused = %lx\n",
511 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
513 prf2->dwVersion = prrf->dwVersion;
514 prf2->dwMerit = prrf->dwMerit;
515 prf2->u.s1.cPins2 = prrf->dwPins;
516 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
517 prf2->u.s1.rgPins2 = rgPins2;
518 pCurrent += sizeof(struct REG_RF);
520 for (i = 0; i < prrf->dwPins; i++)
522 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
523 REGPINTYPES * lpMediaType;
524 REGPINMEDIUM * lpMedium;
527 /* FIXME: check signature */
529 TRACE("\tsignature = %s\n", debugstr_an(prrfp->signature, 4));
531 TRACE("\tpin[%ld]: flags = %lx, instances = %ld, media types = %ld, mediums = %ld\n",
532 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
534 rgPins2[i].dwFlags = prrfp->dwFlags;
535 rgPins2[i].cInstances = prrfp->dwInstances;
536 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
537 rgPins2[i].nMediums = prrfp->dwMediums;
538 pCurrent += sizeof(struct REG_RFP);
539 if (prrfp->bCategory)
541 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
542 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
543 pCurrent += sizeof(DWORD);
544 rgPins2[i].clsPinCategory = clsCat;
547 rgPins2[i].clsPinCategory = NULL;
549 if (rgPins2[i].nMediaTypes > 0)
550 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
554 rgPins2[i].lpMediaType = lpMediaType;
556 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
558 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
559 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
560 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
562 /* FIXME: check signature */
563 TRACE("\t\tsignature = %s\n", debugstr_an(prt->signature, 4));
565 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
566 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
568 lpMediaType[j].clsMajorType = clsMajor;
569 lpMediaType[j].clsMinorType = clsMinor;
571 pCurrent += sizeof(*prt);
574 if (rgPins2[i].nMediums > 0)
575 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
579 rgPins2[i].lpMedium = lpMedium;
581 for (j = 0; j < rgPins2[i].nMediums; j++)
583 DWORD dwOffset = *(DWORD *)pCurrent;
585 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
587 pCurrent += sizeof(dwOffset);
594 SafeArrayUnaccessData(V_UNION(&var, parray));
601 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
604 for (i = 0; i < prf2->u.s1.cPins2; i++)
607 if (prf2->u.s1.rgPins2[i].clsPinCategory)
608 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
610 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
612 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
613 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
615 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
619 static HRESULT WINAPI FilterMapper2_RegisterFilter(
620 IFilterMapper2 * iface,
621 REFCLSID clsidFilter,
623 IMoniker **ppMoniker,
624 const CLSID *pclsidCategory,
625 const OLECHAR *szInstance,
626 const REGFILTER2 *prf2)
628 IParseDisplayName * pParser = NULL;
629 IBindCtx * pBindCtx = NULL;
630 IMoniker * pMoniker = NULL;
631 IPropertyBag * pPropBag = NULL;
633 LPWSTR pwszParseName = NULL;
635 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
638 LPWSTR szClsidTemp = NULL;
640 TRACE("(%s, %s, %p, %s, %s, %p)\n",
641 debugstr_guid(clsidFilter),
644 debugstr_guid(pclsidCategory),
645 debugstr_w(szInstance),
649 FIXME("ppMoniker != NULL not supported at the moment\n");
651 if (prf2->dwVersion != 2)
653 FIXME("dwVersion != 2 not supported at the moment\n");
658 pclsidCategory = &CLSID_ActiveMovieCategories;
660 /* sizeof... will include null terminator and
661 * the + 1 is for the seperator ('\\'). The -1 is
662 * because CHARS_IN_GUID includes the null terminator
664 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
667 nameLen += strlenW(szInstance);
669 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
671 pwszParseName = CoTaskMemAlloc(nameLen);
672 pCurrent = pwszParseName;
674 return E_OUTOFMEMORY;
676 strcpyW(pwszParseName, wszDevice);
677 pCurrent += strlenW(wszDevice);
679 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
680 strcpyW(pCurrent, szClsidTemp);
681 pCurrent += CHARS_IN_GUID - 1;
687 strcpyW(pCurrent+1, szInstance);
692 CoTaskMemFree(szClsidTemp);
695 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
696 strcpyW(pCurrent+1, szClsidTemp);
701 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
704 hr = CreateBindCtx(0, &pBindCtx);
708 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
712 IBindCtx_Release(pBindCtx); pBindCtx = NULL;
715 IParseDisplayName_Release(pParser); pParser = NULL;
718 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
721 hr = FM2_WriteFriendlyName(pPropBag, szName);
724 hr = FM2_WriteClsid(pPropBag, clsidFilter);
727 hr = FM2_WriteFilterData(pPropBag, prf2);
730 IMoniker_Release(pMoniker); pMoniker = NULL;
733 IPropertyBag_Release(pPropBag); pPropBag = NULL;
736 CoTaskMemFree(szClsidTemp);
738 TRACE("-- returning %lx\n", hr);
743 /* internal helper function */
744 static BOOL MatchTypes(
747 const REGPINTYPES * pPinTypes,
749 const GUID * pMatchTypes)
754 if ((nMatchTypes == 0) && (nPinTypes > 0))
757 for (j = 0; j < nPinTypes; j++)
760 for (i = 0; i < nMatchTypes*2; i+=2)
762 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
763 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
773 /* internal helper function for qsort of MONIKER_MERIT array */
774 static int mm_compare(const void * left, const void * right)
776 const struct MONIKER_MERIT * mmLeft = (struct MONIKER_MERIT *)left;
777 const struct MONIKER_MERIT * mmRight = (struct MONIKER_MERIT *)right;
779 if (mmLeft->dwMerit == mmRight->dwMerit)
781 if (mmLeft->dwMerit > mmRight->dwMerit)
787 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
788 * (GUID_NULL's in input to function automatically treated as wild cards)
789 * Input/Output needed means match only on criteria if TRUE (with zero input types
790 * meaning match any input/output pin as long as one exists), otherwise match any
791 * filter that meets the rest of the requirements.
793 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
794 IFilterMapper2 * iface,
795 IEnumMoniker **ppEnum,
801 const GUID *pInputTypes,
802 const REGPINMEDIUM *pMedIn,
803 const CLSID *pPinCategoryIn,
807 const GUID *pOutputTypes,
808 const REGPINMEDIUM *pMedOut,
809 const CLSID *pPinCategoryOut)
811 ICreateDevEnum * pCreateDevEnum;
812 IMoniker * pMonikerCat;
813 IEnumMoniker * pEnumCat;
815 struct Vector monikers = {NULL, 0, 0};
817 TRACE("(%p, %lx, %s, %lx, %s, %ld, %p, %p, %p, %s, %s, %p, %p, %p)\n",
820 bExactMatch ? "true" : "false",
822 bInputNeeded ? "true" : "false",
827 bRender ? "true" : "false",
828 bOutputNeeded ? "true" : "false",
835 FIXME("dwFlags = %lx not implemented\n", dwFlags);
840 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
843 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
845 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
847 IPropertyBag * pPropBagCat = NULL;
849 HRESULT hrSub; /* this is so that one buggy filter
850 doesn't make the whole lot fail */
854 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
856 if (SUCCEEDED(hrSub))
857 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
859 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
862 IEnumMoniker * pEnum;
867 if (TRACE_ON(quartz))
870 V_VT(&temp) = VT_EMPTY;
871 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
872 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
876 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
878 if (SUCCEEDED(hrSub))
879 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
881 if (SUCCEEDED(hrSub))
882 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
884 if (SUCCEEDED(hrSub))
886 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
888 IPropertyBag * pPropBag = NULL;
891 BOOL bInputMatch = !bInputNeeded;
892 BOOL bOutputMatch = !bOutputNeeded;
894 ZeroMemory(&rf2, sizeof(rf2));
896 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
898 if (SUCCEEDED(hrSub))
899 hrSub = FM2_ReadFilterData(pPropBag, &rf2);
901 /* Logic used for bInputMatch expression:
902 * There exists some pin such that bInputNeeded implies (pin is an input and
903 * (bRender implies pin has render flag) and major/minor types members of
905 * bOutputMatch is similar, but without the "bRender implies ..." part
906 * and substituting variables names containing input for output
909 /* determine whether filter meets requirements */
910 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
912 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
914 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
916 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
917 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
918 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
919 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
920 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
923 if (bInputMatch && bOutputMatch)
925 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
926 IMoniker_AddRef(pMoniker);
927 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
931 FM2_DeleteRegFilter(&rf2);
933 IPropertyBag_Release(pPropBag);
934 IMoniker_Release(pMoniker);
936 IEnumMoniker_Release(pEnum);
942 IPropertyBag_Release(pPropBagCat);
943 IMoniker_Release(pMonikerCat);
949 IMoniker ** ppMoniker;
951 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
953 /* sort the monikers in descending merit order */
954 qsort(monikers.pData, nMonikerCount,
955 sizeof(struct MONIKER_MERIT),
958 /* construct an IEnumMoniker interface */
959 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
960 for (i = 0; i < nMonikerCount; i++)
962 /* no need to AddRef here as already AddRef'd above */
963 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
965 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
966 CoTaskMemFree(ppMoniker);
969 delete_vector(&monikers);
970 IEnumMoniker_Release(pEnumCat);
971 ICreateDevEnum_Release(pCreateDevEnum);
976 static ICOM_VTABLE(IFilterMapper2) fm2vtbl =
978 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
980 FilterMapper2_QueryInterface,
981 FilterMapper2_AddRef,
982 FilterMapper2_Release,
984 FilterMapper2_CreateCategory,
985 FilterMapper2_UnregisterFilter,
986 FilterMapper2_RegisterFilter,
987 FilterMapper2_EnumMatchingFilters
990 /*** IUnknown methods ***/
992 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
994 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
996 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
998 return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1001 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1003 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1005 return FilterMapper2_AddRef((IFilterMapper2*)This);
1008 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1010 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1012 return FilterMapper2_Release((IFilterMapper2*)This);
1015 /*** IFilterMapper methods ***/
1017 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1018 IFilterMapper * iface,
1019 IEnumRegFilters **ppEnum,
1034 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1040 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1046 static HRESULT WINAPI FilterMapper_RegisterPin(
1047 IFilterMapper * iface,
1054 CLSID ConnectsToFilter,
1055 LPCWSTR ConnectsToPin)
1062 static HRESULT WINAPI FilterMapper_RegisterPinType(
1063 IFilterMapper * iface,
1073 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1079 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1085 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1091 static ICOM_VTABLE(IFilterMapper) fmvtbl =
1093 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1095 FilterMapper_QueryInterface,
1096 FilterMapper_AddRef,
1097 FilterMapper_Release,
1099 FilterMapper_RegisterFilter,
1100 FilterMapper_RegisterFilterInstance,
1101 FilterMapper_RegisterPin,
1102 FilterMapper_RegisterPinType,
1103 FilterMapper_UnregisterFilter,
1104 FilterMapper_UnregisterFilterInstance,
1105 FilterMapper_UnregisterPin,
1106 FilterMapper_EnumMatchingFilters