[PATCH v2 1/3] mf/tests: Add some WMA encoder ProcessOutput tests.

Rémi Bernon rbernon at codeweavers.com
Wed Feb 9 04:18:02 CST 2022


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51931
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52391
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

v2: Use a separate binary file with the raw WMA buffers. They are fixed
    size anyway so we can just read them sequentially. The WMA encoder
    test compare its output with the last recorded WMA buffers and
    outputs a new wmadata.bin file in a temporary directory.

 dlls/mf/tests/Makefile.in |   2 +
 dlls/mf/tests/mf.c        |  86 ++++++++++++++++++++++++++++++++++++++
 dlls/mf/tests/resource.rc |  24 +++++++++++
 dlls/mf/tests/wmadata.bin | Bin 0 -> 49071 bytes
 4 files changed, 112 insertions(+)
 create mode 100644 dlls/mf/tests/resource.rc
 create mode 100644 dlls/mf/tests/wmadata.bin

diff --git a/dlls/mf/tests/Makefile.in b/dlls/mf/tests/Makefile.in
index da9882fb7db..53592a8758d 100644
--- a/dlls/mf/tests/Makefile.in
+++ b/dlls/mf/tests/Makefile.in
@@ -4,3 +4,5 @@ IMPORTS   = mf mfplat mfuuid ole32 user32 propsys
 
 C_SRCS = \
 	mf.c
+
+RC_SRCS = resource.rc
diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c
index 990b759ff39..c1209ba95b0 100644
--- a/dlls/mf/tests/mf.c
+++ b/dlls/mf/tests/mf.c
@@ -5492,6 +5492,32 @@ static IMFSample *create_sample(const BYTE *data, ULONG size)
     return sample;
 }
 
+#define check_sample(a, b, c, d) check_sample_(__LINE__, a, b, c, d)
+static void check_sample_(int line, IMFSample *sample, const void *expect_buf, ULONG expect_len, HANDLE output_file)
+{
+    IMFMediaBuffer *media_buffer;
+    DWORD length;
+    BYTE *buffer;
+    HRESULT hr;
+    ULONG ret;
+
+    hr = IMFSample_ConvertToContiguousBuffer(sample, &media_buffer);
+    ok_(__FILE__, line)(hr == S_OK, "ConvertToContiguousBuffer returned %#x\n", hr);
+    hr = IMFMediaBuffer_Lock(media_buffer, &buffer, NULL, &length);
+    ok_(__FILE__, line)(hr == S_OK, "Lock returned %#x\n", hr);
+    ok_(__FILE__, line)(expect_len == length, "got length %u\n", length);
+    if (length && length == expect_len)
+    {
+        ok_(__FILE__, line)(!memcmp(expect_buf, buffer, expect_len),
+                "unexpected buffer data\n");
+    }
+    if (output_file) WriteFile(output_file, buffer, length, &length, NULL);
+    hr = IMFMediaBuffer_Unlock(media_buffer);
+    ok_(__FILE__, line)(hr == S_OK, "Unlock returned %#x\n", hr);
+    ret = IMFMediaBuffer_Release(media_buffer);
+    ok_(__FILE__, line)(ret == 1, "Release returned %u\n", ret);
+}
+
 static const BYTE wma_codec_data[10] = {0, 0x44, 0, 0, 0x17, 0, 0, 0, 0, 0};
 static const BYTE wma_decoded_data[0x4000] = {0};
 static const ULONG wma_block_size = 1487;
@@ -5552,10 +5578,17 @@ static void test_wma_encoder(void)
     MFT_REGISTER_TYPE_INFO input_type = {MFMediaType_Audio, MFAudioFormat_Float};
     MFT_OUTPUT_STREAM_INFO output_info;
     MFT_INPUT_STREAM_INFO input_info;
+    MFT_OUTPUT_DATA_BUFFER output;
+    const BYTE *wma_encoded_data;
+    WCHAR output_path[MAX_PATH];
+    ULONG wma_encoded_data_len;
     IMFMediaType *media_type;
     IMFTransform *transform;
+    HANDLE output_file;
     IMFSample *sample;
+    HRSRC resource;
     GUID class_id;
+    DWORD status;
     ULONG i, ret;
     HRESULT hr;
 
@@ -5612,6 +5645,59 @@ static void test_wma_encoder(void)
     hr = IMFTransform_ProcessInput(transform, 0, sample, 0);
     ok(hr == MF_E_NOTACCEPTING, "ProcessInput returned %#x\n", hr);
 
