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
29 #include "quartz_private.h"
31 #define COM_NO_WINDOWS_H
34 #include "wine/obj_property.h"
35 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
42 typedef struct FilterMapper2Impl
44 ICOM_VFIELD(IFilterMapper2
);
45 ICOM_VTABLE(IFilterMapper
) * lpVtblFilterMapper
;
49 static struct ICOM_VTABLE(IFilterMapper2
) fm2vtbl
;
50 static struct ICOM_VTABLE(IFilterMapper
) fmvtbl
;
52 #define _IFilterMapper_Offset ((int)(&(((FilterMapper2Impl*)0)->lpVtblFilterMapper)))
53 #define ICOM_THIS_From_IFilterMapper(impl, iface) impl* This = (impl*)(((char*)iface)-_IFilterMapper_Offset)
55 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
56 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
58 /* CLSID property in media category Moniker */
59 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
60 /* FriendlyName property in media category Moniker */
61 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
62 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
63 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
64 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
65 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
67 /* registry format for REGFILTER2 */
78 BYTE signature
[4]; /* e.g. "0pi3" */
83 DWORD bCategory
; /* is there a category clsid? */
84 /* optional: dwOffsetCategoryClsid */
89 BYTE signature
[4]; /* e.g. "0ty3" */
104 int capacity
; /* in bytes */
105 int current
; /* pointer to next free byte */
108 /* returns the position it was added at */
109 static int add_data(struct Vector
* v
, const BYTE
* pData
, int size
)
111 int index
= v
->current
;
112 if (v
->current
+ size
> v
->capacity
)
114 LPBYTE pOldData
= v
->pData
;
115 v
->capacity
= (v
->capacity
+ size
) * 2;
116 v
->pData
= CoTaskMemAlloc(v
->capacity
);
117 memcpy(v
->pData
, pOldData
, v
->current
);
118 CoTaskMemFree(pOldData
);
120 memcpy(v
->pData
+ v
->current
, pData
, size
);
125 static int find_data(struct Vector
* v
, const BYTE
* pData
, int size
)
128 for (index
= 0; index
< v
->current
; index
++)
129 if (!memcmp(v
->pData
+ index
, pData
, size
))
135 static void delete_vector(struct Vector
* v
)
138 CoTaskMemFree(v
->pData
);
143 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
145 FilterMapper2Impl
* pFM2impl
;
147 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
150 return CLASS_E_NOAGGREGATION
;
152 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
154 return E_OUTOFMEMORY
;
156 pFM2impl
->lpVtbl
= &fm2vtbl
;
157 pFM2impl
->lpVtblFilterMapper
= &fmvtbl
;
158 pFM2impl
->refCount
= 1;
162 TRACE("-- created at %p\n", pFM2impl
);
167 /*** IUnknown methods ***/
169 static HRESULT WINAPI
FilterMapper2_QueryInterface(IFilterMapper2
* iface
, REFIID riid
, LPVOID
*ppv
)
171 ICOM_THIS(FilterMapper2Impl
, iface
);
173 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
177 if (IsEqualIID(riid
, &IID_IUnknown
))
179 else if (IsEqualIID(riid
, &IID_IFilterMapper2
))
181 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
182 *ppv
= &This
->lpVtblFilterMapper
;
186 IUnknown_AddRef((IUnknown
*)*ppv
);
190 FIXME("No interface for %s\n", debugstr_guid(riid
));
191 return E_NOINTERFACE
;
194 static ULONG WINAPI
FilterMapper2_AddRef(IFilterMapper2
* iface
)
196 ICOM_THIS(FilterMapper2Impl
, iface
);
200 return InterlockedIncrement(&This
->refCount
);
203 static ULONG WINAPI
FilterMapper2_Release(IFilterMapper2
* iface
)
205 ICOM_THIS(FilterMapper2Impl
, iface
);
209 if (InterlockedDecrement(&This
->refCount
) == 0)
214 return This
->refCount
;
217 /*** IFilterMapper2 methods ***/
219 static HRESULT WINAPI
FilterMapper2_CreateCategory(
220 IFilterMapper2
* iface
,
221 REFCLSID clsidCategory
,
222 DWORD dwCategoryMerit
,
223 LPCWSTR szDescription
)
225 LPWSTR wClsidAMCat
= NULL
;
226 LPWSTR wClsidCategory
= NULL
;
227 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + strlenW(wszSlashInstance
) + (CHARS_IN_GUID
-1) * 2 + 1];
231 TRACE("(%s, %lx, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
233 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
237 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
242 strcpyW(wszKeyName
, wszClsidSlash
);
243 strcatW(wszKeyName
, wClsidAMCat
);
244 strcatW(wszKeyName
, wszSlashInstance
);
245 strcatW(wszKeyName
, wClsidCategory
);
247 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
));
252 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (LPBYTE
)szDescription
, strlenW(szDescription
) + 1));
257 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, strlenW(wClsidCategory
) + 1));
262 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
)));
268 CoTaskMemFree(wClsidCategory
);
270 CoTaskMemFree(wClsidAMCat
);
275 static HRESULT WINAPI
FilterMapper2_UnregisterFilter(
276 IFilterMapper2
* iface
,
277 const CLSID
*pclsidCategory
,
278 const OLECHAR
*szInstance
,
281 WCHAR wszKeyName
[MAX_PATH
];
282 LPWSTR wClsidCategory
= NULL
;
283 LPWSTR wFilter
= NULL
;
286 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
289 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
291 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
295 strcpyW(wszKeyName
, wszClsidSlash
);
296 strcatW(wszKeyName
, wClsidCategory
);
297 strcatW(wszKeyName
, wszSlashInstance
);
299 strcatW(wszKeyName
, szInstance
);
302 hr
= StringFromCLSID(Filter
, &wFilter
);
304 strcatW(wszKeyName
, wFilter
);
310 hr
= HRESULT_FROM_WIN32(RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
));
314 CoTaskMemFree(wClsidCategory
);
316 CoTaskMemFree(wFilter
);
321 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
325 V_VT(&var
) = VT_BSTR
;
326 V_UNION(&var
, bstrVal
) = (BSTR
)szName
;
328 return IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
331 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
333 LPWSTR wszClsid
= NULL
;
337 hr
= StringFromCLSID(clsid
, &wszClsid
);
341 V_VT(&var
) = VT_BSTR
;
342 V_UNION(&var
, bstrVal
) = wszClsid
;
343 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
346 CoTaskMemFree(wszClsid
);
350 static HRESULT
FM2_WriteFilterData(IPropertyBag
* pPropBag
, const REGFILTER2
* prf2
)
353 int size
= sizeof(struct REG_RF
);
355 struct Vector mainStore
= {NULL
, 0, 0};
356 struct Vector clsidStore
= {NULL
, 0, 0};
359 SAFEARRAYBOUND saBound
;
362 rrf
.dwVersion
= prf2
->dwVersion
;
363 rrf
.dwMerit
= prf2
->dwMerit
;
364 rrf
.dwPins
= prf2
->u
.s1
.cPins2
;
367 add_data(&mainStore
, (LPBYTE
)&rrf
, sizeof(rrf
));
369 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
371 size
+= sizeof(struct REG_RFP
);
372 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
373 size
+= sizeof(DWORD
);
374 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
375 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
378 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
381 REGFILTERPINS2 rgPin2
= prf2
->u
.s1
.rgPins2
[i
];
384 rrfp
.signature
[0] = '0';
385 rrfp
.signature
[1] = 'p';
386 rrfp
.signature
[2] = 'i';
387 rrfp
.signature
[3] = '3';
388 rrfp
.signature
[0] += i
;
389 rrfp
.dwFlags
= rgPin2
.dwFlags
;
390 rrfp
.dwInstances
= rgPin2
.cInstances
;
391 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
392 rrfp
.dwMediums
= rgPin2
.nMediums
;
393 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
395 add_data(&mainStore
, (LPBYTE
)&rrfp
, sizeof(rrfp
));
398 DWORD index
= find_data(&clsidStore
, (LPBYTE
)rgPin2
.clsPinCategory
, sizeof(CLSID
));
400 index
= add_data(&clsidStore
, (LPBYTE
)rgPin2
.clsPinCategory
, sizeof(CLSID
));
403 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
406 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
409 rt
.signature
[0] = '0';
410 rt
.signature
[1] = 't';
411 rt
.signature
[2] = 'y';
412 rt
.signature
[3] = '3';
413 rt
.signature
[0] += j
;
416 rt
.dwOffsetMajor
= find_data(&clsidStore
, (LPBYTE
)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
417 if (rt
.dwOffsetMajor
== -1)
418 rt
.dwOffsetMajor
= add_data(&clsidStore
, (LPBYTE
)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
419 rt
.dwOffsetMajor
+= size
;
420 rt
.dwOffsetMinor
= find_data(&clsidStore
, (LPBYTE
)rgPin2
.lpMediaType
[j
].clsMinorType
, sizeof(CLSID
));
421 if (rt
.dwOffsetMinor
== -1)
422 rt
.dwOffsetMinor
= add_data(&clsidStore
, (LPBYTE
)rgPin2
.lpMediaType
[j
].clsMinorType
, sizeof(CLSID
));
423 rt
.dwOffsetMinor
+= size
;
425 add_data(&mainStore
, (LPBYTE
)&rt
, sizeof(rt
));
428 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
430 DWORD index
= find_data(&clsidStore
, (LPBYTE
)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
432 index
= add_data(&clsidStore
, (LPBYTE
)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
435 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
440 saBound
.cElements
= mainStore
.current
+ clsidStore
.current
;
441 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
444 ERR("Couldn't create SAFEARRAY\n");
451 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
454 memcpy(pbSAData
, mainStore
.pData
, mainStore
.current
);
455 memcpy(pbSAData
+ mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
456 hr
= SafeArrayUnaccessData(psa
);
460 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
461 V_UNION(&var
, parray
) = psa
;
464 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
467 SafeArrayDestroy(psa
);
469 delete_vector(&mainStore
);
470 delete_vector(&clsidStore
);
474 static HRESULT
FM2_ReadFilterData(IPropertyBag
* pPropBag
, REGFILTER2
* prf2
)
479 struct REG_RF
* prrf
;
482 REGFILTERPINS2
* rgPins2
;
485 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
487 hr
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
490 hr
= SafeArrayAccessData(V_UNION(&var
, parray
), (LPVOID
*)&pData
);
494 prrf
= (struct REG_RF
*)pData
;
497 if (prrf
->dwVersion
!= 2)
499 FIXME("Filter registry version %ld not supported\n", prrf
->dwVersion
);
500 ZeroMemory(prf2
, sizeof(*prf2
));
507 TRACE("version = %ld, merit = %lx, #pins = %ld, unused = %lx\n",
508 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
510 prf2
->dwVersion
= prrf
->dwVersion
;
511 prf2
->dwMerit
= prrf
->dwMerit
;
512 prf2
->u
.s1
.cPins2
= prrf
->dwPins
;
513 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
514 prf2
->u
.s1
.rgPins2
= rgPins2
;
515 pCurrent
+= sizeof(struct REG_RF
);
517 for (i
= 0; i
< prrf
->dwPins
; i
++)
519 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
520 REGPINTYPES
* lpMediaType
;
521 REGPINMEDIUM
* lpMedium
;
524 /* FIXME: check signature */
526 TRACE("\tsignature = %s\n", debugstr_an(prrfp
->signature
, 4));
528 TRACE("\tpin[%ld]: flags = %lx, instances = %ld, media types = %ld, mediums = %ld\n",
529 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
531 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
532 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
533 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
534 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
535 pCurrent
+= sizeof(struct REG_RFP
);
536 if (prrfp
->bCategory
)
538 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
539 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
540 pCurrent
+= sizeof(DWORD
);
541 rgPins2
[i
].clsPinCategory
= clsCat
;
544 rgPins2
[i
].clsPinCategory
= NULL
;
546 if (rgPins2
[i
].nMediaTypes
> 0)
547 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
551 rgPins2
[i
].lpMediaType
= lpMediaType
;
553 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
555 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
556 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
557 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
559 /* FIXME: check signature */
560 TRACE("\t\tsignature = %s\n", debugstr_an(prt
->signature
, 4));
562 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
563 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
565 lpMediaType
[j
].clsMajorType
= clsMajor
;
566 lpMediaType
[j
].clsMinorType
= clsMinor
;
568 pCurrent
+= sizeof(*prt
);
571 if (rgPins2
[i
].nMediums
> 0)
572 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
576 rgPins2
[i
].lpMedium
= lpMedium
;
578 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
580 DWORD dwOffset
= *(DWORD
*)pCurrent
;
582 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
584 pCurrent
+= sizeof(dwOffset
);
591 SafeArrayUnaccessData(V_UNION(&var
, parray
));
598 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
601 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
604 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
605 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
);
607 for (j
= 0; j
< prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
; j
++)
609 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
610 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
612 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMedium
);
616 static HRESULT WINAPI
FilterMapper2_RegisterFilter(
617 IFilterMapper2
* iface
,
618 REFCLSID clsidFilter
,
620 IMoniker
**ppMoniker
,
621 const CLSID
*pclsidCategory
,
622 const OLECHAR
*szInstance
,
623 const REGFILTER2
*prf2
)
625 IParseDisplayName
* pParser
= NULL
;
626 IBindCtx
* pBindCtx
= NULL
;
627 IMoniker
* pMoniker
= NULL
;
628 IPropertyBag
* pPropBag
= NULL
;
630 LPWSTR pwszParseName
= NULL
;
632 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
635 LPWSTR szClsidTemp
= NULL
;
637 TRACE("(%s, %s, %p, %s, %s, %p)\n",
638 debugstr_guid(clsidFilter
),
641 debugstr_guid(pclsidCategory
),
642 debugstr_w(szInstance
),
646 FIXME("ppMoniker != NULL not supported at the moment\n");
648 if (prf2
->dwVersion
!= 2)
650 FIXME("dwVersion != 2 not supported at the moment\n");
655 pclsidCategory
= &CLSID_ActiveMovieCategories
;
657 /* sizeof... will include null terminator and
658 * the + 1 is for the separator ('\\'). The -1 is
659 * because CHARS_IN_GUID includes the null terminator
661 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
664 nameLen
+= strlenW(szInstance
);
666 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
668 pwszParseName
= CoTaskMemAlloc(nameLen
);
669 pCurrent
= pwszParseName
;
671 return E_OUTOFMEMORY
;
673 strcpyW(pwszParseName
, wszDevice
);
674 pCurrent
+= strlenW(wszDevice
);
676 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
677 strcpyW(pCurrent
, szClsidTemp
);
678 pCurrent
+= CHARS_IN_GUID
- 1;
684 strcpyW(pCurrent
+1, szInstance
);
689 CoTaskMemFree(szClsidTemp
);
692 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
693 strcpyW(pCurrent
+1, szClsidTemp
);
698 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
701 hr
= CreateBindCtx(0, &pBindCtx
);
705 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
709 IBindCtx_Release(pBindCtx
); pBindCtx
= NULL
;
712 IParseDisplayName_Release(pParser
); pParser
= NULL
;
715 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
718 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
721 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
724 hr
= FM2_WriteFilterData(pPropBag
, prf2
);
727 IMoniker_Release(pMoniker
); pMoniker
= NULL
;
730 IPropertyBag_Release(pPropBag
); pPropBag
= NULL
;
733 CoTaskMemFree(szClsidTemp
);
735 TRACE("-- returning %lx\n", hr
);
740 /* internal helper function */
741 static BOOL
MatchTypes(
744 const REGPINTYPES
* pPinTypes
,
746 const GUID
* pMatchTypes
)
751 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
754 for (j
= 0; j
< nPinTypes
; j
++)
757 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
759 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
760 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
770 /* internal helper function for qsort of MONIKER_MERIT array */
771 static int mm_compare(const void * left
, const void * right
)
773 const struct MONIKER_MERIT
* mmLeft
= (struct MONIKER_MERIT
*)left
;
774 const struct MONIKER_MERIT
* mmRight
= (struct MONIKER_MERIT
*)right
;
776 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
778 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
784 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
785 * (GUID_NULL's in input to function automatically treated as wild cards)
786 * Input/Output needed means match only on criteria if TRUE (with zero input types
787 * meaning match any input/output pin as long as one exists), otherwise match any
788 * filter that meets the rest of the requirements.
790 static HRESULT WINAPI
FilterMapper2_EnumMatchingFilters(
791 IFilterMapper2
* iface
,
792 IEnumMoniker
**ppEnum
,
798 const GUID
*pInputTypes
,
799 const REGPINMEDIUM
*pMedIn
,
800 const CLSID
*pPinCategoryIn
,
804 const GUID
*pOutputTypes
,
805 const REGPINMEDIUM
*pMedOut
,
806 const CLSID
*pPinCategoryOut
)
808 ICreateDevEnum
* pCreateDevEnum
;
809 IMoniker
* pMonikerCat
;
810 IEnumMoniker
* pEnumCat
;
812 struct Vector monikers
= {NULL
, 0, 0};
814 TRACE("(%p, %lx, %s, %lx, %s, %ld, %p, %p, %p, %s, %s, %p, %p, %p)\n",
817 bExactMatch
? "true" : "false",
819 bInputNeeded
? "true" : "false",
824 bRender
? "true" : "false",
825 bOutputNeeded
? "true" : "false",
832 FIXME("dwFlags = %lx not implemented\n", dwFlags
);
837 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
840 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
842 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
844 IPropertyBag
* pPropBagCat
= NULL
;
846 HRESULT hrSub
; /* this is so that one buggy filter
847 doesn't make the whole lot fail */
851 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
853 if (SUCCEEDED(hrSub
))
854 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
856 if (SUCCEEDED(hrSub
) && (V_UNION(&var
, ulVal
) >= dwMerit
))
859 IEnumMoniker
* pEnum
;
864 if (TRACE_ON(quartz
))
867 V_VT(&temp
) = VT_EMPTY
;
868 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
869 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
873 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
875 if (SUCCEEDED(hrSub
))
876 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsidCat
);
878 if (SUCCEEDED(hrSub
))
879 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
881 if (SUCCEEDED(hrSub
))
883 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
885 IPropertyBag
* pPropBag
= NULL
;
888 BOOL bInputMatch
= !bInputNeeded
;
889 BOOL bOutputMatch
= !bOutputNeeded
;
891 ZeroMemory(&rf2
, sizeof(rf2
));
893 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
895 if (SUCCEEDED(hrSub
))
896 hrSub
= FM2_ReadFilterData(pPropBag
, &rf2
);
898 /* Logic used for bInputMatch expression:
899 * There exists some pin such that bInputNeeded implies (pin is an input and
900 * (bRender implies pin has render flag) and major/minor types members of
902 * bOutputMatch is similar, but without the "bRender implies ..." part
903 * and substituting variables names containing input for output
906 /* determine whether filter meets requirements */
907 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
909 for (i
= 0; (i
< rf2
.u
.s1
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
911 const REGFILTERPINS2
* rfp2
= rf2
.u
.s1
.rgPins2
+ i
;
913 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
914 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
915 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
916 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
917 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
920 if (bInputMatch
&& bOutputMatch
)
922 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
923 IMoniker_AddRef(pMoniker
);
924 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
928 FM2_DeleteRegFilter(&rf2
);
930 IPropertyBag_Release(pPropBag
);
931 IMoniker_Release(pMoniker
);
933 IEnumMoniker_Release(pEnum
);
939 IPropertyBag_Release(pPropBagCat
);
940 IMoniker_Release(pMonikerCat
);
946 IMoniker
** ppMoniker
;
948 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
950 /* sort the monikers in descending merit order */
951 qsort(monikers
.pData
, nMonikerCount
,
952 sizeof(struct MONIKER_MERIT
),
955 /* construct an IEnumMoniker interface */
956 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
957 for (i
= 0; i
< nMonikerCount
; i
++)
959 /* no need to AddRef here as already AddRef'd above */
960 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
962 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
963 CoTaskMemFree(ppMoniker
);
966 delete_vector(&monikers
);
967 IEnumMoniker_Release(pEnumCat
);
968 ICreateDevEnum_Release(pCreateDevEnum
);
973 static ICOM_VTABLE(IFilterMapper2
) fm2vtbl
=
975 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
977 FilterMapper2_QueryInterface
,
978 FilterMapper2_AddRef
,
979 FilterMapper2_Release
,
981 FilterMapper2_CreateCategory
,
982 FilterMapper2_UnregisterFilter
,
983 FilterMapper2_RegisterFilter
,
984 FilterMapper2_EnumMatchingFilters
987 /*** IUnknown methods ***/
989 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
991 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl
, iface
);
993 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
995 return FilterMapper2_QueryInterface((IFilterMapper2
*)&This
->lpVtbl
, riid
, ppv
);
998 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1000 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl
, iface
);
1002 return FilterMapper2_AddRef((IFilterMapper2
*)This
);
1005 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1007 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl
, iface
);
1009 return FilterMapper2_Release((IFilterMapper2
*)This
);
1012 /*** IFilterMapper methods ***/
1014 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1015 IFilterMapper
* iface
,
1016 IEnumRegFilters
**ppEnum
,
1031 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1037 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1043 static HRESULT WINAPI
FilterMapper_RegisterPin(
1044 IFilterMapper
* iface
,
1051 CLSID ConnectsToFilter
,
1052 LPCWSTR ConnectsToPin
)
1059 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1060 IFilterMapper
* iface
,
1070 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1076 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1082 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1088 static ICOM_VTABLE(IFilterMapper
) fmvtbl
=
1090 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1092 FilterMapper_QueryInterface
,
1093 FilterMapper_AddRef
,
1094 FilterMapper_Release
,
1096 FilterMapper_RegisterFilter
,
1097 FilterMapper_RegisterFilterInstance
,
1098 FilterMapper_RegisterPin
,
1099 FilterMapper_RegisterPinType
,
1100 FilterMapper_UnregisterFilter
,
1101 FilterMapper_UnregisterFilterInstance
,
1102 FilterMapper_UnregisterPin
,
1103 FilterMapper_EnumMatchingFilters