From 97ed08cb523632b487cd3cdb8141333cebf059e5 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 5 Apr 2021 09:10:57 +0300 Subject: [PATCH] mfplay: Keep user callback reference. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mfplay/player.c | 8 ++++++++ dlls/mfplay/tests/Makefile.in | 2 +- dlls/mfplay/tests/mfplay.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/dlls/mfplay/player.c b/dlls/mfplay/player.c index 1e2a3a8f189..6905812835a 100644 --- a/dlls/mfplay/player.c +++ b/dlls/mfplay/player.c @@ -33,6 +33,7 @@ struct media_player { IMFPMediaPlayer IMFPMediaPlayer_iface; LONG refcount; + IMFPMediaPlayerCallback *callback; }; static struct media_player *impl_from_IMFPMediaPlayer(IMFPMediaPlayer *iface) @@ -76,7 +77,11 @@ static ULONG WINAPI media_player_Release(IMFPMediaPlayer *iface) TRACE("%p, refcount %u.\n", iface, refcount); if (!refcount) + { + if (player->callback) + IMFPMediaPlayerCallback_Release(player->callback); heap_free(player); + } return refcount; } @@ -396,6 +401,9 @@ HRESULT WINAPI MFPCreateMediaPlayer(const WCHAR *url, BOOL start_playback, MFP_C object->IMFPMediaPlayer_iface.lpVtbl = &media_player_vtbl; object->refcount = 1; + object->callback = callback; + if (object->callback) + IMFPMediaPlayerCallback_AddRef(object->callback); *player = &object->IMFPMediaPlayer_iface; diff --git a/dlls/mfplay/tests/Makefile.in b/dlls/mfplay/tests/Makefile.in index ca08c65ce24..43c7ec26240 100644 --- a/dlls/mfplay/tests/Makefile.in +++ b/dlls/mfplay/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = mfplay.dll -IMPORTS = mfplay +IMPORTS = mfplay uuid mfuuid C_SRCS = \ mfplay.c diff --git a/dlls/mfplay/tests/mfplay.c b/dlls/mfplay/tests/mfplay.c index e9b5df95039..ef8aaddc76f 100644 --- a/dlls/mfplay/tests/mfplay.c +++ b/dlls/mfplay/tests/mfplay.c @@ -26,14 +26,55 @@ #include "wine/test.h" +static HRESULT WINAPI test_callback_QueryInterface(IMFPMediaPlayerCallback *iface, REFIID riid, void **obj) +{ + if (IsEqualIID(riid, &IID_IMFPMediaPlayerCallback) || + IsEqualIID(riid, &IID_IUnknown)) + { + *obj = iface; + IMFPMediaPlayerCallback_AddRef(iface); + return S_OK; + } + + *obj = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI test_callback_AddRef(IMFPMediaPlayerCallback *iface) +{ + return 2; +} + +static ULONG WINAPI test_callback_Release(IMFPMediaPlayerCallback *iface) +{ + return 1; +} + +static void WINAPI test_callback_OnMediaPlayerEvent(IMFPMediaPlayerCallback *iface, MFP_EVENT_HEADER *event_header) +{ +} + +static const IMFPMediaPlayerCallbackVtbl test_callback_vtbl = +{ + test_callback_QueryInterface, + test_callback_AddRef, + test_callback_Release, + test_callback_OnMediaPlayerEvent, +}; + static void test_create_player(void) { + IMFPMediaPlayerCallback callback = { &test_callback_vtbl }; IMFPMediaPlayer *player; HRESULT hr; hr = MFPCreateMediaPlayer(NULL, FALSE, 0, NULL, NULL, &player); ok(hr == S_OK, "Unexpected hr %#x.\n", hr); IMFPMediaPlayer_Release(player); + + hr = MFPCreateMediaPlayer(NULL, FALSE, 0, &callback, NULL, &player); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IMFPMediaPlayer_Release(player); } START_TEST(mfplay) -- 2.11.4.GIT