Skip to content

Commit

Permalink
amend! mfmediaengine: Be a bit more conservative with locks in engine…
Browse files Browse the repository at this point in the history
… Shutdown.

mfmediaengine: Be a bit more conservative with locks in engine Shutdown.

During engine shutdown we acquire engine lock first, then locks of its constituents (e.g. sample
grabbers); whereas normally the order is the other way around (e.g. timer callback -> acquire sample
grabber lock -> OnProcessSample callback -> engine lock). This is deadlock prone.

With this commit, engine lock is released before we shutdown the inner media session.
  • Loading branch information
Yuxuan Shui committed Nov 24, 2023
1 parent a58b925 commit 4a69ec6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dlls/mfmediaengine/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ static HRESULT WINAPI media_engine_GetVideoAspectRatio(IMFMediaEngineEx *iface,
static HRESULT WINAPI media_engine_Shutdown(IMFMediaEngineEx *iface)
{
struct media_engine *engine = impl_from_IMFMediaEngineEx(iface);
IMFMediaSession *session;
IMFMediaSession *session = NULL;
HRESULT hr = S_OK;

TRACE("%p.\n", iface);
Expand All @@ -2218,8 +2218,11 @@ static HRESULT WINAPI media_engine_Shutdown(IMFMediaEngineEx *iface)
}
LeaveCriticalSection(&engine->cs);

IMFMediaSession_Shutdown(session);
IMFMediaSession_Release(session);
if (SUCCEEDED(hr))
{
IMFMediaSession_Shutdown(session);
IMFMediaSession_Release(session);
}
return hr;
}

Expand Down

0 comments on commit 4a69ec6

Please sign in to comment.