From 2e0253ae3a6aa9acf85191c7a8084dc2ded29041 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Wed, 7 Mar 2018 04:30:15 -0600 Subject: [PATCH] Clean up mf_uninit --- libfreerdp/codec/h264_mf.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libfreerdp/codec/h264_mf.c b/libfreerdp/codec/h264_mf.c index a892d46a4..dc9c43239 100644 --- a/libfreerdp/codec/h264_mf.c +++ b/libfreerdp/codec/h264_mf.c @@ -431,6 +431,12 @@ static int mf_compress(H264_CONTEXT* h264, const BYTE** ppSrcYuv, const UINT32* return 1; } +static BOOL mf_plat_loaded(H264_CONTEXT_MF* sys) +{ + return sys->MFStartup && sys->MFShutdown && sys->MFCreateSample + && sys->MFCreateMemoryBuffer && sys->MFCreateMediaType; +} + static void mf_uninit(H264_CONTEXT* h264) { UINT32 x; @@ -470,8 +476,14 @@ static void mf_uninit(H264_CONTEXT* h264) if (sys->mfplat) { + if (mf_plat_loaded(sys)) + sys->MFShutdown(); + FreeLibrary(sys->mfplat); sys->mfplat = NULL; + + if (mf_plat_loaded(sys)) + CoUninitialize(); } for (x = 0; x < sizeof(h264->pYUVData) / sizeof(h264->pYUVData[0]); x++) @@ -479,8 +491,7 @@ static void mf_uninit(H264_CONTEXT* h264) memset(h264->pYUVData, 0, sizeof(h264->pYUVData)); memset(h264->iStride, 0, sizeof(h264->iStride)); - sys->MFShutdown(); - CoUninitialize(); + free(sys); h264->pSystemData = NULL; } @@ -494,15 +505,12 @@ static BOOL mf_init(H264_CONTEXT* h264) if (!sys) goto error; + h264->pSystemData = (void*) sys; /* http://decklink-sdk-delphi.googlecode.com/svn/trunk/Blackmagic%20DeckLink%20SDK%209.7/Win/Samples/Streaming/StreamingPreview/DecoderMF.cpp */ sys->mfplat = LoadLibraryA("mfplat.dll"); - if (!sys->mfplat) - { - free(sys); - goto error; - } - h264->pSystemData = (void*) sys; + if (!sys->mfplat) + goto error; sys->MFStartup = (pfnMFStartup) GetProcAddress(sys->mfplat, "MFStartup"); sys->MFShutdown = (pfnMFShutdown) GetProcAddress(sys->mfplat, "MFShutdown"); @@ -513,8 +521,7 @@ static BOOL mf_init(H264_CONTEXT* h264) sys->MFCreateMediaType = (pfnMFCreateMediaType) GetProcAddress(sys->mfplat, "MFCreateMediaType"); - if (!sys->MFStartup || !sys->MFShutdown || !sys->MFCreateSample - || !sys->MFCreateMemoryBuffer || !sys->MFCreateMediaType) + if (!mf_plat_loaded(sys)) goto error; CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);