[vlc-commits] [Git][videolan/vlc][master] 4 commits: win32: thread: document the clock sources by speed

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Aug 19 10:15:41 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
c6c5bf38 by Steve Lhomme at 2022-08-19T09:14:20+00:00
win32: thread: document the clock sources by speed

- - - - -
84357ef5 by Steve Lhomme at 2022-08-19T09:14:20+00:00
win32: thread: remove "wall" clock source option

It's slower than the "perf" clock source and doesn't provide any extra
precision. We don't need the UTC reference it provides.

We keep it as the default source until the user/default preferences are applied
since it provides an good granularity in a time where things may happen fast
(libvlc startup). The 10/16 millisecond granularity of the other sources are
not very useful there.

- - - - -
0dee1928 by Steve Lhomme at 2022-08-19T09:14:20+00:00
win32: thread: remove "tick" and "interrupt" clock sources

Their granularity are too small to provide a smooth playback.

- - - - -
5b4a021a by Steve Lhomme at 2022-08-19T09:14:20+00:00
win32: thread: bring back the winmm clock source

It is the default on 3.0 and might be useful when QueryPerformanceCounter() is
not accurate or too slow to call.

* https://docs.microsoft.com/en-US/troubleshoot/windows-server/performance/programs-queryperformancecounter-function-perform-poorly
* https://www.virtualdub.org/blog2/entry_106.html
* https://chromium.googlesource.com/chromium/src/base/+/refs/heads/main/time/time_win.cc

Partially reverts fdbbae70af8005bcaa771ef63968a2d023da267e. Now we link
statically with winmm. It should be on all Win7+ machines.

We also don't force a period value smaller than wPeriodMin.

- - - - -


3 changed files:

- src/Makefile.am
- src/libvlc-module.c
- src/win32/thread.c


Changes:

=====================================
src/Makefile.am
=====================================
@@ -432,6 +432,7 @@ if HAVE_WINSTORE
 libvlccore_la_SOURCES += posix/timer.c win32/dirs-uap.c
 else
 libvlccore_la_SOURCES += win32/timer.c win32/dirs.c
+libvlccore_la_LIBADD += -lwinmm
 endif
 libvlccore_la_LIBADD += -lbcrypt
 endif


=====================================
src/libvlc-module.c
=====================================
@@ -1139,13 +1139,17 @@ static const char* const ppsz_restore_playback_desc[] = {
 #define CLOCK_SOURCE_TEXT N_("Clock source")
 #ifdef _WIN32
 static const char *const clock_sources[] = {
-    "", "interrupt", "tick",
-    "perf", "wall",
+    "", "perf",
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+    "multimedia",
+#endif
 };
 
 static const char *const clock_sources_text[] = {
-    N_("Auto"), "Interrupt time", "Windows time",
-    "Performance counters", "System time (DANGEROUS!)",
+    N_("Auto"), "Performance counters",
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+    "Multimedia timers",
+#endif
 };
 #endif
 


=====================================
src/win32/thread.c
=====================================
@@ -43,6 +43,10 @@
 #include <time.h>
 #include <vlc_atomic.h>
 
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+#include <mmsystem.h>
+#endif
+
 #ifndef NTDDI_WIN10_RS3
 #define NTDDI_WIN10_RS3  0x0A000004
 #endif
@@ -520,29 +524,6 @@ static union
     } perf;
 } clk;
 
-static vlc_tick_t mdate_interrupt (void)
-{
-    ULONGLONG ts;
-    BOOL ret;
-
-    ret = QueryUnbiasedInterruptTime (&ts);
-    if (unlikely(!ret))
-        abort ();
-
-    /* hundreds of nanoseconds */
-    static_assert ((10000000 % CLOCK_FREQ) == 0, "Broken frequencies ratio");
-    return VLC_TICK_FROM_MSFTIME(ts);
-}
-
-static vlc_tick_t mdate_tick (void)
-{
-    ULONGLONG ts = GetTickCount64 ();
-
-    /* milliseconds */
-    static_assert ((CLOCK_FREQ % 1000) == 0, "Broken frequencies ratio");
-    return VLC_TICK_FROM_MS( ts );
-}
-
 static vlc_tick_t mdate_perf (void)
 {
     /* We don't need the real date, just the value of a high precision timer */
@@ -565,10 +546,6 @@ static vlc_tick_t mdate_perf_100ns(void)
     return VLC_TICK_FROM_MSFTIME(counter.QuadPart);
 }
 
