msdmo: Improve registration and reading of codecs.

This commit is contained in:
Aric Stewart 2007-10-10 10:13:49 -05:00 committed by Alexandre Julliard
parent c632a7500f
commit 352d29b194
1 changed files with 132 additions and 75 deletions

View File

@ -32,6 +32,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(msdmo); WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
#define MSDMO_MAJOR_VERSION 6
static const WCHAR szDMORootKey[] = static const WCHAR szDMORootKey[] =
{ {
@ -96,6 +97,8 @@ typedef struct
HKEY hkey; HKEY hkey;
} IEnumDMOImpl; } IEnumDMOImpl;
static HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types);
static const IEnumDMOVtbl edmovt; static const IEnumDMOVtbl edmovt;
static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid) static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid)
@ -119,6 +122,40 @@ static BOOL IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE* mt1, const DMO_PARTIAL
IsEqualCLSID(&mt1->subtype, &GUID_NULL)); IsEqualCLSID(&mt1->subtype, &GUID_NULL));
} }
static HRESULT write_types(HKEY hkey, LPCWSTR name, const DMO_PARTIAL_MEDIATYPE* types, DWORD count)
{
HRESULT hres = S_OK;
if (MSDMO_MAJOR_VERSION > 5)
{
hres = RegSetValueExW(hkey, name, 0, REG_BINARY, (const BYTE*) types,
count* sizeof(DMO_PARTIAL_MEDIATYPE));
}
else
{
HKEY skey1,skey2,skey3;
DWORD index = 0;
WCHAR szGuidKey[64];
hres = RegCreateKeyExW(hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &skey1, NULL);
while (index < count)
{
GUIDToString(szGuidKey,&types[index].type);
hres = RegCreateKeyExW(skey1, szGuidKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey2, NULL);
GUIDToString(szGuidKey,&types[index].subtype);
hres = RegCreateKeyExW(skey2, szGuidKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey3, NULL);
RegCloseKey(skey3);
RegCloseKey(skey2);
index ++;
}
RegCloseKey(skey1);
}
return hres;
}
/*************************************************************** /***************************************************************
* DMORegister * DMORegister
* *
@ -144,7 +181,8 @@ HRESULT WINAPI DMORegister(
TRACE("%s\n", debugstr_w(szName)); TRACE("%s\n", debugstr_w(szName));
hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey); hres = RegCreateKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hrkey, NULL);
if (ERROR_SUCCESS != hres) if (ERROR_SUCCESS != hres)
goto lend; goto lend;
@ -156,13 +194,13 @@ HRESULT WINAPI DMORegister(
/* Set default Name value */ /* Set default Name value */
hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName, hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
(strlenW(szName) + 1)) * sizeof(WCHAR); (strlenW(szName) + 1) * sizeof(WCHAR));
/* Set InputTypes */ /* Set InputTypes */
hres = RegSetValueExW(hkey, szDMOInputType, 0, REG_BINARY, hres = write_types(hkey, szDMOInputType, pInTypes, cInTypes);
(const BYTE*) pInTypes, cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE));
/* Set OutputTypes */ /* Set OutputTypes */
hres = RegSetValueExW(hkey, szDMOOutputType, 0, REG_BINARY, hres = write_types(hkey, szDMOOutputType, pOutTypes, cOutTypes);
(const BYTE*) pOutTypes, cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE));
if (dwFlags & DMO_REGISTERF_IS_KEYED) if (dwFlags & DMO_REGISTERF_IS_KEYED)
{ {
@ -175,13 +213,15 @@ HRESULT WINAPI DMORegister(
} }
/* Register the category */ /* Register the category */
hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey); hres = RegCreateKeyExW(hrkey, szDMOCategories, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
if (ERROR_SUCCESS != hres) if (ERROR_SUCCESS != hres)
goto lend; goto lend;
RegCloseKey(hkey); RegCloseKey(hkey);
hres = RegOpenKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, KEY_WRITE, &hkey); hres = RegCreateKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
if (ERROR_SUCCESS != hres) if (ERROR_SUCCESS != hres)
goto lend; goto lend;
hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL, hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
@ -330,19 +370,25 @@ static IEnumDMO * IEnumDMO_Constructor(
lpedmo->guidCategory = guidCategory; lpedmo->guidCategory = guidCategory;
lpedmo->dwFlags = dwFlags; lpedmo->dwFlags = dwFlags;
size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE); if (cInTypes > 0)
lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size); {
if (!lpedmo->pInTypes) size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
goto lerr; lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size);
memcpy(lpedmo->pInTypes, pInTypes, size); if (!lpedmo->pInTypes)
lpedmo->cInTypes = cInTypes; goto lerr;
memcpy(lpedmo->pInTypes, pInTypes, size);
lpedmo->cInTypes = cInTypes;
}
size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE); if (cOutTypes > 0)
lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size); {
if (!lpedmo->pOutTypes) size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
goto lerr; lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size);
memcpy(lpedmo->pOutTypes, pOutTypes, size); if (!lpedmo->pOutTypes)
lpedmo->cOutTypes = cOutTypes; goto lerr;
memcpy(lpedmo->pOutTypes, pOutTypes, size);
lpedmo->cOutTypes = cOutTypes;
}
/* If not filtering by category enum from media objects root */ /* If not filtering by category enum from media objects root */
if (IsEqualGUID(guidCategory, &GUID_NULL)) if (IsEqualGUID(guidCategory, &GUID_NULL))
@ -487,15 +533,16 @@ static HRESULT WINAPI IEnumDMO_fnNext(
DWORD cInTypes; DWORD cInTypes;
DMO_PARTIAL_MEDIATYPE* pInTypes; DMO_PARTIAL_MEDIATYPE* pInTypes;
len = MAX_PATH * sizeof(WCHAR); hres = read_types(hkey, szDMOInputType, &cInTypes,
hres = RegQueryValueExW(hkey, szDMOInputType, NULL, NULL, (LPBYTE) szValue, &len); sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
if (ERROR_SUCCESS != hres) (DMO_PARTIAL_MEDIATYPE*)szValue);
if (ERROR_SUCCESS != hres)
{ {
RegCloseKey(hkey); RegCloseKey(hkey);
continue; continue;
} }
cInTypes = len / sizeof(DMO_PARTIAL_MEDIATYPE);
pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue; pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
for (i = 0; i < This->cInTypes; i++) for (i = 0; i < This->cInTypes; i++)
@ -523,15 +570,16 @@ static HRESULT WINAPI IEnumDMO_fnNext(
DWORD cOutTypes; DWORD cOutTypes;
DMO_PARTIAL_MEDIATYPE* pOutTypes; DMO_PARTIAL_MEDIATYPE* pOutTypes;
len = MAX_PATH * sizeof(WCHAR); hres = read_types(hkey, szDMOOutputType, &cOutTypes,
hres = RegQueryValueExW(hkey, szDMOOutputType, NULL, NULL, (LPBYTE) szValue, &len); sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
(DMO_PARTIAL_MEDIATYPE*)szValue);
if (ERROR_SUCCESS != hres) if (ERROR_SUCCESS != hres)
{ {
RegCloseKey(hkey); RegCloseKey(hkey);
continue; continue;
} }
cOutTypes = len / sizeof(DMO_PARTIAL_MEDIATYPE);
pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue; pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
for (i = 0; i < This->cOutTypes; i++) for (i = 0; i < This->cOutTypes; i++)
@ -659,64 +707,73 @@ static const IEnumDMOVtbl edmovt =
}; };
HRESULT build_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types ) HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types )
{ {
HRESULT ret = S_OK; HRESULT ret = S_OK;
HKEY hkey; if (MSDMO_MAJOR_VERSION > 5)
WCHAR szGuidKey[64];
*supplied = 0;
if (ERROR_SUCCESS == RegOpenKeyExW(root, key, 0, KEY_READ, &hkey))
{ {
int index = 0; DWORD len;
WCHAR szNextKey[MAX_PATH]; len = requested * sizeof(DMO_PARTIAL_MEDIATYPE);
DWORD len; ret = RegQueryValueExW(root, key, NULL, NULL, (LPBYTE) types, &len);
LONG rc = ERROR_SUCCESS; *supplied = len / sizeof(DMO_PARTIAL_MEDIATYPE);
}
else
{
HKEY hkey;
WCHAR szGuidKey[64];
len = MAX_PATH; *supplied = 0;
while (rc == ERROR_SUCCESS) if (ERROR_SUCCESS == RegOpenKeyExW(root, key, 0, KEY_READ, &hkey))
{
len = MAX_PATH;
rc = RegEnumKeyExW(hkey, index, szNextKey, &len, NULL, NULL, NULL, NULL);
if (rc == ERROR_SUCCESS)
{ {
HKEY subk; int index = 0;
int sub_index = 0; WCHAR szNextKey[MAX_PATH];
LONG rcs = ERROR_SUCCESS; DWORD len;
WCHAR szSubKey[MAX_PATH]; LONG rc = ERROR_SUCCESS;
RegOpenKeyExW(hkey, szNextKey, 0, KEY_READ, &subk); while (rc == ERROR_SUCCESS)
while (rcs == ERROR_SUCCESS)
{ {
len = MAX_PATH; len = MAX_PATH * sizeof(WCHAR);
rcs = RegEnumKeyExW(subk, sub_index, szSubKey, &len, NULL, NULL, NULL, NULL); rc = RegEnumKeyExW(hkey, index, szNextKey, &len, NULL, NULL, NULL, NULL);
if (rcs == ERROR_SUCCESS) if (rc == ERROR_SUCCESS)
{ {
if (*supplied >= requested) HKEY subk;
{ int sub_index = 0;
/* Bailing */ LONG rcs = ERROR_SUCCESS;
ret = S_FALSE; WCHAR szSubKey[MAX_PATH];
rc = ERROR_MORE_DATA;
rcs = ERROR_MORE_DATA;
break;
}
wsprintfW(szGuidKey,szToGuidFmt,szNextKey); RegOpenKeyExW(hkey, szNextKey, 0, KEY_READ, &subk);
CLSIDFromString(szGuidKey, &types[*supplied].type); while (rcs == ERROR_SUCCESS)
wsprintfW(szGuidKey,szToGuidFmt,szSubKey); {
CLSIDFromString(szGuidKey, &types[*supplied].subtype); len = MAX_PATH * sizeof(WCHAR);
TRACE("Adding type %s subtype %s at index %i\n", rcs = RegEnumKeyExW(subk, sub_index, szSubKey, &len, NULL, NULL, NULL, NULL);
debugstr_guid(&types[*supplied].type), if (rcs == ERROR_SUCCESS)
debugstr_guid(&types[*supplied].subtype), {
*supplied); if (*supplied >= requested)
(*supplied)++; {
/* Bailing */
ret = S_FALSE;
rc = ERROR_MORE_DATA;
rcs = ERROR_MORE_DATA;
break;
}
wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
CLSIDFromString(szGuidKey, &types[*supplied].type);
wsprintfW(szGuidKey,szToGuidFmt,szSubKey);
CLSIDFromString(szGuidKey, &types[*supplied].subtype);
TRACE("Adding type %s subtype %s at index %i\n",
debugstr_guid(&types[*supplied].type),
debugstr_guid(&types[*supplied].subtype),
*supplied);
(*supplied)++;
}
sub_index++;
}
index++;
} }
sub_index++;
} }
index++; RegCloseKey(hkey);
} }
}
RegCloseKey(hkey);
} }
return ret; return ret;
} }
@ -751,7 +808,7 @@ HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO,
if (ulInputTypesRequested > 0) if (ulInputTypesRequested > 0)
{ {
ret = build_types(hkey, szDMOInputType, pulInputTypesSupplied, ulInputTypesRequested, pInputTypes ); ret = read_types(hkey, szDMOInputType, pulInputTypesSupplied, ulInputTypesRequested, pInputTypes );
} }
else else
*pulInputTypesSupplied = 0; *pulInputTypesSupplied = 0;
@ -759,7 +816,7 @@ HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO,
if (ulOutputTypesRequested > 0) if (ulOutputTypesRequested > 0)
{ {
HRESULT ret2; HRESULT ret2;
ret2 = build_types(hkey, szDMOOutputType, pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes ); ret2 = read_types(hkey, szDMOOutputType, pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes );
if (ret == S_OK) if (ret == S_OK)
ret = ret2; ret = ret2;