From ce37290a5a7b630207c4303c90c44a9a09a8ab2b Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 14 Apr 2021 09:49:10 +0300 Subject: [PATCH] mfplat: Release queue subscriber on queue release. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mfplat/main.c | 6 ++---- dlls/mfplat/tests/mfplat.c | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c index e23c648c823..5a35350f5c5 100644 --- a/dlls/mfplat/main.c +++ b/dlls/mfplat/main.c @@ -7019,6 +7019,7 @@ static void event_queue_cleanup(struct event_queue *queue) while ((event = queue_pop_event(queue))) IMFMediaEvent_Release(event); + event_queue_clear_subscriber(queue); } static HRESULT WINAPI eventqueue_QueryInterface(IMFMediaEventQueue *iface, REFIID riid, void **out) @@ -7162,9 +7163,7 @@ static HRESULT WINAPI eventqueue_EndGetEvent(IMFMediaEventQueue *iface, IMFAsync else if (queue->subscriber == (IRtwqAsyncResult *)result) { *event = queue_pop_event(queue); - if (queue->subscriber) - IRtwqAsyncResult_Release(queue->subscriber); - queue->subscriber = NULL; + event_queue_clear_subscriber(queue); queue->notified = FALSE; hr = *event ? S_OK : E_FAIL; } @@ -7265,7 +7264,6 @@ static HRESULT WINAPI eventqueue_Shutdown(IMFMediaEventQueue *iface) if (!queue->is_shut_down) { event_queue_cleanup(queue); - event_queue_clear_subscriber(queue); queue->is_shut_down = TRUE; } diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 603dbbe22ff..fd9a27d599c 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -326,6 +326,7 @@ static WCHAR *load_resource(const WCHAR *name) struct test_callback { IMFAsyncCallback IMFAsyncCallback_iface; + LONG refcount; HANDLE event; DWORD param; IMFMediaEvent *media_event; @@ -352,12 +353,14 @@ static HRESULT WINAPI testcallback_QueryInterface(IMFAsyncCallback *iface, REFII static ULONG WINAPI testcallback_AddRef(IMFAsyncCallback *iface) { - return 2; + struct test_callback *callback = impl_from_IMFAsyncCallback(iface); + return InterlockedIncrement(&callback->refcount); } static ULONG WINAPI testcallback_Release(IMFAsyncCallback *iface) { - return 1; + struct test_callback *callback = impl_from_IMFAsyncCallback(iface); + return InterlockedDecrement(&callback->refcount); } static HRESULT WINAPI testcallback_GetParameters(IMFAsyncCallback *iface, DWORD *flags, DWORD *queue) @@ -2462,6 +2465,7 @@ static void init_test_callback(struct test_callback *callback) { callback->IMFAsyncCallback_iface.lpVtbl = &testcallbackvtbl; callback->event = NULL; + callback->refcount = 1; } static void test_MFCreateAsyncResult(void) @@ -3114,6 +3118,19 @@ static void test_event_queue(void) IMFMediaEventQueue_Release(queue); + /* Release while subscribed. */ + init_test_callback(&callback); + + hr = MFCreateEventQueue(&queue); + ok(hr == S_OK, "Failed to create event queue, hr %#x.\n", hr); + + hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback.IMFAsyncCallback_iface, NULL); + ok(hr == S_OK, "Failed to Begin*, hr %#x.\n", hr); + EXPECT_REF(&callback.IMFAsyncCallback_iface, 2); + + IMFMediaEventQueue_Release(queue); + EXPECT_REF(&callback.IMFAsyncCallback_iface, 1); + hr = MFShutdown(); ok(hr == S_OK, "Failed to shut down, hr %#x.\n", hr); }