-#if _WIN32_WINNT < _WIN32_WINNT_WIN8
-static void (WINAPI *SystemTimeAsFileTime_)(LPFILETIME) = GetSystemTimeAsFileTime;
-#endif // _WIN32_WINNT < _WIN32_WINNT_WIN8
-
 static vlc_tick_t mdate_wall (void)
 {
     FILETIME ts;
@@ -577,7 +554,7 @@ static vlc_tick_t mdate_wall (void)
 #if _WIN32_WINNT >= _WIN32_WINNT_WIN8
     GetSystemTimePreciseAsFileTime (&ts);
 #else // _WIN32_WINNT < _WIN32_WINNT_WIN8
-    SystemTimeAsFileTime_ (&ts);
+    GetSystemTimeAsFileTime (&ts);
 #endif // _WIN32_WINNT < _WIN32_WINNT_WIN8
     s.LowPart = ts.dwLowDateTime;
     s.HighPart = ts.dwHighDateTime;
@@ -586,6 +563,17 @@ static vlc_tick_t mdate_wall (void)
     return VLC_TICK_FROM_MSFTIME(s.QuadPart);
 }
 
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+static vlc_tick_t mdate_multimedia(void)
+{
+    DWORD ts = timeGetTime ();
+
+    /* milliseconds */
+    static_assert ((CLOCK_FREQ % 1000) == 0, "Broken frequencies ratio");
+    return VLC_TICK_FROM_MS(ts);
+}
+#endif
+
 static vlc_tick_t (*mdate_selected) (void) = mdate_wall;
 
 vlc_tick_t vlc_tick_now (void)
@@ -647,20 +635,29 @@ void (vlc_tick_sleep)(vlc_tick_t delay)
 
 static void SelectClockSource(libvlc_int_t *obj)
 {
+    // speed comparison / granularity / counts during sleep
+    // multimedia:102000 /    5 ms / no
+    // perf:      155612 / ~100 ns / yes
+    // wall:      181593 /  100 ns / yes
+
     char *str = var_InheritString(obj, "clock-source");
     const char *name = str != NULL ? str : "perf";
-    if (!strcmp (name, "interrupt"))
-    {
-        msg_Dbg (obj, "using interrupt time as clock source");
-        mdate_selected = mdate_interrupt;
-    }
-    else
-    if (!strcmp (name, "tick"))
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+    if (!strcmp (name, "multimedia"))
     {
-        msg_Dbg (obj, "using Windows time as clock source");
-        mdate_selected = mdate_tick;
+        TIMECAPS caps;
+
+        msg_Dbg (obj, "using multimedia timers as clock source");
+        if (timeGetDevCaps (&caps, sizeof (caps)) != MMSYSERR_NOERROR)
+            abort();
+        msg_Dbg (obj, " min period: %u ms, max period: %u ms",
+                 caps.wPeriodMin, caps.wPeriodMax);
+        mdate_selected = mdate_multimedia;
+
+        timeBeginPeriod(__MAX(5, caps.wPeriodMin));
     }
     else
+#endif
     if (!strcmp (name, "perf"))
     {
         msg_Dbg (obj, "using performance counters as clock source");
@@ -673,18 +670,6 @@ static void SelectClockSource(libvlc_int_t *obj)
             mdate_selected = mdate_perf;
     }
     else
-    if (!strcmp (name, "wall"))
-    {
-        msg_Dbg (obj, "using system time as clock source");
-#if _WIN32_WINNT < _WIN32_WINNT_WIN8
-        HMODULE h = GetModuleHandle(TEXT("kernel32.dll"));
-        SystemTimeAsFileTime_ = (void*)GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
-        if (unlikely(SystemTimeAsFileTime_ == NULL)) // win7
-            SystemTimeAsFileTime_ = GetSystemTimeAsFileTime;
-#endif // _WIN32_WINNT < _WIN32_WINNT_WIN8
-        mdate_selected = mdate_wall;
-    }
-    else
     {
         msg_Err (obj, "invalid clock source \"%s\"", name);
         abort ();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/21276001e002bba18571a28be38e61b7edf270db...5b4a021a2092c64fa1ca3799a5ab2096195f0b49

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/21276001e002bba18571a28be38e61b7edf270db...5b4a021a2092c64fa1ca3799a5ab2096195f0b49
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list