+    status = 0xdeadbeef;
+    sample = create_sample(NULL, output_info.cbSize);
+    memset(&output, 0, sizeof(output));
+    output.pSample = sample;
+
+    /* check wmadata.bin against current encoder output */
+    resource = FindResourceW(NULL, L"wmadata.bin", (const WCHAR *)RT_RCDATA);
+    ok(resource != 0, "FindResourceW failed, error %u\n", GetLastError());
+    wma_encoded_data = LockResource(LoadResource(GetModuleHandleW(NULL), resource));
+    wma_encoded_data_len = SizeofResource(GetModuleHandleW(NULL), resource);
+    ok(wma_encoded_data_len % wma_block_size == 0, "got wma encoded length %u\n", wma_encoded_data_len);
+
+    /* and generate a new one as well in a temporary directory */
+    GetTempPathW(ARRAY_SIZE(output_path), output_path);
+    lstrcatW(output_path, L"wmadata.bin");
+    output_file = CreateFileW(output_path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
+    ok(output_file != INVALID_HANDLE_VALUE, "CreateFileW failed, error %u\n", GetLastError());
+
+    i = 0;
+    while (SUCCEEDED(hr = IMFTransform_ProcessOutput(transform, 0, 1, &output, &status)))
+    {
+        winetest_push_context("%u", i);
+        ok(hr == S_OK, "ProcessOutput returned %#x\n", hr);
+        ok(output.pSample == sample, "got pSample %p\n", output.pSample);
+        ok(output.dwStatus == MFT_OUTPUT_DATA_BUFFER_INCOMPLETE ||
+                broken(output.dwStatus == (MFT_OUTPUT_DATA_BUFFER_INCOMPLETE|5)) /* win7 */,
+                "got dwStatus %#x\n", output.dwStatus);
+        ok(status == 0, "got status %#x\n", status);
+        ok(wma_encoded_data_len > i * wma_block_size, "got %u blocks\n", i);
+        check_sample(sample, wma_encoded_data + i * wma_block_size, wma_block_size, output_file);
+        winetest_pop_context();
+        i++;
+    }
+
+    trace("created %s\n", debugstr_w(output_path));
+    CloseHandle(output_file);
+
+    ret = IMFSample_Release(sample);
+    ok(ret == 0, "Release returned %u\n", ret);
+
+    status = 0xdeadbeef;
+    sample = create_sample(NULL, output_info.cbSize);
+    memset(&output, 0, sizeof(output));
+    output.pSample = sample;
+    hr = IMFTransform_ProcessOutput(transform, 0, 1, &output, &status);
+    ok(hr == MF_E_TRANSFORM_NEED_MORE_INPUT, "ProcessOutput returned %#x\n", hr);
+    ok(output.pSample == sample, "got pSample %p\n", output.pSample);
+    ok(output.dwStatus == 0, "got dwStatus %#x\n", output.dwStatus);
+    ok(status == 0, "got status %#x\n", status);
+    check_sample(sample, NULL, 0, NULL);
+    ret = IMFSample_Release(sample);
+    ok(ret == 0, "Release returned %u\n", ret);
+
     ret = IMFTransform_Release(transform);
     ok(ret == 0, "Release returned %u\n", ret);
 
diff --git a/dlls/mf/tests/resource.rc b/dlls/mf/tests/resource.rc
new file mode 100644
index 00000000000..931139c741a
--- /dev/null
+++ b/dlls/mf/tests/resource.rc
@@ -0,0 +1,24 @@
+/*
+ * Resources for mf test suite.
+ *
+ * Copyright 2022 Rémi Bernon for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "windef.h"
+
+/* @makedep: wmadata.bin */
+wmadata.bin RCDATA wmadata.bin
diff --git a/dlls/mf/tests/wmadata.bin b/dlls/mf/tests/wmadata.bin
new file mode 100644
index 0000000000000000000000000000000000000000..6c70c14ce3208f5c711effe156ac484c706686cd
GIT binary patch
literal 49071
zcmeI%v1tQA5CzZ!Co(v2sMN-RN>FHQ2Zt+A0S?rGRe*vkK_#dJm7ofYN{~8G=;V at t
zY2d@#Y&QD5fzQG|4#V$leA<6a-|s)KZ=Zi3&-<6f;1D1{fIybOau^hN*2<(MK!89e
zuu|t8i#q}Y2&4(D)p^>=<Rw6WKqoM&^Nz(G0RjZl1U7S>`wC6loV)}G5GVp$uk+$z
zAV7dXsK8F0hi*=60t5&Yfk~Yg4+8-L1VRN4>O6FFViO=hpa>l2I`<V?SPTRR5J(d^
zd7Y=NOkM&62y_Bxb>6YKBS3&an!rV!r>#t00t5(j0#|k3vA82ZfIynSeXes~p=q0w
zmjD3*MPT7|UOWs02oMMrSgP~T&52Eb0D&T~Qs>3PK!5;&P=U2N58a&D1PBl)0^?lg
zzCsI&fdBylX#yLs^R$)8OMn1 at PGGCfI~I2Y2oOjU*s1fhmB~wh0D(?mQs*6uI|2j<
zqzN46I`<WtwmEqT5Fk(lj$Y@*!$5!lflz^yIuG5P*aQd=C<147UOWs02oMMrxTy2c
w&52Eb0D&TKo$K6JXkjrBAV45Z;O=#vwlaAM5FpSAJgD=I#T@|x1kwcl0V8@&#Q*>R

literal 0
HcmV?d00001

-- 
2.34.1




More information about the wine-devel mailing list