[vlc-devel] [PATCH 2/3] core: win32: do not load winmm.dll on startup, it's not a Known DLL
Steve Lhomme
robux4 at videolabs.io
Fri Mar 10 09:52:31 CET 2017
load it programmatically and only from System32
---
configure.ac | 4 +---
src/win32/specific.c | 24 ++++++++++++++++++------
src/win32/thread.c | 19 +++++++++++++++++--
3 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/configure.ac b/configure.ac
index ad4586afcb..8471e3fdf6 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 72c4fb7580..a39fae7251 100644
--- a/src/win32/specific.c
+++ b/src/win32/specific.c
@@ -32,6 +32,7 @@
#include "libvlc.h"
#include "../lib/libvlc_internal.h"
#include "config/vlc_getopt.h"
+#include "modules/modules.h"
#include <mmsystem.h>
#include <winsock.h>
@@ -55,11 +56,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 = win32_LoadSyslib(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);
@@ -205,9 +212,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 408524efdd..9695a045cf 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;
@@ -710,6 +713,10 @@ static union
LARGE_INTEGER freq;
} perf;
} clk;
+#if !VLC_WINSTORE_APP
+static MMRESULT (WINAPI *timeGetDevCaps_)(LPTIMECAPS ptc,UINT cbtc);
+static DWORD (WINAPI *timeGetTime_)(void);
+#endif
static mtime_t mdate_interrupt (void)
{
@@ -745,7 +752,7 @@ static mtime_t mdate_tick (void)
#include <mmsystem.h>
static mtime_t mdate_multimedia (void)
{
- DWORD ts = timeGetTime ();
+ DWORD ts = timeGetTime_ ();
/* milliseconds */
static_assert ((CLOCK_FREQ % 1000) == 0, "Broken frequencies ratio");
@@ -884,8 +891,16 @@ static void SelectClockSource (vlc_object_t *obj)
{
TIMECAPS caps;
+ HMODULE hWinmm = GetModuleHandle(TEXT("winmm.dll"));
+ if (!hWinmm)
+ abort();
+ timeGetDevCaps_ = (void*)GetProcAddress(hWinmm, "timeGetDevCaps");
+ timeGetTime_ = (void*)GetProcAddress(hWinmm, "timeGetTime");
+ if (!timeGetDevCaps_ || !timeGetTime_)
+ abort();
+
msg_Dbg (obj, "using multimedia timers as clock source");
- if (timeGetDevCaps (&caps, sizeof (caps)) != MMSYSERR_NOERROR)
+ if (timeGetDevCaps_ (&caps, sizeof (caps)) != MMSYSERR_NOERROR)
abort ();
msg_Dbg (obj, " min period: %u ms, max period: %u ms",
caps.wPeriodMin, caps.wPeriodMax);
--
2.11.1
More information about the vlc-devel
mailing list