vlc | branch: master | Steve Lhomme <[email protected]> | Fri Mar 10 09:52:31 2017 +0100| [d16bd4813a2842be220813e902462272ac8af4b0] | committer: Jean-Baptiste Kempf
core: win32: do not load winmm.dll on startup, it's not a Known DLL Modified-by: Jean-Baptiste Kempf <[email protected]> Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d16bd4813a2842be220813e902462272ac8af4b0 --- configure.ac | 4 +--- src/win32/specific.c | 23 +++++++++++++++++------ src/win32/thread.c | 27 +++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index ad4586a..8471e3f 100644 --- a/configure.ac +++ b/configure.ac @@ -315,9 +315,7 @@ AS_IF([test "${SYS}" = "mingw32"],[ LIBCOM="" VLC_ADD_LIBS([libvlccore], [-lruntimeobject]) AC_LIBOBJ([gai_strerror]) - ],[ - VLC_ADD_LIBS([libvlccore],[-lwinmm]) - ]) + ],[]) AC_SUBST(LIBCOM) ]) AC_DEFINE_UNQUOTED(VLC_WINSTORE_APP, ${vlc_winstore_app}, [Define to 1 if you want to build for Windows Store apps]) diff --git a/src/win32/specific.c b/src/win32/specific.c index 455b318..37f0b99 100644 --- a/src/win32/specific.c +++ b/src/win32/specific.c @@ -55,11 +55,17 @@ static int system_InitWSA(int hi, int lo) /** * Initializes MME timer, Winsock. */ +static HMODULE hWinmm = INVALID_HANDLE_VALUE; void system_Init(void) { -#if !VLC_WINSTORE_APP - timeBeginPeriod(5); -#endif + hWinmm = LoadLibrary(TEXT("winmm.dll")); + if (hWinmm) + { + MMRESULT (WINAPI * timeBeginPeriod)(UINT); + timeBeginPeriod = (void*)GetProcAddress(hWinmm, "timeBeginPeriod"); + if (timeBeginPeriod) + timeBeginPeriod(5); + } if (system_InitWSA(2, 2) && system_InitWSA(1, 1)) fputs("Error: cannot initialize Winsocks\n", stderr); @@ -204,9 +210,14 @@ void system_Configure( libvlc_int_t *p_this, int i_argc, const char *const ppsz_ */ void system_End(void) { -#if !VLC_WINSTORE_APP - timeEndPeriod(5); -#endif + if (hWinmm) + { + MMRESULT (WINAPI * timeEndPeriod)(UINT); + timeEndPeriod = (void*)GetProcAddress(hWinmm, "timeEndPeriod"); + if (timeEndPeriod) + timeEndPeriod(5); + FreeLibrary(hWinmm); + } /* XXX: In theory, we should not call this if WSAStartup() failed. */ WSACleanup(); diff --git a/src/win32/thread.c b/src/win32/thread.c index 408524e..fca34cb 100644 --- a/src/win32/thread.c +++ b/src/win32/thread.c @@ -38,6 +38,9 @@ #include <limits.h> #include <errno.h> #include <time.h> +#if !VLC_WINSTORE_APP +#include <mmsystem.h> +#endif /*** Static mutex and condition variable ***/ static CRITICAL_SECTION super_mutex; @@ -709,6 +712,13 @@ static union { LARGE_INTEGER freq; } perf; +#if !VLC_WINSTORE_APP + struct + { + MMRESULT (WINAPI *timeGetDevCaps)(LPTIMECAPS ptc,UINT cbtc); + DWORD (WINAPI *timeGetTime)(void); + } multimedia; +#endif } clk; static mtime_t mdate_interrupt (void) @@ -742,10 +752,9 @@ static mtime_t mdate_tick (void) return ts * (CLOCK_FREQ / 1000); } #if !VLC_WINSTORE_APP -#include <mmsystem.h> static mtime_t mdate_multimedia (void) { - DWORD ts = timeGetTime (); + DWORD ts = clk.multimedia.timeGetTime (); /* milliseconds */ static_assert ((CLOCK_FREQ % 1000) == 0, "Broken frequencies ratio"); @@ -884,9 +893,18 @@ static void SelectClockSource (vlc_object_t *obj) { TIMECAPS caps; + HMODULE hWinmm = GetModuleHandle(TEXT("winmm.dll")); + if (!hWinmm) + goto perf; + + clk.multimedia.timeGetDevCaps = (void*)GetProcAddress(hWinmm, "timeGetDevCaps"); + clk.multimedia.timeGetTime = (void*)GetProcAddress(hWinmm, "timeGetTime"); + if (!clk.multimedia.timeGetDevCaps || !clk.multimedia.timeGetTime) + goto perf; + msg_Dbg (obj, "using multimedia timers as clock source"); - if (timeGetDevCaps (&caps, sizeof (caps)) != MMSYSERR_NOERROR) - abort (); + if (clk.multimedia.timeGetDevCaps (&caps, sizeof (caps)) != MMSYSERR_NOERROR) + goto perf; msg_Dbg (obj, " min period: %u ms, max period: %u ms", caps.wPeriodMin, caps.wPeriodMax); mdate_selected = mdate_multimedia; @@ -895,6 +913,7 @@ static void SelectClockSource (vlc_object_t *obj) else if (!strcmp (name, "perf")) { + perf: msg_Dbg (obj, "using performance counters as clock source"); if (!QueryPerformanceFrequency (&clk.perf.freq)) abort (); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
