Nikolay Sivov : mfplat: Get rid of variant coercion calls.

Alexandre Julliard julliard at winehq.org
Mon Mar 18 16:20:15 CDT 2019


Module: wine
Branch: master
Commit: ced0a1de7e016a4bf10a188c4ebe10365cd8e220
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ced0a1de7e016a4bf10a188c4ebe10365cd8e220

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Mon Mar 18 13:00:57 2019 +0300

mfplat: Get rid of variant coercion calls.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mfplat/main.c         | 72 ++++++++++++++++++++++++++++++++--------------
 dlls/mfplat/tests/mfplat.c |  4 ++-
 2 files changed, 53 insertions(+), 23 deletions(-)

diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c
index 4589840..7481b77 100644
--- a/dlls/mfplat/main.c
+++ b/dlls/mfplat/main.c
@@ -37,6 +37,7 @@
 #include "mfplat_private.h"
 #include "mfreadwrite.h"
 #include "propvarutil.h"
+#include "strsafe.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
 
@@ -857,7 +858,8 @@ static HRESULT WINAPI mfattributes_GetUINT32(IMFAttributes *iface, REFGUID key,
     attrval.vt = VT_UI4;
     hr = attributes_get_item(attributes, key, &attrval);
     if (SUCCEEDED(hr))
-        hr = PropVariantToUInt32(&attrval, value);
+        *value = attrval.u.ulVal;
+
     return hr;
 }
 
@@ -873,7 +875,8 @@ static HRESULT WINAPI mfattributes_GetUINT64(IMFAttributes *iface, REFGUID key,
     attrval.vt = VT_UI8;
     hr = attributes_get_item(attributes, key, &attrval);
     if (SUCCEEDED(hr))
-        hr = PropVariantToUInt64(&attrval, value);
+        *value = attrval.u.uhVal.QuadPart;
+
     return hr;
 }
 
@@ -889,7 +892,8 @@ static HRESULT WINAPI mfattributes_GetDouble(IMFAttributes *iface, REFGUID key,
     attrval.vt = VT_R8;
     hr = attributes_get_item(attributes, key, &attrval);
     if (SUCCEEDED(hr))
-        hr = PropVariantToDouble(&attrval, value);
+        *value = attrval.u.dblVal;
+
     return hr;
 }
 
@@ -905,7 +909,7 @@ static HRESULT WINAPI mfattributes_GetGUID(IMFAttributes *iface, REFGUID key, GU
     attrval.vt = VT_CLSID;
     hr = attributes_get_item(attributes, key, &attrval);
     if (SUCCEEDED(hr))
-        hr = PropVariantToGUID(&attrval, value);
+        *value = *attrval.u.puuid;
 
     return hr;
 }
@@ -913,17 +917,25 @@ static HRESULT WINAPI mfattributes_GetGUID(IMFAttributes *iface, REFGUID key, GU
 static HRESULT WINAPI mfattributes_GetStringLength(IMFAttributes *iface, REFGUID key, UINT32 *length)
 {
     struct attributes *attributes = impl_from_IMFAttributes(iface);
-    PROPVARIANT attrval;
-    HRESULT hr;
+    struct attribute *attribute;
+    HRESULT hr = S_OK;
 
     TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
 
-    PropVariantInit(&attrval);
-    attrval.vt = VT_LPWSTR;
-    hr = attributes_get_item(attributes, key, &attrval);
-    if (SUCCEEDED(hr) && length)
-        *length = lstrlenW(attrval.u.pwszVal);
-    PropVariantClear(&attrval);
+    EnterCriticalSection(&attributes->cs);
+
+    attribute = attributes_find_item(attributes, key, NULL);
+    if (attribute)
+    {
+        if (attribute->value.vt == MF_ATTRIBUTE_STRING)
+            *length = strlenW(attribute->value.u.pwszVal);
+        else
+            hr = MF_E_INVALIDTYPE;
+    }
+    else
+        hr = MF_E_ATTRIBUTENOTFOUND;
+
+    LeaveCriticalSection(&attributes->cs);
 
     return hr;
 }
@@ -932,19 +944,35 @@ static HRESULT WINAPI mfattributes_GetString(IMFAttributes *iface, REFGUID key,
         UINT32 size, UINT32 *length)
 {
     struct attributes *attributes = impl_from_IMFAttributes(iface);
-    PROPVARIANT attrval;
-    HRESULT hr;
+    struct attribute *attribute;
+    HRESULT hr = S_OK;
 
     TRACE("%p, %s, %p, %d, %p.\n", iface, debugstr_attr(key), value, size, length);
 
-    PropVariantInit(&attrval);
-    attrval.vt = VT_LPWSTR;
-    hr = attributes_get_item(attributes, key, &attrval);
-    if (SUCCEEDED(hr))
-        hr = PropVariantToString(&attrval, value, size);
-    if (SUCCEEDED(hr) && length)
-        *length = lstrlenW(value);
-    PropVariantClear(&attrval);
+    EnterCriticalSection(&attributes->cs);
+
+    attribute = attributes_find_item(attributes, key, NULL);
+    if (attribute)
+    {
+        if (attribute->value.vt == MF_ATTRIBUTE_STRING)
+        {
+            int len = strlenW(attribute->value.u.pwszVal);
+
+            if (length)
+                *length = len;
+
+            if (size <= len)
+                return STRSAFE_E_INSUFFICIENT_BUFFER;
+
+            memcpy(value, attribute->value.u.pwszVal, (len + 1) * sizeof(WCHAR));
+        }
+        else
+            hr = MF_E_INVALIDTYPE;
+    }
+    else
+        hr = MF_E_ATTRIBUTENOTFOUND;
+
+    LeaveCriticalSection(&attributes->cs);
 
     return hr;
 }
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c
index 7c36210..31b6ba1 100644
--- a/dlls/mfplat/tests/mfplat.c
+++ b/dlls/mfplat/tests/mfplat.c
@@ -708,9 +708,11 @@ static void test_attributes(void)
     ok(!lstrcmpW(bufferW, stringW), "Unexpected string %s.\n", wine_dbgstr_w(bufferW));
     memset(bufferW, 0, sizeof(bufferW));
 
-    hr = IMFAttributes_GetString(attributes, &DUMMY_GUID1, bufferW, 1, NULL);
+    string_length = 0;
+    hr = IMFAttributes_GetString(attributes, &DUMMY_GUID1, bufferW, 1, &string_length);
     ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Unexpected hr %#x.\n", hr);
     ok(!bufferW[0], "Unexpected string %s.\n", wine_dbgstr_w(bufferW));
+    ok(string_length, "Unexpected length.\n");
 
     string_length = 0xdeadbeef;
     hr = IMFAttributes_GetStringLength(attributes, &GUID_NULL, &string_length);




More information about the wine-cvs mailing list