Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mfmediaengine/Makefile.in | 2 +- dlls/mfmediaengine/main.c | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/dlls/mfmediaengine/Makefile.in b/dlls/mfmediaengine/Makefile.in index 292baa8001e..2278e87a645 100644 --- a/dlls/mfmediaengine/Makefile.in +++ b/dlls/mfmediaengine/Makefile.in @@ -1,6 +1,6 @@ MODULE = mfmediaengine.dll IMPORTLIB = mfmediaengine -IMPORTS = mfuuid uuid +IMPORTS = mf mfuuid uuid
EXTRADLLFLAGS = -mno-cygwin
diff --git a/dlls/mfmediaengine/main.c b/dlls/mfmediaengine/main.c index eef485e315b..77466e99931 100644 --- a/dlls/mfmediaengine/main.c +++ b/dlls/mfmediaengine/main.c @@ -66,6 +66,7 @@ enum media_engine_flags struct media_engine { IMFMediaEngine IMFMediaEngine_iface; + IMFAsyncCallback session_events; LONG refcount; IMFMediaEngineNotify *callback; UINT64 playback_hwnd; @@ -73,6 +74,7 @@ struct media_engine IMFDXGIDeviceManager *dxgi_manager; enum media_engine_mode mode; unsigned int flags; + IMFMediaSession *session; CRITICAL_SECTION cs; };
@@ -89,6 +91,70 @@ static inline struct media_engine *impl_from_IMFMediaEngine(IMFMediaEngine *ifac return CONTAINING_RECORD(iface, struct media_engine, IMFMediaEngine_iface); }
+static struct media_engine *impl_from_session_events_IMFAsyncCallback(IMFAsyncCallback *iface) +{ + return CONTAINING_RECORD(iface, struct media_engine, session_events); +} + +static HRESULT WINAPI media_engine_session_events_QueryInterface(IMFAsyncCallback *iface, REFIID riid, void **obj) +{ + if (IsEqualIID(riid, &IID_IMFAsyncCallback) || + IsEqualIID(riid, &IID_IUnknown)) + { + *obj = iface; + IMFAsyncCallback_AddRef(iface); + return S_OK; + } + + WARN("Unsupported interface %s.\n", debugstr_guid(riid)); + *obj = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI media_engine_session_events_AddRef(IMFAsyncCallback *iface) +{ + struct media_engine *engine = impl_from_session_events_IMFAsyncCallback(iface); + return IMFMediaEngine_AddRef(&engine->IMFMediaEngine_iface); +} + +static ULONG WINAPI media_engine_session_events_Release(IMFAsyncCallback *iface) +{ + struct media_engine *engine = impl_from_session_events_IMFAsyncCallback(iface); + return IMFMediaEngine_Release(&engine->IMFMediaEngine_iface); +} + +static HRESULT WINAPI media_engine_session_events_GetParameters(IMFAsyncCallback *iface, DWORD *flags, DWORD *queue) +{ + return E_NOTIMPL; +} + +static HRESULT WINAPI media_engine_session_events_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result) +{ + struct media_engine *engine = impl_from_session_events_IMFAsyncCallback(iface); + IMFMediaEvent *event = NULL; + HRESULT hr; + + if (FAILED(hr = IMFMediaSession_EndGetEvent(engine->session, result, &event))) + WARN("Failed to get session event, hr %#x.\n", hr); + + if (event) + IMFMediaEvent_Release(event); + + if (FAILED(hr = IMFMediaSession_BeginGetEvent(engine->session, iface, NULL))) + WARN("Failed to subscribe to session events, hr %#x.\n", hr); + + return S_OK; +} + +static const IMFAsyncCallbackVtbl media_engine_session_events_vtbl = +{ + media_engine_session_events_QueryInterface, + media_engine_session_events_AddRef, + media_engine_session_events_Release, + media_engine_session_events_GetParameters, + media_engine_session_events_Invoke, +}; + static HRESULT WINAPI media_engine_QueryInterface(IMFMediaEngine *iface, REFIID riid, void **obj) { TRACE("(%p, %s, %p).\n", iface, debugstr_guid(riid), obj); @@ -122,6 +188,8 @@ static void free_media_engine(struct media_engine *engine) IMFMediaEngineNotify_Release(engine->callback); if (engine->dxgi_manager) IMFDXGIDeviceManager_Release(engine->dxgi_manager); + if (engine->session) + IMFMediaSession_Release(engine->session); DeleteCriticalSection(&engine->cs); heap_free(engine); } @@ -449,7 +517,10 @@ static HRESULT WINAPI media_engine_Shutdown(IMFMediaEngine *iface) if (engine->flags & FLAGS_ENGINE_SHUT_DOWN) hr = MF_E_SHUTDOWN; else + { engine->flags |= FLAGS_ENGINE_SHUT_DOWN; + IMFMediaSession_Shutdown(engine->session); + } LeaveCriticalSection(&engine->cs);
return hr; @@ -550,6 +621,7 @@ static HRESULT init_media_engine(DWORD flags, IMFAttributes *attributes, struct HRESULT hr;
engine->IMFMediaEngine_iface.lpVtbl = &media_engine_vtbl; + engine->session_events.lpVtbl = &media_engine_session_events_vtbl; engine->refcount = 1; engine->flags = flags & MF_MEDIA_ENGINE_CREATEFLAGS_MASK; InitializeCriticalSection(&engine->cs); @@ -559,6 +631,12 @@ static HRESULT init_media_engine(DWORD flags, IMFAttributes *attributes, struct if (FAILED(hr)) return MF_E_ATTRIBUTENOTFOUND;
+ if (FAILED(hr = MFCreateMediaSession(NULL, &engine->session))) + return hr; + + if (FAILED(hr = IMFMediaSession_BeginGetEvent(engine->session, &engine->session_events, NULL))) + return hr; + IMFAttributes_GetUINT64(attributes, &MF_MEDIA_ENGINE_PLAYBACK_HWND, &engine->playback_hwnd); IMFAttributes_GetUnknown(attributes, &MF_MEDIA_ENGINE_DXGI_MANAGER, &IID_IMFDXGIDeviceManager, (void **)&engine->dxgi_manager);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mfmediaengine/main.c | 41 +++++++++++++++++++++--- dlls/mfmediaengine/tests/mfmediaengine.c | 33 ++++++++++++++++++- 2 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/dlls/mfmediaengine/main.c b/dlls/mfmediaengine/main.c index 77466e99931..13cbeb4b8db 100644 --- a/dlls/mfmediaengine/main.c +++ b/dlls/mfmediaengine/main.c @@ -61,6 +61,8 @@ enum media_engine_flags FLAGS_ENGINE_SHUT_DOWN = 0x20, FLAGS_ENGINE_AUTO_PLAY = 0x40, FLAGS_ENGINE_LOOP = 0x80, + FLAGS_ENGINE_PAUSED = 0x100, + FLAGS_ENGINE_WAITING = 0x200, };
struct media_engine @@ -328,9 +330,16 @@ static double WINAPI media_engine_GetDuration(IMFMediaEngine *iface)
static BOOL WINAPI media_engine_IsPaused(IMFMediaEngine *iface) { - FIXME("(%p): stub.\n", iface); + struct media_engine *engine = impl_from_IMFMediaEngine(iface); + BOOL value;
- return FALSE; + TRACE("%p.\n", iface); + + EnterCriticalSection(&engine->cs); + value = !!(engine->flags & FLAGS_ENGINE_PAUSED); + LeaveCriticalSection(&engine->cs); + + return value; }
static double WINAPI media_engine_GetDefaultPlaybackRate(IMFMediaEngine *iface) @@ -438,9 +447,31 @@ static HRESULT WINAPI media_engine_SetLoop(IMFMediaEngine *iface, BOOL loop)
static HRESULT WINAPI media_engine_Play(IMFMediaEngine *iface) { - FIXME("(%p): stub.\n", iface); + struct media_engine *engine = impl_from_IMFMediaEngine(iface); + PROPVARIANT var;
- return E_NOTIMPL; + TRACE("%p.\n", iface); + + EnterCriticalSection(&engine->cs); + + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_PURGEQUEUEDEVENTS, 0, 0); + + if (!(engine->flags & FLAGS_ENGINE_WAITING)) + { + engine->flags &= ~FLAGS_ENGINE_PAUSED; + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_PLAY, 0, 0); + + var.vt = VT_EMPTY; + IMFMediaSession_Start(engine->session, &GUID_NULL, &var); + + engine->flags |= FLAGS_ENGINE_WAITING; + } + + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_WAITING, 0, 0); + + LeaveCriticalSection(&engine->cs); + + return S_OK; }
static HRESULT WINAPI media_engine_Pause(IMFMediaEngine *iface) @@ -623,7 +654,7 @@ static HRESULT init_media_engine(DWORD flags, IMFAttributes *attributes, struct engine->IMFMediaEngine_iface.lpVtbl = &media_engine_vtbl; engine->session_events.lpVtbl = &media_engine_session_events_vtbl; engine->refcount = 1; - engine->flags = flags & MF_MEDIA_ENGINE_CREATEFLAGS_MASK; + engine->flags = (flags & MF_MEDIA_ENGINE_CREATEFLAGS_MASK) | FLAGS_ENGINE_PAUSED; InitializeCriticalSection(&engine->cs);
hr = IMFAttributes_GetUnknown(attributes, &MF_MEDIA_ENGINE_CALLBACK, &IID_IMFMediaEngineNotify, diff --git a/dlls/mfmediaengine/tests/mfmediaengine.c b/dlls/mfmediaengine/tests/mfmediaengine.c index 504464b5272..e7cb6432b92 100644 --- a/dlls/mfmediaengine/tests/mfmediaengine.c +++ b/dlls/mfmediaengine/tests/mfmediaengine.c @@ -307,7 +307,6 @@ todo_wine ok(val == 0.0, "Unexpected time %f.\n", val);
state = IMFMediaEngine_IsPaused(media_engine); -todo_wine ok(!!state, "Unexpected state %d.\n", state);
val = IMFMediaEngine_GetDefaultPlaybackRate(media_engine); @@ -393,6 +392,37 @@ todo_wine IMFMediaEngine_Release(media_engine); }
+static void test_Play(void) +{ + struct media_engine_notify notify_impl = {{&media_engine_notify_vtbl}, 1}; + IMFMediaEngineNotify *callback = ¬ify_impl.IMFMediaEngineNotify_iface; + IMFMediaEngine *media_engine; + HRESULT hr; + BOOL ret; + + media_engine = create_media_engine(callback); + + ret = IMFMediaEngine_IsPaused(media_engine); + ok(ret, "Unexpected state %d.\n", ret); + + hr = IMFMediaEngine_Play(media_engine); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + ret = IMFMediaEngine_IsPaused(media_engine); + ok(!ret, "Unexpected state %d.\n", ret); + + hr = IMFMediaEngine_Play(media_engine); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMFMediaEngine_Shutdown(media_engine); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + ret = IMFMediaEngine_IsPaused(media_engine); + ok(!ret, "Unexpected state %d.\n", ret); + + IMFMediaEngine_Release(media_engine); +} + START_TEST(mfmediaengine) { HRESULT hr; @@ -416,6 +446,7 @@ START_TEST(mfmediaengine) test_factory(); test_CreateInstance(); test_Shutdown(); + test_Play();
IMFMediaEngineClassFactory_Release(factory);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=72490
Your paranoid android.
=== build (build log) ===
error: patch failed: dlls/mfmediaengine/main.c:66 error: patch failed: dlls/mfmediaengine/main.c:61 error: patch failed: dlls/mfmediaengine/tests/mfmediaengine.c:307 Task: Patch failed to apply
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mfmediaengine/main.c | 21 +++++++++++++++++++-- dlls/mfmediaengine/tests/mfmediaengine.c | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/dlls/mfmediaengine/main.c b/dlls/mfmediaengine/main.c index 13cbeb4b8db..fcef1be048f 100644 --- a/dlls/mfmediaengine/main.c +++ b/dlls/mfmediaengine/main.c @@ -476,9 +476,26 @@ static HRESULT WINAPI media_engine_Play(IMFMediaEngine *iface)
static HRESULT WINAPI media_engine_Pause(IMFMediaEngine *iface) { - FIXME("(%p): stub.\n", iface); + struct media_engine *engine = impl_from_IMFMediaEngine(iface);
- return E_NOTIMPL; + TRACE("%p.\n", iface); + + EnterCriticalSection(&engine->cs); + + if (!(engine->flags & FLAGS_ENGINE_PAUSED)) + { + engine->flags &= ~FLAGS_ENGINE_WAITING; + engine->flags |= FLAGS_ENGINE_PAUSED; + + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_TIMEUPDATE, 0, 0); + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_PAUSE, 0, 0); + } + + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_PURGEQUEUEDEVENTS, 0, 0); + + LeaveCriticalSection(&engine->cs); + + return S_OK; }
static BOOL WINAPI media_engine_GetMuted(IMFMediaEngine *iface) diff --git a/dlls/mfmediaengine/tests/mfmediaengine.c b/dlls/mfmediaengine/tests/mfmediaengine.c index e7cb6432b92..a3db611e9fc 100644 --- a/dlls/mfmediaengine/tests/mfmediaengine.c +++ b/dlls/mfmediaengine/tests/mfmediaengine.c @@ -421,6 +421,23 @@ static void test_Play(void) ok(!ret, "Unexpected state %d.\n", ret);
IMFMediaEngine_Release(media_engine); + + /* Play -> Pause */ + media_engine = create_media_engine(callback); + + hr = IMFMediaEngine_Play(media_engine); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + ret = IMFMediaEngine_IsPaused(media_engine); + ok(!ret, "Unexpected state %d.\n", ret); + + hr = IMFMediaEngine_Pause(media_engine); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + ret = IMFMediaEngine_IsPaused(media_engine); + ok(!!ret, "Unexpected state %d.\n", ret); + + IMFMediaEngine_Release(media_engine); }
START_TEST(mfmediaengine)
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=72491
Your paranoid android.
=== build (build log) ===
error: patch failed: dlls/mfmediaengine/main.c:66 error: patch failed: dlls/mfmediaengine/main.c:61 error: patch failed: dlls/mfmediaengine/tests/mfmediaengine.c:307 error: patch failed: dlls/mfmediaengine/tests/mfmediaengine.c:421 Task: Patch failed to apply