[vlc-commits] core: win32: do not load winmm.dll on startup, it's not a Known DLL

Steve Lhomme git at videolan.org
Fri Mar 10 19:05:21 CET 2017


vlc/vlc-2.2 | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Fri Mar 10 09:52:31 2017 +0100| [bb58955eaed816326a878f936534f7e9188e91e2] | committer: Jean-Baptiste Kempf

core: win32: do not load winmm.dll on startup, it's not a Known DLL

Modified-by: Jean-Baptiste Kempf <jb at videolan.org>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit d16bd4813a2842be220813e902462272ac8af4b0)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=bb58955eaed816326a878f936534f7e9188e91e2
---

 configure.ac         |  2 +-
 src/win32/specific.c | 23 +++++++++++++++++------
 src/win32/thread.c   | 27 +++++++++++++++++++++++----
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 320167d..8ad4a10 100644
--- a/configure.ac
+++ b/configure.ac
@@ -253,7 +253,7 @@ case "${host_os}" in
         # DEP, ASLR, NO SEH
         LDFLAGS="${LDFLAGS} -Wl,--nxcompat -Wl,--no-seh -Wl,--dynamicbase"
 
-        VLC_ADD_LIBS([libvlccore],[-lwinmm])
+        VLC_ADD_LIBS([libvlccore],[])
         VLC_ADD_LDFLAGS([vlc],[-mwindows])
         VLC_ADD_LIBS([win32text],[-lgdi32])
         AC_CHECK_PROGS(U2D, [unix2dos todos], unix2dos)
diff --git a/src/win32/specific.c b/src/win32/specific.c
index 2c052d1..407fd76 100644
--- a/src/win32/specific.c
+++ b/src/win32/specific.c
@@ -53,11 +53,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);
@@ -202,9 +208,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 2447adf..fe53b4b 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 vlc_mutex_t super_mutex;
@@ -688,6 +691,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)
@@ -721,10 +731,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");
@@ -836,9 +845,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;
@@ -847,6 +865,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 ();



More information about the vlc-commits mailing list