Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/msdmo/tests/msdmo.c | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
diff --git a/dlls/msdmo/tests/msdmo.c b/dlls/msdmo/tests/msdmo.c index 68de11f21ab..14653ea8d75 100644 --- a/dlls/msdmo/tests/msdmo.c +++ b/dlls/msdmo/tests/msdmo.c @@ -117,9 +117,59 @@ static void test_DMOEnum(void) IEnumDMO_Release(enum_dmo); }
+static void test_DMOGetTypes(void) +{ + static const DMO_PARTIAL_MEDIATYPE input_types[] = + { + {{0x1111}, {0x2222}}, + {{0x1111}, {0x3333}}, + }; + ULONG input_count, output_count; + DMO_PARTIAL_MEDIATYPE types[3]; + HRESULT hr; + + hr = DMOGetTypes(&GUID_unknowndmo, 0, &input_count, types, 0, &output_count, NULL); + ok(hr == E_FAIL, "Got hr %#x.\n", hr); + + hr = DMORegister(L"testdmo", &GUID_unknowndmo, &GUID_unknowncategory, 0, + ARRAY_SIZE(input_types), input_types, 0, NULL); + if (hr != S_OK) + return; + + hr = DMOGetTypes(&GUID_unknowndmo, 0, &input_count, types, 0, &output_count, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!input_count, "Got input count %u.\n", input_count); + ok(!output_count, "Got output count %u.\n", output_count); + + memset(types, 0, sizeof(types)); + hr = DMOGetTypes(&GUID_unknowndmo, 1, &input_count, types, 0, &output_count, NULL); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(input_count == 1, "Got input count %u.\n", input_count); + ok(!output_count, "Got output count %u.\n", output_count); + todo_wine ok(!memcmp(types, input_types, sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n"); + + memset(types, 0, sizeof(types)); + hr = DMOGetTypes(&GUID_unknowndmo, 2, &input_count, types, 0, &output_count, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(input_count == 2, "Got input count %u.\n", input_count); + ok(!output_count, "Got output count %u.\n", output_count); + ok(!memcmp(types, input_types, 2 * sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n"); + + memset(types, 0, sizeof(types)); + hr = DMOGetTypes(&GUID_unknowndmo, 2, &input_count, types, 0, &output_count, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(input_count == 2, "Got input count %u.\n", input_count); + ok(!output_count, "Got output count %u.\n", output_count); + ok(!memcmp(types, input_types, 2 * sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n"); + + hr = DMOUnregister(&GUID_unknowndmo, &GUID_unknowncategory); + ok(hr == S_OK, "Got hr %#x.\n", hr); +} + START_TEST(msdmo) { test_DMOUnregister(); test_DMOGetName(); test_DMOEnum(); + test_DMOGetTypes(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/msdmo/dmoreg.c | 92 +++++++++++++++++----------------------- dlls/msdmo/tests/msdmo.c | 2 +- 2 files changed, 39 insertions(+), 55 deletions(-)
diff --git a/dlls/msdmo/dmoreg.c b/dlls/msdmo/dmoreg.c index a23bd95512d..cd253c3e9a2 100644 --- a/dlls/msdmo/dmoreg.c +++ b/dlls/msdmo/dmoreg.c @@ -706,62 +706,46 @@ static const IEnumDMOVtbl edmovt = IEnumDMO_fnClone, };
- -HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types ) -{ - DWORD len = requested * sizeof(DMO_PARTIAL_MEDIATYPE); - LONG ret = RegQueryValueExW(root, key, NULL, NULL, (BYTE *)types, &len); - - *supplied = len / sizeof(DMO_PARTIAL_MEDIATYPE); - return HRESULT_FROM_WIN32(ret); -} - /*************************************************************** * DMOGetTypes (MSDMO.@) */ -HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO, - ULONG ulInputTypesRequested, - ULONG* pulInputTypesSupplied, - DMO_PARTIAL_MEDIATYPE* pInputTypes, - ULONG ulOutputTypesRequested, - ULONG* pulOutputTypesSupplied, - DMO_PARTIAL_MEDIATYPE* pOutputTypes) +HRESULT WINAPI DMOGetTypes(REFCLSID clsid, ULONG input_count, ULONG *ret_input_count, DMO_PARTIAL_MEDIATYPE *input, + ULONG output_count, ULONG *ret_output_count, DMO_PARTIAL_MEDIATYPE *output) { - HKEY root,hkey; - HRESULT ret = S_OK; - WCHAR szguid[64]; - - TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO), ulInputTypesRequested, - pulInputTypesSupplied, pInputTypes, ulOutputTypesRequested, pulOutputTypesSupplied, - pOutputTypes); - - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\MediaObjects", 0, KEY_READ, &root)) - return E_FAIL; - - if (ERROR_SUCCESS != RegOpenKeyExW(root,GUIDToString(szguid,clsidDMO) , 0, - KEY_READ, &hkey)) - { - RegCloseKey(root); - return E_FAIL; - } - - if (ulInputTypesRequested > 0) - { - ret = read_types(hkey, L"InputTypes", pulInputTypesSupplied, ulInputTypesRequested, pInputTypes ); - } - else - *pulInputTypesSupplied = 0; - - if (ulOutputTypesRequested > 0) - { - HRESULT ret2; - ret2 = read_types(hkey, L"OutputTypes", pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes ); - - if (ret == S_OK) - ret = ret2; - } - else - *pulOutputTypesSupplied = 0; - - return ret; + WCHAR guidstr[64]; + HKEY root, key; + LSTATUS ret; + DWORD size; + + TRACE("clsid %s, input_count %u, ret_input_count %p, input %p, output_count %u, ret_output_count %p, output %p.\n", + debugstr_guid(clsid), input_count, ret_input_count, input, output_count, ret_output_count, output); + + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\MediaObjects", 0, KEY_READ, &root)) + return E_FAIL; + + if (RegOpenKeyExW(root, GUIDToString(guidstr, clsid), 0, KEY_READ, &key)) + { + RegCloseKey(root); + return E_FAIL; + } + + *ret_input_count = 0; + if (input_count > 0) + { + size = input_count * sizeof(DMO_PARTIAL_MEDIATYPE); + ret = RegQueryValueExW(key, L"InputTypes", NULL, NULL, (BYTE *)input, &size); + if (!ret || ret == ERROR_MORE_DATA) + *ret_input_count = size / sizeof(DMO_PARTIAL_MEDIATYPE); + } + + *ret_output_count = 0; + if (output_count > 0) + { + size = output_count * sizeof(DMO_PARTIAL_MEDIATYPE); + ret = RegQueryValueExW(key, L"OutputTypes", NULL, NULL, (BYTE *)output, &size); + if (!ret || ret == ERROR_MORE_DATA) + *ret_output_count = size / sizeof(DMO_PARTIAL_MEDIATYPE); + } + + return S_OK; } diff --git a/dlls/msdmo/tests/msdmo.c b/dlls/msdmo/tests/msdmo.c index 14653ea8d75..2afa56e5a6c 100644 --- a/dlls/msdmo/tests/msdmo.c +++ b/dlls/msdmo/tests/msdmo.c @@ -143,7 +143,7 @@ static void test_DMOGetTypes(void)
memset(types, 0, sizeof(types)); hr = DMOGetTypes(&GUID_unknowndmo, 1, &input_count, types, 0, &output_count, NULL); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(hr == S_OK, "Got hr %#x.\n", hr); todo_wine ok(input_count == 1, "Got input count %u.\n", input_count); ok(!output_count, "Got output count %u.\n", output_count); todo_wine ok(!memcmp(types, input_types, sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n");
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/msdmo/dmoreg.c | 22 ++++++++-------------- dlls/msdmo/tests/msdmo.c | 2 +- 2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/dlls/msdmo/dmoreg.c b/dlls/msdmo/dmoreg.c index cd253c3e9a2..8c32a8f59fb 100644 --- a/dlls/msdmo/dmoreg.c +++ b/dlls/msdmo/dmoreg.c @@ -730,22 +730,16 @@ HRESULT WINAPI DMOGetTypes(REFCLSID clsid, ULONG input_count, ULONG *ret_input_c }
*ret_input_count = 0; - if (input_count > 0) - { - size = input_count * sizeof(DMO_PARTIAL_MEDIATYPE); - ret = RegQueryValueExW(key, L"InputTypes", NULL, NULL, (BYTE *)input, &size); - if (!ret || ret == ERROR_MORE_DATA) - *ret_input_count = size / sizeof(DMO_PARTIAL_MEDIATYPE); - } + size = input_count * sizeof(DMO_PARTIAL_MEDIATYPE); + ret = RegQueryValueExW(key, L"InputTypes", NULL, NULL, (BYTE *)input, &size); + if (!ret || ret == ERROR_MORE_DATA) + *ret_input_count = min(input_count, size / sizeof(DMO_PARTIAL_MEDIATYPE));
*ret_output_count = 0; - if (output_count > 0) - { - size = output_count * sizeof(DMO_PARTIAL_MEDIATYPE); - ret = RegQueryValueExW(key, L"OutputTypes", NULL, NULL, (BYTE *)output, &size); - if (!ret || ret == ERROR_MORE_DATA) - *ret_output_count = size / sizeof(DMO_PARTIAL_MEDIATYPE); - } + size = output_count * sizeof(DMO_PARTIAL_MEDIATYPE); + ret = RegQueryValueExW(key, L"OutputTypes", NULL, NULL, (BYTE *)output, &size); + if (!ret || ret == ERROR_MORE_DATA) + *ret_output_count = min(output_count, size / sizeof(DMO_PARTIAL_MEDIATYPE));
return S_OK; } diff --git a/dlls/msdmo/tests/msdmo.c b/dlls/msdmo/tests/msdmo.c index 2afa56e5a6c..a1ab8ee00dc 100644 --- a/dlls/msdmo/tests/msdmo.c +++ b/dlls/msdmo/tests/msdmo.c @@ -144,7 +144,7 @@ static void test_DMOGetTypes(void) memset(types, 0, sizeof(types)); hr = DMOGetTypes(&GUID_unknowndmo, 1, &input_count, types, 0, &output_count, NULL); ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(input_count == 1, "Got input count %u.\n", input_count); + ok(input_count == 1, "Got input count %u.\n", input_count); ok(!output_count, "Got output count %u.\n", output_count); todo_wine ok(!memcmp(types, input_types, sizeof(DMO_PARTIAL_MEDIATYPE)), "Types didn't match.\n");
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/msdmo/dmoreg.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/msdmo/dmoreg.c b/dlls/msdmo/dmoreg.c index 8c32a8f59fb..8e0680931f4 100644 --- a/dlls/msdmo/dmoreg.c +++ b/dlls/msdmo/dmoreg.c @@ -741,5 +741,7 @@ HRESULT WINAPI DMOGetTypes(REFCLSID clsid, ULONG input_count, ULONG *ret_input_c if (!ret || ret == ERROR_MORE_DATA) *ret_output_count = min(output_count, size / sizeof(DMO_PARTIAL_MEDIATYPE));
+ RegCloseKey(key); + RegCloseKey(root); return S_OK; }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- Congratulations, Microsoft, on this well-designed API.
dlls/devenum/mediacatenum.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/dlls/devenum/mediacatenum.c b/dlls/devenum/mediacatenum.c index 16b729ab1fd..ab675b5656f 100644 --- a/dlls/devenum/mediacatenum.c +++ b/dlls/devenum/mediacatenum.c @@ -147,28 +147,27 @@ static HRESULT WINAPI property_bag_Read(IPropertyBag *iface, };
unsigned int count = 1, input_count, output_count, i; - DMO_PARTIAL_MEDIATYPE *types = NULL; + DMO_PARTIAL_MEDIATYPE *types = NULL, *new_array; REGPINTYPES *reg_types; HRESULT hr;
- if (!(types = malloc(2 * count * sizeof(*types)))) - return E_OUTOFMEMORY; - - while ((hr = DMOGetTypes(&moniker->clsid, count, &input_count, types, - count, &output_count, types + count)) == S_FALSE) + do { count *= 2; - if (!(types = realloc(types, count * sizeof(*types)))) + if (!(new_array = realloc(types, 2 * count * sizeof(*types)))) { free(types); return E_OUTOFMEMORY; } - } - if (hr != S_OK) - { - free(types); - return hr; - } + types = new_array; + + if (FAILED(hr = DMOGetTypes(&moniker->clsid, count, &input_count, types, + count, &output_count, types + count))) + { + free(types); + return hr; + } + } while (input_count == count || output_count == count);
if (!(reg_types = malloc(2 * count * sizeof(*reg_types)))) {