[PATCH 5/6] mfmediaengine: Close the media session on shutdown.
Derek Lesho
dlesho at codeweavers.com
Wed Jan 5 10:03:05 CST 2022
On 1/5/22 06:09, Nikolay Sivov wrote:
>
>
> On 1/4/22 20:35, Derek Lesho wrote:
>> failed:
>> @@ -1297,6 +1302,7 @@ static void free_media_engine(struct
>> media_engine *engine)
>> }
>> SysFreeString(engine->current_source);
>> DeleteCriticalSection(&engine->cs);
>> + CloseHandle(engine->session_closed);
>> free(engine->video_frame.buffer);
>> free(engine);
>> }
>> @@ -1956,6 +1962,8 @@ static HRESULT WINAPI
>> media_engine_Shutdown(IMFMediaEngine *iface)
>> else
>> {
>> media_engine_set_flag(engine, FLAGS_ENGINE_SHUT_DOWN, TRUE);
>> + IMFMediaSession_Close(engine->session);
>> + WaitForSingleObject(engine->session_closed, INFINITE);
>> IMFMediaSession_Shutdown(engine->session);
>> }
>
> Could you explain what does this fix?
::Close releases the queued topology object, ::Shutdown doesn't.
::Release also closes the topology object, but there's a circular
dependency here as the sample grabber sink node in the queued topology
references the sample grabber media sink object, which references the
sample grabber callback object, which, in the case of the media engine,
contributes to the reference count of the media engine, and the media
engine only releases the media session once it is fully released.
Additionally, the documentation advises that you ::Close a session
before shutting it down.
https://docs.microsoft.com/en-us/windows/win32/medfound/step-7--shut-down-the-media-session
>> LeaveCriticalSection(&engine->cs);
>> @@ -2451,6 +2459,7 @@ static HRESULT init_media_engine(DWORD flags,
>> IMFAttributes *attributes, struct
>> engine->duration = NAN;
>> engine->video_frame.pts = MINLONGLONG;
>> InitializeCriticalSection(&engine->cs);
>> + engine->session_closed = CreateEventW(NULL, TRUE, FALSE, NULL);
>> hr = IMFAttributes_GetUnknown(attributes,
>> &MF_MEDIA_ENGINE_CALLBACK, &IID_IMFMediaEngineNotify,
>> (void **)&engine->callback);
>
>
More information about the wine-devel
mailing list