From 6fa8ff69300d167b34a4c4b079ae6d5924ba1fc4 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 2 Jun 2020 11:41:04 +0300 Subject: [PATCH] mfmediaengine: Send "ratechange" event for both default and playback rate changes. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mfmediaengine/main.c | 60 ++++++++++++++++++++---- dlls/mfmediaengine/tests/mfmediaengine.c | 32 +++++++++++-- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/dlls/mfmediaengine/main.c b/dlls/mfmediaengine/main.c index fcef1be048f..b9bf3c7027b 100644 --- a/dlls/mfmediaengine/main.c +++ b/dlls/mfmediaengine/main.c @@ -76,6 +76,8 @@ struct media_engine IMFDXGIDeviceManager *dxgi_manager; enum media_engine_mode mode; unsigned int flags; + double playback_rate; + double default_playback_rate; IMFMediaSession *session; CRITICAL_SECTION cs; }; @@ -344,30 +346,70 @@ static BOOL WINAPI media_engine_IsPaused(IMFMediaEngine *iface) static double WINAPI media_engine_GetDefaultPlaybackRate(IMFMediaEngine *iface) { - FIXME("(%p): stub.\n", iface); + struct media_engine *engine = impl_from_IMFMediaEngine(iface); + double rate; - return 0.0; + TRACE("%p.\n", iface); + + EnterCriticalSection(&engine->cs); + rate = engine->default_playback_rate; + LeaveCriticalSection(&engine->cs); + + return rate; } static HRESULT WINAPI media_engine_SetDefaultPlaybackRate(IMFMediaEngine *iface, double rate) { - FIXME("(%p, %f): stub.\n", iface, rate); + struct media_engine *engine = impl_from_IMFMediaEngine(iface); + HRESULT hr = S_OK; - return E_NOTIMPL; + TRACE("%p, %f.\n", iface, rate); + + EnterCriticalSection(&engine->cs); + if (engine->flags & FLAGS_ENGINE_SHUT_DOWN) + hr = MF_E_SHUTDOWN; + else if (engine->default_playback_rate != rate) + { + engine->default_playback_rate = rate; + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_RATECHANGE, 0, 0); + } + LeaveCriticalSection(&engine->cs); + + return hr; } static double WINAPI media_engine_GetPlaybackRate(IMFMediaEngine *iface) { - FIXME("(%p): stub.\n", iface); + struct media_engine *engine = impl_from_IMFMediaEngine(iface); + double rate; - return 0.0; + TRACE("%p.\n", iface); + + EnterCriticalSection(&engine->cs); + rate = engine->playback_rate; + LeaveCriticalSection(&engine->cs); + + return rate; } static HRESULT WINAPI media_engine_SetPlaybackRate(IMFMediaEngine *iface, double rate) { - FIXME("(%p, %f): stub.\n", iface, rate); + struct media_engine *engine = impl_from_IMFMediaEngine(iface); + HRESULT hr = S_OK; - return E_NOTIMPL; + TRACE("%p, %f.\n", iface, rate); + + EnterCriticalSection(&engine->cs); + if (engine->flags & FLAGS_ENGINE_SHUT_DOWN) + hr = MF_E_SHUTDOWN; + else if (engine->playback_rate != rate) + { + engine->playback_rate = rate; + IMFMediaEngineNotify_EventNotify(engine->callback, MF_MEDIA_ENGINE_EVENT_RATECHANGE, 0, 0); + } + LeaveCriticalSection(&engine->cs); + + return hr; } static HRESULT WINAPI media_engine_GetPlayed(IMFMediaEngine *iface, IMFMediaTimeRange **played) @@ -672,6 +714,8 @@ static HRESULT init_media_engine(DWORD flags, IMFAttributes *attributes, struct engine->session_events.lpVtbl = &media_engine_session_events_vtbl; engine->refcount = 1; engine->flags = (flags & MF_MEDIA_ENGINE_CREATEFLAGS_MASK) | FLAGS_ENGINE_PAUSED; + engine->default_playback_rate = 1.0; + engine->playback_rate = 1.0; 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 a3db611e9fc..4079e9aa70f 100644 --- a/dlls/mfmediaengine/tests/mfmediaengine.c +++ b/dlls/mfmediaengine/tests/mfmediaengine.c @@ -310,15 +310,12 @@ todo_wine ok(!!state, "Unexpected state %d.\n", state); val = IMFMediaEngine_GetDefaultPlaybackRate(media_engine); -todo_wine ok(val == 1.0, "Unexpected rate %f.\n", val); hr = IMFMediaEngine_SetDefaultPlaybackRate(media_engine, 2.0); -todo_wine ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#x.\n", hr); val = IMFMediaEngine_GetPlaybackRate(media_engine); -todo_wine ok(val == 1.0, "Unexpected rate %f.\n", val); hr = IMFMediaEngine_GetPlayed(media_engine, &time_range); @@ -440,6 +437,34 @@ static void test_Play(void) IMFMediaEngine_Release(media_engine); } +static void test_playback_rate(void) +{ + struct media_engine_notify notify_impl = {{&media_engine_notify_vtbl}, 1}; + IMFMediaEngineNotify *callback = ¬ify_impl.IMFMediaEngineNotify_iface; + IMFMediaEngine *media_engine; + double rate; + HRESULT hr; + + media_engine = create_media_engine(callback); + + rate = IMFMediaEngine_GetDefaultPlaybackRate(media_engine); + ok(rate == 1.0, "Unexpected default rate.\n"); + + rate = IMFMediaEngine_GetPlaybackRate(media_engine); + ok(rate == 1.0, "Unexpected default rate.\n"); + + hr = IMFMediaEngine_SetPlaybackRate(media_engine, 0.0); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + rate = IMFMediaEngine_GetPlaybackRate(media_engine); + ok(rate == 0.0, "Unexpected default rate.\n"); + + hr = IMFMediaEngine_SetDefaultPlaybackRate(media_engine, 0.0); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + IMFMediaEngine_Release(media_engine); +} + START_TEST(mfmediaengine) { HRESULT hr; @@ -464,6 +489,7 @@ START_TEST(mfmediaengine) test_CreateInstance(); test_Shutdown(); test_Play(); + test_playback_rate(); IMFMediaEngineClassFactory_Release(factory);