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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #define COM_NO_WINDOWS_H
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
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
85 const GUID* guidCategory;
88 DMO_PARTIAL_MEDIATYPE *pInTypes;
90 DMO_PARTIAL_MEDIATYPE *pOutTypes;
94 const GUID IID_IEnumDMO = { 0x2c3cd98a, 0x2bfa, 0x4a53,
95 { 0x9c, 0x27, 0x52, 0x49, 0xba, 0x64, 0xba, 0x0f}};
97 static struct IEnumDMOVtbl edmovt;
99 static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid)
101 wsprintfW(lpwstr, szGUIDFmt, lpcguid->Data1, lpcguid->Data2,
102 lpcguid->Data3, lpcguid->Data4[0], lpcguid->Data4[1],
103 lpcguid->Data4[2], lpcguid->Data4[3], lpcguid->Data4[4],
104 lpcguid->Data4[5], lpcguid->Data4[6], lpcguid->Data4[7]);
109 static BOOL IsMediaTypeEqual(DMO_PARTIAL_MEDIATYPE* mt1, DMO_PARTIAL_MEDIATYPE* mt2)
112 return (IsEqualCLSID(&mt1->type, &mt2->type) ||
113 IsEqualCLSID(&mt2->type, &GUID_NULL) ||
114 IsEqualCLSID(&mt1->type, &GUID_NULL)) &&
115 (IsEqualCLSID(&mt1->subtype, &mt2->subtype) ||
116 IsEqualCLSID(&mt2->subtype, &GUID_NULL) ||
117 IsEqualCLSID(&mt1->subtype, &GUID_NULL));
120 /***************************************************************
123 * Register a DirectX Media Object.
125 HRESULT WINAPI DMORegister(
128 REFGUID guidCategory,
131 const DMO_PARTIAL_MEDIATYPE *pInTypes,
133 const DMO_PARTIAL_MEDIATYPE *pOutTypes
143 TRACE("%s\n", debugstr_w(szName));
145 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey);
146 if (ERROR_SUCCESS != hres)
149 /* Create clsidDMO key under MediaObjects */
150 hres = RegCreateKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, NULL,
151 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
152 if (ERROR_SUCCESS != hres)
155 /* Set default Name value */
156 hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
157 (strlenW(szName) + 1)) * sizeof(WCHAR);
159 hres = RegSetValueExW(hkey, szDMOInputType, 0, REG_BINARY,
160 (const BYTE*) pInTypes, cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE));
161 /* Set OutputTypes */
162 hres = RegSetValueExW(hkey, szDMOOutputType, 0, REG_BINARY,
163 (const BYTE*) pOutTypes, cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE));
165 if (dwFlags & DMO_REGISTERF_IS_KEYED)
167 /* Create Keyed key */
168 hres = RegCreateKeyExW(hkey, szDMOKeyed, 0, NULL,
169 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
170 if (ERROR_SUCCESS != hres)
175 /* Register the category */
176 hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey);
177 if (ERROR_SUCCESS != hres)
182 hres = RegOpenKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, KEY_WRITE, &hkey);
183 if (ERROR_SUCCESS != hres)
185 hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
186 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hclskey, NULL);
187 if (ERROR_SUCCESS != hres)
196 RegCloseKey(hclskey);
200 TRACE(" hresult=0x%08lx\n", hres);
205 /***************************************************************
208 * Unregister a DirectX Media Object.
210 HRESULT WINAPI DMOUnregister(REFCLSID clsidDMO, REFGUID guidCategory)
217 GUIDToString(szguid, clsidDMO);
219 TRACE("%s %p\n", debugstr_w(szguid), guidCategory);
221 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey);
222 if (ERROR_SUCCESS != hres)
225 hres = RegDeleteKeyW(hrkey, szguid);
226 if (ERROR_SUCCESS != hres)
229 hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey);
230 if (ERROR_SUCCESS != hres)
233 hres = RegDeleteKeyW(hckey, szguid);
234 if (ERROR_SUCCESS != hres)
247 /***************************************************************
250 * Get DMP Name from the registry
252 HRESULT WINAPI DMOGetName(REFCLSID clsidDMO, WCHAR* szName)
260 TRACE("%s\n", debugstr_guid(clsidDMO));
262 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
263 0, KEY_READ, &hrkey);
264 if (ERROR_SUCCESS != hres)
267 hres = RegOpenKeyExW(hrkey, GUIDToString(szguid, clsidDMO),
269 if (ERROR_SUCCESS != hres)
272 count = 80 * sizeof(WCHAR); /* 80 by API definition */
273 hres = RegQueryValueExW(hkey, NULL, NULL, NULL,
274 (LPBYTE) szName, &count);
276 TRACE(" szName=%s\n", debugstr_w(szName));
287 /**************************************************************************
288 * IEnumDMO_Destructor
290 static BOOL IEnumDMO_Destructor(IEnumDMO* iface)
292 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
297 RegCloseKey(This->hkey);
299 HeapFree(GetProcessHeap(), 0, This->pInTypes);
300 HeapFree(GetProcessHeap(), 0, This->pOutTypes);
306 /**************************************************************************
307 * IEnumDMO_Constructor
309 IEnumDMO * IEnumDMO_Constructor(
310 REFGUID guidCategory,
313 const DMO_PARTIAL_MEDIATYPE *pInTypes,
315 const DMO_PARTIAL_MEDIATYPE *pOutTypes)
318 IEnumDMOImpl* lpedmo;
321 lpedmo = (IEnumDMOImpl*)HeapAlloc(GetProcessHeap(),
322 HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
327 lpedmo->lpVtbl = &edmovt;
329 lpedmo->guidCategory = guidCategory;
330 lpedmo->dwFlags = dwFlags;
332 size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
333 lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size);
334 if (!lpedmo->pInTypes)
336 memcpy(lpedmo->pInTypes, pInTypes, size);
337 lpedmo->cInTypes = cInTypes;
339 size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
340 lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size);
341 if (!lpedmo->pOutTypes)
343 memcpy(lpedmo->pOutTypes, pOutTypes, size);
344 lpedmo->cOutTypes = cOutTypes;
346 /* If not filtering by category enum from media objects root */
347 if (IsEqualGUID(guidCategory, &GUID_NULL))
349 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
350 0, KEY_READ, &lpedmo->hkey))
356 WCHAR szKey[MAX_PATH];
358 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories,
359 GUIDToString(szguid, guidCategory));
360 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey,
361 0, KEY_READ, &lpedmo->hkey))
368 IEnumDMO_Destructor((IEnumDMO*)lpedmo);
369 HeapFree(GetProcessHeap(),0,lpedmo);
374 TRACE("returning %p\n", lpedmo);
376 return (IEnumDMO*)lpedmo;
380 /******************************************************************************
383 static ULONG WINAPI IEnumDMO_fnAddRef(IEnumDMO * iface)
385 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
386 return InterlockedIncrement(&This->ref);
390 /**************************************************************************
391 * EnumDMO_QueryInterface
393 static HRESULT WINAPI IEnumDMO_fnQueryInterface(
398 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
402 if(IsEqualIID(riid, &IID_IUnknown))
404 else if(IsEqualIID(riid, &IID_IEnumDMO))
405 *ppvObj = (IEnumDMO*)This;
409 IEnumDMO_fnAddRef((IEnumDMO*)*ppvObj);
413 return E_NOINTERFACE;
417 /******************************************************************************
420 static ULONG WINAPI IEnumDMO_fnRelease(IEnumDMO * iface)
422 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
423 ULONG refCount = InterlockedDecrement(&This->ref);
427 IEnumDMO_Destructor((IEnumDMO*)This);
428 HeapFree(GetProcessHeap(),0,This);
434 /******************************************************************************
437 static HRESULT WINAPI IEnumDMO_fnNext(
442 DWORD * pcItemsFetched)
446 WCHAR szNextKey[MAX_PATH];
447 WCHAR szKey[MAX_PATH];
448 WCHAR szValue[MAX_PATH];
453 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
455 TRACE("%ld\n", cItemsToFetch);
457 if (!pCLSID || !Names || !pcItemsFetched)
460 while (count < cItemsToFetch)
464 hres = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, &ft);
465 if (hres != ERROR_SUCCESS)
468 TRACE("found %s\n", debugstr_w(szNextKey));
470 if (This->dwFlags & DMO_REGISTERF_IS_KEYED)
472 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed);
473 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
474 if (ERROR_SUCCESS != hres)
479 wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey);
480 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
486 DMO_PARTIAL_MEDIATYPE* pInTypes;
488 len = MAX_PATH * sizeof(WCHAR);
489 hres = RegQueryValueExW(hkey, szDMOInputType, NULL, NULL, (LPBYTE) szValue, &len);
490 if (ERROR_SUCCESS != hres)
496 cInTypes = len / sizeof(DMO_PARTIAL_MEDIATYPE);
497 pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
499 for (i = 0; i < This->cInTypes; i++)
501 for (j = 0; j < cInTypes; j++)
503 if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i]))
511 if (i < This->cInTypes)
522 DMO_PARTIAL_MEDIATYPE* pOutTypes;
524 len = MAX_PATH * sizeof(WCHAR);
525 hres = RegQueryValueExW(hkey, szDMOOutputType, NULL, NULL, (LPBYTE) szValue, &len);
526 if (ERROR_SUCCESS != hres)
532 cOutTypes = len / sizeof(DMO_PARTIAL_MEDIATYPE);
533 pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
535 for (i = 0; i < This->cOutTypes; i++)
537 for (j = 0; j < cOutTypes; j++)
539 if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i]))
547 if (i < This->cOutTypes)
554 /* Media object wasn't filtered so add it to return list */
556 len = MAX_PATH * sizeof(WCHAR);
557 hres = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE) szValue, &len);
558 if (ERROR_SUCCESS == hres)
560 Names[count] = HeapAlloc(GetProcessHeap(), 0, strlenW(szValue) + 1);
562 strcmpW(Names[count], szValue);
564 CLSIDFromString(szNextKey, &pCLSID[count]);
566 TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey));
571 *pcItemsFetched = count;
572 if (*pcItemsFetched < cItemsToFetch)
579 /******************************************************************************
582 static HRESULT WINAPI IEnumDMO_fnSkip(IEnumDMO * iface, DWORD cItemsToSkip)
584 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
586 This->index += cItemsToSkip;
592 /******************************************************************************
595 static HRESULT WINAPI IEnumDMO_fnReset(IEnumDMO * iface)
597 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
605 /******************************************************************************
608 static HRESULT WINAPI IEnumDMO_fnClone(IEnumDMO * iface, IEnumDMO **ppEnum)
610 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
612 FIXME("(%p)->() to (%p)->() E_NOTIMPL\n", This, ppEnum);
618 /***************************************************************
621 * Enumerate DirectX Media Objects in the registry.
623 HRESULT WINAPI DMOEnum(
624 REFGUID guidCategory,
627 const DMO_PARTIAL_MEDIATYPE *pInTypes,
629 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
632 HRESULT hres = E_FAIL;
634 TRACE("guidCategory=%p dwFlags=0x%08lx cInTypes=%ld cOutTypes=%ld\n",
635 guidCategory, dwFlags, cInTypes, cOutTypes);
637 *ppEnum = IEnumDMO_Constructor(guidCategory, dwFlags, cInTypes,
638 pInTypes, cOutTypes, pOutTypes);
646 static IEnumDMOVtbl edmovt =
648 IEnumDMO_fnQueryInterface,
658 HRESULT WINAPI DMOGetTypes(REFCLSID a, unsigned long b, unsigned long* c,
659 DMO_PARTIAL_MEDIATYPE* d, unsigned long e,
660 unsigned long* f, DMO_PARTIAL_MEDIATYPE* g)
662 FIXME("(%p,%lu,%p,%p,%lu,%p,%p),stub!\n",a,b,c,d,e,f,g);