[vlc-devel] [PATCH 3/3] win32: don't link directly to winmm

Steve Lhomme robux4 at videolabs.io
Thu Mar 9 16:02:37 CET 2017


It's not part of the known DLLs and so may not be automatically loaded from system32.
---
 configure.ac         |  4 +---
 src/win32/specific.c | 24 ++++++++++++++++++------
 src/win32/thread.c   | 14 ++++++++++++--
 3 files changed, 31 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..6625032212 100644
--- a/src/win32/specific.c
+++ b/src/win32/specific.c
@@ -29,6 +29,7 @@
 # define UNICODE
 #endif
 #include <vlc_common.h>
+#include <vlc_modules.h>
 #include "libvlc.h"
 #include "../lib/libvlc_internal.h"
 #include "config/vlc_getopt.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 = vlc_load_syslib("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..905337a7bd 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -743,9 +743,11 @@ static mtime_t mdate_tick (void)
 }
 #if !VLC_WINSTORE_APP
 #include <mmsystem.h>
+static MMRESULT (WINAPI *timeGetDevCaps_)(LPTIMECAPS ptc,UINT cbtc);
+static DWORD (WINAPI *timeGetTime_)(void);
 static mtime_t mdate_multimedia (void)
 {
-     DWORD ts = timeGetTime ();
+    DWORD ts = timeGetTime_ ();
 
     /* milliseconds */
     static_assert ((CLOCK_FREQ % 1000) == 0, "Broken frequencies ratio");
@@ -884,8 +886,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