2 * Copyright (C) 2003 Michael Günnewig
3 * Copyright (C) 2003 CodeWeavers Inc. (Ulrich Czekalla)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msdmo
);
35 #define MSDMO_MAJOR_VERSION 6
37 static const WCHAR szDMORootKey
[] =
39 'D','i','r','e','c','t','S','h','o','w','\\',
40 'M','e','d','i','a','O','b','j','e','c','t','s',0
43 static const WCHAR szDMOInputType
[] =
45 'I','n','p','u','t','T','y','p','e','s',0
48 static const WCHAR szDMOOutputType
[] =
50 'O','u','t','p','u','t','T','y','p','e','s',0
53 static const WCHAR szDMOKeyed
[] =
58 static const WCHAR szDMOCategories
[] =
60 'C','a','t','e','g','o','r','i','e','s',0
63 static const WCHAR szGUIDFmt
[] =
65 '%','0','8','X','-','%','0','4','X','-','%','0','4','X','-','%','0',
66 '2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2',
67 'X','%','0','2','X','%','0','2','X','%','0','2','X',0
70 static const WCHAR szCat3Fmt
[] =
72 '%','s','\\','%','s','\\','%','s',0
75 static const WCHAR szCat2Fmt
[] =
77 '%','s','\\','%','s',0
80 static const WCHAR szToGuidFmt
[] =
88 IEnumDMO IEnumDMO_iface
;
91 const GUID
* guidCategory
;
94 DMO_PARTIAL_MEDIATYPE
*pInTypes
;
96 DMO_PARTIAL_MEDIATYPE
*pOutTypes
;
100 static inline IEnumDMOImpl
*impl_from_IEnumDMO(IEnumDMO
*iface
)
102 return CONTAINING_RECORD(iface
, IEnumDMOImpl
, IEnumDMO_iface
);
105 static HRESULT
read_types(HKEY root
, LPCWSTR key
, ULONG
*supplied
, ULONG requested
, DMO_PARTIAL_MEDIATYPE
* types
);
107 static const IEnumDMOVtbl edmovt
;
109 static LPWSTR
GUIDToString(LPWSTR lpwstr
, REFGUID lpcguid
)
111 wsprintfW(lpwstr
, szGUIDFmt
, lpcguid
->Data1
, lpcguid
->Data2
,
112 lpcguid
->Data3
, lpcguid
->Data4
[0], lpcguid
->Data4
[1],
113 lpcguid
->Data4
[2], lpcguid
->Data4
[3], lpcguid
->Data4
[4],
114 lpcguid
->Data4
[5], lpcguid
->Data4
[6], lpcguid
->Data4
[7]);
119 static BOOL
IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE
* mt1
, const DMO_PARTIAL_MEDIATYPE
* mt2
)
122 return (IsEqualCLSID(&mt1
->type
, &mt2
->type
) ||
123 IsEqualCLSID(&mt2
->type
, &GUID_NULL
) ||
124 IsEqualCLSID(&mt1
->type
, &GUID_NULL
)) &&
125 (IsEqualCLSID(&mt1
->subtype
, &mt2
->subtype
) ||
126 IsEqualCLSID(&mt2
->subtype
, &GUID_NULL
) ||
127 IsEqualCLSID(&mt1
->subtype
, &GUID_NULL
));
130 static HRESULT
write_types(HKEY hkey
, LPCWSTR name
, const DMO_PARTIAL_MEDIATYPE
* types
, DWORD count
)
133 if (MSDMO_MAJOR_VERSION
> 5)
135 hres
= RegSetValueExW(hkey
, name
, 0, REG_BINARY
, (const BYTE
*) types
,
136 count
* sizeof(DMO_PARTIAL_MEDIATYPE
));
140 HKEY skey1
,skey2
,skey3
;
144 hres
= RegCreateKeyExW(hkey
, name
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
145 KEY_WRITE
, NULL
, &skey1
, NULL
);
146 while (index
< count
)
148 GUIDToString(szGuidKey
,&types
[index
].type
);
149 hres
= RegCreateKeyExW(skey1
, szGuidKey
, 0, NULL
,
150 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &skey2
, NULL
);
151 GUIDToString(szGuidKey
,&types
[index
].subtype
);
152 hres
= RegCreateKeyExW(skey2
, szGuidKey
, 0, NULL
,
153 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &skey3
, NULL
);
164 /***************************************************************
165 * DMORegister (MSDMO.@)
167 * Register a DirectX Media Object.
169 HRESULT WINAPI
DMORegister(
172 REFGUID guidCategory
,
175 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
177 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
187 TRACE("%s\n", debugstr_w(szName
));
189 hres
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, NULL
,
190 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hrkey
, NULL
);
191 if (ERROR_SUCCESS
!= hres
)
194 /* Create clsidDMO key under MediaObjects */
195 hres
= RegCreateKeyExW(hrkey
, GUIDToString(szguid
, clsidDMO
), 0, NULL
,
196 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
197 if (ERROR_SUCCESS
!= hres
)
200 /* Set default Name value */
201 hres
= RegSetValueExW(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*) szName
,
202 (strlenW(szName
) + 1) * sizeof(WCHAR
));
205 hres
= write_types(hkey
, szDMOInputType
, pInTypes
, cInTypes
);
207 /* Set OutputTypes */
208 hres
= write_types(hkey
, szDMOOutputType
, pOutTypes
, cOutTypes
);
210 if (dwFlags
& DMO_REGISTERF_IS_KEYED
)
212 /* Create Keyed key */
213 hres
= RegCreateKeyExW(hkey
, szDMOKeyed
, 0, NULL
,
214 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hckey
, NULL
);
215 if (ERROR_SUCCESS
!= hres
)
220 /* Register the category */
221 hres
= RegCreateKeyExW(hrkey
, szDMOCategories
, 0, NULL
,
222 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hckey
, NULL
);
223 if (ERROR_SUCCESS
!= hres
)
228 hres
= RegCreateKeyExW(hckey
, GUIDToString(szguid
, guidCategory
), 0, NULL
,
229 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
230 if (ERROR_SUCCESS
!= hres
)
232 hres
= RegCreateKeyExW(hkey
, GUIDToString(szguid
, clsidDMO
), 0, NULL
,
233 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hclskey
, NULL
);
234 if (ERROR_SUCCESS
!= hres
)
243 RegCloseKey(hclskey
);
247 TRACE(" hresult=0x%08x\n", hres
);
252 /***************************************************************
253 * DMOUnregister (MSDMO.@)
255 * Unregister a DirectX Media Object.
257 HRESULT WINAPI
DMOUnregister(REFCLSID clsidDMO
, REFGUID guidCategory
)
264 GUIDToString(szguid
, clsidDMO
);
266 TRACE("%s %p\n", debugstr_w(szguid
), guidCategory
);
268 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, KEY_WRITE
, &hrkey
);
269 if (ERROR_SUCCESS
!= hres
)
272 hres
= RegDeleteKeyW(hrkey
, szguid
);
273 if (ERROR_SUCCESS
!= hres
)
276 hres
= RegOpenKeyExW(hrkey
, szDMOCategories
, 0, KEY_WRITE
, &hckey
);
277 if (ERROR_SUCCESS
!= hres
)
280 hres
= RegDeleteKeyW(hckey
, szguid
);
281 if (ERROR_SUCCESS
!= hres
)
294 /***************************************************************
295 * DMOGetName (MSDMO.@)
297 * Get DMP Name from the registry
299 HRESULT WINAPI
DMOGetName(REFCLSID clsidDMO
, WCHAR szName
[])
305 static const INT max_name_len
= 80;
308 TRACE("%s\n", debugstr_guid(clsidDMO
));
310 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
,
311 0, KEY_READ
, &hrkey
);
312 if (ERROR_SUCCESS
!= hres
)
315 hres
= RegOpenKeyExW(hrkey
, GUIDToString(szguid
, clsidDMO
),
317 if (ERROR_SUCCESS
!= hres
)
320 count
= max_name_len
* sizeof(WCHAR
);
321 hres
= RegQueryValueExW(hkey
, NULL
, NULL
, NULL
,
322 (LPBYTE
) szName
, &count
);
324 TRACE(" szName=%s\n", debugstr_w(szName
));
335 /**************************************************************************
336 * IEnumDMOImpl_Destructor
338 static BOOL
IEnumDMOImpl_Destructor(IEnumDMOImpl
* This
)
343 RegCloseKey(This
->hkey
);
345 HeapFree(GetProcessHeap(), 0, This
->pInTypes
);
346 HeapFree(GetProcessHeap(), 0, This
->pOutTypes
);
352 /**************************************************************************
353 * IEnumDMO_Constructor
355 static HRESULT
IEnumDMO_Constructor(
356 REFGUID guidCategory
,
359 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
361 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
,
364 IEnumDMOImpl
* lpedmo
;
370 lpedmo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumDMOImpl
));
372 return E_OUTOFMEMORY
;
374 lpedmo
->IEnumDMO_iface
.lpVtbl
= &edmovt
;
377 lpedmo
->guidCategory
= guidCategory
;
378 lpedmo
->dwFlags
= dwFlags
;
382 size
= cInTypes
* sizeof(DMO_PARTIAL_MEDIATYPE
);
383 lpedmo
->pInTypes
= HeapAlloc(GetProcessHeap(), 0, size
);
384 if (!lpedmo
->pInTypes
)
389 memcpy(lpedmo
->pInTypes
, pInTypes
, size
);
390 lpedmo
->cInTypes
= cInTypes
;
395 size
= cOutTypes
* sizeof(DMO_PARTIAL_MEDIATYPE
);
396 lpedmo
->pOutTypes
= HeapAlloc(GetProcessHeap(), 0, size
);
397 if (!lpedmo
->pOutTypes
)
402 memcpy(lpedmo
->pOutTypes
, pOutTypes
, size
);
403 lpedmo
->cOutTypes
= cOutTypes
;
406 /* If not filtering by category enum from media objects root */
407 if (IsEqualGUID(guidCategory
, &GUID_NULL
))
409 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0, KEY_READ
, &lpedmo
->hkey
))
415 WCHAR szKey
[MAX_PATH
];
417 wsprintfW(szKey
, szCat3Fmt
, szDMORootKey
, szDMOCategories
,
418 GUIDToString(szguid
, guidCategory
));
419 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &lpedmo
->hkey
))
427 IEnumDMOImpl_Destructor(lpedmo
);
428 HeapFree(GetProcessHeap(), 0, lpedmo
);
432 TRACE("returning %p\n", lpedmo
);
433 *obj
= &lpedmo
->IEnumDMO_iface
;
439 /******************************************************************************
442 static ULONG WINAPI
IEnumDMO_fnAddRef(IEnumDMO
* iface
)
444 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
445 ULONG refCount
= InterlockedIncrement(&This
->ref
);
446 TRACE("(%p)->(%d)\n", This
, refCount
);
450 /**************************************************************************
451 * EnumDMO_QueryInterface
453 static HRESULT WINAPI
IEnumDMO_fnQueryInterface(IEnumDMO
* iface
, REFIID riid
, void **ppvObj
)
455 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
457 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObj
);
461 if (IsEqualIID(riid
, &IID_IEnumDMO
) ||
462 IsEqualIID(riid
, &IID_IUnknown
))
465 IEnumDMO_fnAddRef(iface
);
468 return *ppvObj
? S_OK
: E_NOINTERFACE
;
471 /******************************************************************************
474 static ULONG WINAPI
IEnumDMO_fnRelease(IEnumDMO
* iface
)
476 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
477 ULONG refCount
= InterlockedDecrement(&This
->ref
);
479 TRACE("(%p)->(%d)\n", This
, refCount
);
483 IEnumDMOImpl_Destructor(This
);
484 HeapFree(GetProcessHeap(),0,This
);
490 /******************************************************************************
493 static HRESULT WINAPI
IEnumDMO_fnNext(
498 DWORD
* pcItemsFetched
)
502 WCHAR szNextKey
[MAX_PATH
];
504 WCHAR szKey
[MAX_PATH
];
505 WCHAR szValue
[MAX_PATH
];
510 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
512 TRACE("(%p)->(%d %p %p %p)\n", This
, cItemsToFetch
, pCLSID
, Names
, pcItemsFetched
);
514 if (!pCLSID
|| !Names
|| !pcItemsFetched
)
517 while (count
< cItemsToFetch
)
522 hres
= RegEnumKeyExW(This
->hkey
, This
->index
, szNextKey
, &len
, NULL
, NULL
, NULL
, &ft
);
523 if (hres
!= ERROR_SUCCESS
)
526 TRACE("found %s\n", debugstr_w(szNextKey
));
528 if (!(This
->dwFlags
& DMO_ENUMF_INCLUDE_KEYED
))
530 wsprintfW(szKey
, szCat3Fmt
, szDMORootKey
, szNextKey
, szDMOKeyed
);
531 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &hkey
);
532 if (ERROR_SUCCESS
== hres
)
535 /* Skip Keyed entries */
540 wsprintfW(szKey
, szCat2Fmt
, szDMORootKey
, szNextKey
);
541 hres
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szKey
, 0, KEY_READ
, &hkey
);
547 DMO_PARTIAL_MEDIATYPE
* pInTypes
;
549 hres
= read_types(hkey
, szDMOInputType
, &cInTypes
,
550 sizeof(szValue
)/sizeof(DMO_PARTIAL_MEDIATYPE
),
551 (DMO_PARTIAL_MEDIATYPE
*)szValue
);
553 if (ERROR_SUCCESS
!= hres
)
559 pInTypes
= (DMO_PARTIAL_MEDIATYPE
*) szValue
;
561 for (i
= 0; i
< This
->cInTypes
; i
++)
563 for (j
= 0; j
< cInTypes
; j
++)
565 if (IsMediaTypeEqual(&pInTypes
[j
], &This
->pInTypes
[i
]))
573 if (i
< This
->cInTypes
)
584 DMO_PARTIAL_MEDIATYPE
* pOutTypes
;
586 hres
= read_types(hkey
, szDMOOutputType
, &cOutTypes
,
587 sizeof(szValue
)/sizeof(DMO_PARTIAL_MEDIATYPE
),
588 (DMO_PARTIAL_MEDIATYPE
*)szValue
);
590 if (ERROR_SUCCESS
!= hres
)
596 pOutTypes
= (DMO_PARTIAL_MEDIATYPE
*) szValue
;
598 for (i
= 0; i
< This
->cOutTypes
; i
++)
600 for (j
= 0; j
< cOutTypes
; j
++)
602 if (IsMediaTypeEqual(&pOutTypes
[j
], &This
->pOutTypes
[i
]))
610 if (i
< This
->cOutTypes
)
617 /* Media object wasn't filtered so add it to return list */
619 len
= MAX_PATH
* sizeof(WCHAR
);
620 hres
= RegQueryValueExW(hkey
, NULL
, NULL
, NULL
, (LPBYTE
) szValue
, &len
);
621 if (ERROR_SUCCESS
== hres
)
623 Names
[count
] = HeapAlloc(GetProcessHeap(), 0, (strlenW(szValue
) + 1) * sizeof(WCHAR
));
625 strcpyW(Names
[count
], szValue
);
627 wsprintfW(szGuidKey
,szToGuidFmt
,szNextKey
);
628 CLSIDFromString(szGuidKey
, &pCLSID
[count
]);
630 TRACE("found match %s %s\n", debugstr_w(szValue
), debugstr_w(szNextKey
));
635 *pcItemsFetched
= count
;
636 if (*pcItemsFetched
< cItemsToFetch
)
639 TRACE("<-- %i found\n",count
);
644 /******************************************************************************
647 static HRESULT WINAPI
IEnumDMO_fnSkip(IEnumDMO
* iface
, DWORD cItemsToSkip
)
649 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
651 TRACE("(%p)->(%d)\n", This
, cItemsToSkip
);
652 This
->index
+= cItemsToSkip
;
658 /******************************************************************************
661 static HRESULT WINAPI
IEnumDMO_fnReset(IEnumDMO
* iface
)
663 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
665 TRACE("(%p)\n", This
);
672 /******************************************************************************
675 static HRESULT WINAPI
IEnumDMO_fnClone(IEnumDMO
*iface
, IEnumDMO
**ppEnum
)
677 IEnumDMOImpl
*This
= impl_from_IEnumDMO(iface
);
678 TRACE("(%p)->(%p)\n", This
, ppEnum
);
679 return IEnumDMO_Constructor(This
->guidCategory
, This
->dwFlags
, This
->cInTypes
, This
->pInTypes
,
680 This
->cOutTypes
, This
->pOutTypes
, ppEnum
);
684 /***************************************************************
687 * Enumerate DirectX Media Objects in the registry.
689 HRESULT WINAPI
DMOEnum(
690 REFGUID guidCategory
,
693 const DMO_PARTIAL_MEDIATYPE
*pInTypes
,
695 const DMO_PARTIAL_MEDIATYPE
*pOutTypes
,
698 TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n",
699 guidCategory
, dwFlags
, cInTypes
, cOutTypes
);
701 return IEnumDMO_Constructor(guidCategory
, dwFlags
, cInTypes
,
702 pInTypes
, cOutTypes
, pOutTypes
, ppEnum
);
706 static const IEnumDMOVtbl edmovt
=
708 IEnumDMO_fnQueryInterface
,
718 HRESULT
read_types(HKEY root
, LPCWSTR key
, ULONG
*supplied
, ULONG requested
, DMO_PARTIAL_MEDIATYPE
* types
)
721 if (MSDMO_MAJOR_VERSION
> 5)
724 len
= requested
* sizeof(DMO_PARTIAL_MEDIATYPE
);
725 ret
= RegQueryValueExW(root
, key
, NULL
, NULL
, (LPBYTE
) types
, &len
);
726 *supplied
= len
/ sizeof(DMO_PARTIAL_MEDIATYPE
);
734 if (ERROR_SUCCESS
== RegOpenKeyExW(root
, key
, 0, KEY_READ
, &hkey
))
737 WCHAR szNextKey
[MAX_PATH
];
739 LONG rc
= ERROR_SUCCESS
;
741 while (rc
== ERROR_SUCCESS
)
744 rc
= RegEnumKeyExW(hkey
, index
, szNextKey
, &len
, NULL
, NULL
, NULL
, NULL
);
745 if (rc
== ERROR_SUCCESS
)
749 LONG rcs
= ERROR_SUCCESS
;
750 WCHAR szSubKey
[MAX_PATH
];
752 RegOpenKeyExW(hkey
, szNextKey
, 0, KEY_READ
, &subk
);
753 while (rcs
== ERROR_SUCCESS
)
756 rcs
= RegEnumKeyExW(subk
, sub_index
, szSubKey
, &len
, NULL
, NULL
, NULL
, NULL
);
757 if (rcs
== ERROR_SUCCESS
)
759 if (*supplied
>= requested
)
763 rc
= ERROR_MORE_DATA
;
764 rcs
= ERROR_MORE_DATA
;
768 wsprintfW(szGuidKey
,szToGuidFmt
,szNextKey
);
769 CLSIDFromString(szGuidKey
, &types
[*supplied
].type
);
770 wsprintfW(szGuidKey
,szToGuidFmt
,szSubKey
);
771 CLSIDFromString(szGuidKey
, &types
[*supplied
].subtype
);
772 TRACE("Adding type %s subtype %s at index %i\n",
773 debugstr_guid(&types
[*supplied
].type
),
774 debugstr_guid(&types
[*supplied
].subtype
),
789 /***************************************************************
790 * DMOGetTypes (MSDMO.@)
792 HRESULT WINAPI
DMOGetTypes(REFCLSID clsidDMO
,
793 ULONG ulInputTypesRequested
,
794 ULONG
* pulInputTypesSupplied
,
795 DMO_PARTIAL_MEDIATYPE
* pInputTypes
,
796 ULONG ulOutputTypesRequested
,
797 ULONG
* pulOutputTypesSupplied
,
798 DMO_PARTIAL_MEDIATYPE
* pOutputTypes
)
804 TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO
), ulInputTypesRequested
,
805 pulInputTypesSupplied
, pInputTypes
, ulOutputTypesRequested
, pulOutputTypesSupplied
,
808 if (ERROR_SUCCESS
!= RegOpenKeyExW(HKEY_CLASSES_ROOT
, szDMORootKey
, 0,
812 if (ERROR_SUCCESS
!= RegOpenKeyExW(root
,GUIDToString(szguid
,clsidDMO
) , 0,
819 if (ulInputTypesRequested
> 0)
821 ret
= read_types(hkey
, szDMOInputType
, pulInputTypesSupplied
, ulInputTypesRequested
, pInputTypes
);
824 *pulInputTypesSupplied
= 0;
826 if (ulOutputTypesRequested
> 0)
829 ret2
= read_types(hkey
, szDMOOutputType
, pulOutputTypesSupplied
, ulOutputTypesRequested
, pOutputTypes
);
835 *pulOutputTypesSupplied
= 0;