Zebediah Figura : quartz/tests: Add tests for DirectSound renderer filter state.

Alexandre Julliard julliard at winehq.org
Fri Jul 17 16:30:47 CDT 2020


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

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Fri Jul 17 14:51:20 2020 -0500

quartz/tests: Add tests for DirectSound renderer filter state.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/quartz/tests/dsoundrender.c | 233 +++++++++++++++++++++++++++++----------
 1 file changed, 176 insertions(+), 57 deletions(-)

diff --git a/dlls/quartz/tests/dsoundrender.c b/dlls/quartz/tests/dsoundrender.c
index d5c18d389a..35f935bcad 100644
--- a/dlls/quartz/tests/dsoundrender.c
+++ b/dlls/quartz/tests/dsoundrender.c
@@ -20,6 +20,7 @@
  */
 
 #define COBJMACROS
+#include <math.h>
 #include "dshow.h"
 #include "initguid.h"
 #include "dsound.h"
@@ -674,8 +675,164 @@ static void test_allocator(IMemInputPin *input)
     IMemAllocator_Release(ret_allocator);
 }
 
+struct frame_thread_params
+{
+    IMemInputPin *sink;
+    IMediaSample *sample;
+};
+
+static DWORD WINAPI frame_thread(void *arg)
+{
+    struct frame_thread_params *params = arg;
+    HRESULT hr;
+
+    if (winetest_debug > 1) trace("%04x: Sending frame.\n", GetCurrentThreadId());
+    hr = IMemInputPin_Receive(params->sink, params->sample);
+    if (winetest_debug > 1) trace("%04x: Returned %#x.\n", GetCurrentThreadId(), hr);
+    IMediaSample_Release(params->sample);
+    free(params);
+    return hr;
+}
+
+static HRESULT send_frame(IMemInputPin *sink)
+{
+    struct frame_thread_params *params = malloc(sizeof(*params));
+    REFERENCE_TIME start_time, end_time;
+    IMemAllocator *allocator;
+    unsigned short *words;
+    IMediaSample *sample;
+    unsigned int i;
+    HANDLE thread;
+    HRESULT hr;
+    BYTE *data;
+    DWORD ret;
+
+    hr = IMemInputPin_GetAllocator(sink, &allocator);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaSample_GetPointer(sample, &data);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    words = (unsigned short *)data;
+    for (i = 0; i < 44100 * 2; i += 2)
+        words[i] = words[i+1] = sinf(i / 20.0f) * 0x7fff;
+
+    hr = IMediaSample_SetActualDataLength(sample, 44100 * 4);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    start_time = 0;
+    end_time = start_time + 10000000;
+    hr = IMediaSample_SetTime(sample, &start_time, &end_time);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    params->sink = sink;
+    params->sample = sample;
+    thread = CreateThread(NULL, 0, frame_thread, params, 0, NULL);
+    ret = WaitForSingleObject(thread, 500);
+    todo_wine_if (ret) ok(!ret, "Wait failed.\n");
+    GetExitCodeThread(thread, &ret);
+    CloseHandle(thread);
+
+    IMemAllocator_Release(allocator);
+    return ret;
+}
+
+static void test_filter_state(IMemInputPin *input, IFilterGraph2 *graph)
+{
+    IMediaControl *control;
+    OAFilterState state;
+    HRESULT hr;
+
+    IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
+
+    hr = send_frame(input);
+    ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
+
+    /* The renderer is not fully paused until it receives a sample. The
+     * DirectSound renderer never blocks in Receive(), despite returning S_OK
+     * from ReceiveCanBlock(). Instead it holds on to each sample until its
+     * presentation time, then writes it into the buffer. This is more work
+     * than it's worth to emulate, so for now, we'll ignore this behaviour. */
+
+    hr = IMediaControl_Pause(control);
+    ok(hr == S_FALSE, "Got hr %#x.\n", hr);
+
+    /* It's possible to queue multiple samples while paused. The number of
+     * samples that can be queued depends on the length of each sample, but
+     * it's not particularly clear how. */
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
+
+    hr = send_frame(input);
+    todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 1000, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_Stop(control);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = send_frame(input);
+    ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_Pause(control);
+    ok(hr == S_FALSE, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
+
+    hr = send_frame(input);
+    todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 1000, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_Run(control);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = send_frame(input);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = send_frame(input);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_Run(control);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_Pause(control);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_Stop(control);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMediaControl_GetState(control, 0, &state);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    /* The DirectSound renderer will silently refuse to transition to running
+     * if it hasn't finished pausing yet. Once it does it reports itself as
+     * completely paused. */
+
+    IMediaControl_Release(control);
+}
+
 static void test_connect_pin(void)
 {
+    ALLOCATOR_PROPERTIES req_props = {1, 4 * 44100, 1, 0}, ret_props;
     WAVEFORMATEX wfx =
     {
         .wFormatTag = WAVE_FORMAT_PCM,
@@ -695,6 +852,7 @@ static void test_connect_pin(void)
     };
     IBaseFilter *filter = create_dsound_render();
     struct testfilter source;
+    IMemAllocator *allocator;
     IFilterGraph2 *graph;
     IMemInputPin *input;
     AM_MEDIA_TYPE mt;
@@ -734,6 +892,22 @@ static void test_connect_pin(void)
 
     test_allocator(input);
 
+    hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER,
+            &IID_IMemAllocator, (void **)&allocator);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
+    hr = IMemInputPin_NotifyAllocator(input, allocator, TRUE);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    hr = IMemAllocator_Commit(allocator);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = IMemInputPin_ReceiveCanBlock(input);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    test_filter_state(input, graph);
+
     hr = IFilterGraph2_Disconnect(graph, pin);
     ok(hr == S_OK, "Got hr %#x.\n", hr);
     hr = IFilterGraph2_Disconnect(graph, pin);
@@ -749,6 +923,8 @@ static void test_connect_pin(void)
     hr = IPin_ConnectionMediaType(pin, &mt);
     ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
 
+    ref = IMemAllocator_Release(allocator);
+    ok(!ref, "Got outstanding refcount %d.\n", ref);
     IMemInputPin_Release(input);
     IPin_Release(pin);
     ref = IFilterGraph2_Release(graph);
@@ -759,62 +935,6 @@ static void test_connect_pin(void)
     ok(!ref, "Got outstanding refcount %d.\n", ref);
 }
 
-static void test_pin(IPin *pin)
-{
-    IMemInputPin *mpin = NULL;
-
-    IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&mpin);
-
-    ok(mpin != NULL, "No IMemInputPin found!\n");
-    if (mpin)
-    {
-        ok(IMemInputPin_ReceiveCanBlock(mpin) == S_OK, "Receive can't block for pin!\n");
-        ok(IMemInputPin_NotifyAllocator(mpin, NULL, 0) == E_POINTER, "NotifyAllocator likes a NULL pointer argument\n");
-        IMemInputPin_Release(mpin);
-    }
-    /* TODO */
-}
-
-static void test_basefilter(void)
-{
-    IEnumPins *pin_enum = NULL;
-    IBaseFilter *base = create_dsound_render();
-    IPin *pins[2];
-    ULONG ref;
-    HRESULT hr;
-
-    hr = IBaseFilter_EnumPins(base, NULL);
-    ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
-
-    hr= IBaseFilter_EnumPins(base, &pin_enum);
-    ok(hr == S_OK, "hr = %08x and not S_OK\n", hr);
-
-    hr = IEnumPins_Next(pin_enum, 1, NULL, NULL);
-    ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
-
-    hr = IEnumPins_Next(pin_enum, 2, pins, NULL);
-    ok(hr == E_INVALIDARG, "hr = %08x and not E_INVALIDARG\n", hr);
-
-    pins[0] = (void *)0xdead;
-    pins[1] = (void *)0xdeed;
-
-    hr = IEnumPins_Next(pin_enum, 2, pins, &ref);
-    ok(hr == S_FALSE, "hr = %08x instead of S_FALSE\n", hr);
-    ok(pins[0] != (void *)0xdead && pins[0] != NULL, "pins[0] = %p\n", pins[0]);
-    if (pins[0] != (void *)0xdead && pins[0] != NULL)
-    {
-        test_pin(pins[0]);
-        IPin_Release(pins[0]);
-    }
-
-    ok(pins[1] == (void *)0xdeed, "pins[1] = %p\n", pins[1]);
-
-    ref = IEnumPins_Release(pin_enum);
-    ok(ref == 0, "ref is %u and not 0!\n", ref);
-
-    IBaseFilter_Release(base);
-}
-
 static void test_unconnected_filter_state(void)
 {
     IBaseFilter *filter = create_dsound_render();
@@ -1016,7 +1136,6 @@ START_TEST(dsoundrender)
     test_unconnected_filter_state();
     test_media_types();
     test_connect_pin();
-    test_basefilter();
 
     CoUninitialize();
 }




More information about the wine-cvs mailing list