[vlc-commits] [Git][videolan/vlc][master] 7 commits: libvlc-module: remove Windows multimedia clock source choice

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Aug 11 12:13:36 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
f696c2fd by Steve Lhomme at 2022-08-11T12:02:28+00:00
libvlc-module: remove Windows multimedia clock source choice

It was removed in fdbbae70af8005bcaa771ef63968a2d023da267e

- - - - -
5d026038 by Steve Lhomme at 2022-08-11T12:02:28+00:00
win32: thread: simplify the mdate_interrupt conversion

QueryUnbiasedInterruptTime() provides ticks in 100 ns resolution, so we can use
VLC_TICK_FROM_MSFTIME().

- - - - -
9d215434 by Steve Lhomme at 2022-08-11T12:02:28+00:00
win32: thread: allow SetPriorityClass() in Win10 RS3 UAP builds

- - - - -
6d233f3f by Steve Lhomme at 2022-08-11T12:02:28+00:00
win32: threads: do not use mdate_perf as the default clock source

It relies on clk.perf.freq.QuadPart which is uninitialized and unknown until
SelectClockSource() is called. So it calls vlc_threads_setup() each time until
vlc_threads_setup() is called with the libvlc instance.

Except vlc_threads_setup(NULL) will crash on the
var_InheritBool(vlc, "high-priority") call. It's broken since
d0c4c5a9072c779bbec89a0600caf31e279478cd

Usable candidates at startup are:
* mdate_interrupt which is a counter in 100 ns, not a wall clock
* mdate_tick which is a counter in 1 ms, not a wall clock
* mdate_perf_100ns which is a clock in 100 ns but we don't know if the system
uses that resolution
* mdate_wall which is a clock in 100 ns resolution (slowest)

mdate_wall gives the better results and should provide a safe transition with
mdate_perf/mdate_perf_100ns values.

- - - - -
337fd69b by Steve Lhomme at 2022-08-11T12:02:28+00:00
win32: thread: simplify the clock selection code

Now that we always call it with a proper libvlc_int_t.

- - - - -
5fccc834 by Steve Lhomme at 2022-08-11T12:02:28+00:00
win32: thread: remove unneeded mdate_default and setup_lock

Since vlc_threads_setup is only called once with the proper libvlc_int_t, we
don't need a mechanism to check the first call, nor a special value to check
if it's the first call or not.

- - - - -
008e8cef by Steve Lhomme at 2022-08-11T12:02:28+00:00
libvlc-module: set the default clock-source value in the parameter definition

It might provide better documentation to the user. And we don't need to
reinvent the wheel to handle a default value in SelectClockSource().

- - - - -


2 changed files:

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


Changes:

=====================================
src/libvlc-module.c
=====================================
@@ -1140,17 +1140,11 @@ static const char* const ppsz_restore_playback_desc[] = {
 #ifdef _WIN32
 static const char *const clock_sources[] = {
     "", "interrupt", "tick",
-#ifndef VLC_WINSTORE_APP
-    "multimedia",
-#endif
     "perf", "wall",
 };
 
 static const char *const clock_sources_text[] = {
     N_("Auto"), "Interrupt time", "Windows time",
-#ifndef VLC_WINSTORE_APP
-    "Multimedia timers",
-#endif
     "Performance counters", "System time (DANGEROUS!)",
 };
 #endif
@@ -2091,7 +2085,7 @@ vlc_module_begin ()
 #endif
 
 #ifdef _WIN32
-    add_string( "clock-source", NULL, CLOCK_SOURCE_TEXT, NULL )
+    add_string( "clock-source", "perf", CLOCK_SOURCE_TEXT, NULL )
         change_string_list( clock_sources, clock_sources_text )
 #endif
 


=====================================
src/win32/thread.c
=====================================
@@ -43,6 +43,10 @@
 #include <time.h>
 #include <vlc_atomic.h>
 
+#ifndef NTDDI_WIN10_RS3
+#define NTDDI_WIN10_RS3  0x0A000004
+#endif
+
 /*** Static mutex and condition variable ***/
 static SRWLOCK super_lock = SRWLOCK_INIT;
 
@@ -526,7 +530,7 @@ static vlc_tick_t mdate_interrupt (void)
 
     /* hundreds of nanoseconds */
     static_assert ((10000000 % CLOCK_FREQ) == 0, "Broken frequencies ratio");
-    return ts / (10000000 / CLOCK_FREQ);
+    return VLC_TICK_FROM_MSFTIME(ts);
 }
 
 static vlc_tick_t mdate_tick (void)
@@ -577,13 +581,7 @@ static vlc_tick_t mdate_wall (void)
     return VLC_TICK_FROM_MSFTIME(s.QuadPart);
 }
 
-static vlc_tick_t mdate_default(void)
-{
-    vlc_threads_setup(NULL);
-    return mdate_perf();
-}
-
-static vlc_tick_t (*mdate_selected) (void) = mdate_default;
+static vlc_tick_t (*mdate_selected) (void) = mdate_wall;
 
 vlc_tick_t vlc_tick_now (void)
 {
@@ -631,16 +629,10 @@ void (vlc_tick_sleep)(vlc_tick_t delay)
     vlc_tick_wait (vlc_tick_now () + delay);
 }
 
-static BOOL SelectClockSource(vlc_object_t *obj)
+static void SelectClockSource(libvlc_int_t *obj)
 {
-    const char *name = "perf";
-    char *str = NULL;
-    if (obj != NULL)
-    {
-        str = var_InheritString(obj, "clock-source");
-        if (str != NULL)
-            name = str;
-    }
+    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");
@@ -676,7 +668,6 @@ static BOOL SelectClockSource(vlc_object_t *obj)
         abort ();
     }
     free (str);
-    return TRUE;
 }
 
 
@@ -692,22 +683,12 @@ unsigned vlc_GetCPUCount (void)
 
 
 /*** Initialization ***/
-static SRWLOCK setup_lock = SRWLOCK_INIT; /* FIXME: use INIT_ONCE */
 
 void vlc_threads_setup(libvlc_int_t *vlc)
 {
-    AcquireSRWLockExclusive(&setup_lock);
-    if (mdate_selected != mdate_default)
-    {
-        ReleaseSRWLockExclusive(&setup_lock);
-        return;
-    }
-
-    if (!SelectClockSource((vlc != NULL) ? VLC_OBJECT(vlc) : NULL))
-        abort();
-    assert(mdate_selected != mdate_default);
+    SelectClockSource(vlc);
 
-#ifndef VLC_WINSTORE_APP
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) || NTDDI_VERSION >= NTDDI_WIN10_RS3
     /* Raise default priority of the current process */
 #ifndef ABOVE_NORMAL_PRIORITY_CLASS
 #   define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
@@ -721,7 +702,6 @@ void vlc_threads_setup(libvlc_int_t *vlc)
             msg_Dbg(vlc, "could not raise process priority");
     }
 #endif
-    ReleaseSRWLockExclusive(&setup_lock);
 }
 
 #define LOOKUP(s) (((s##_) = (void *)GetProcAddress(h, #s)) != NULL)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1df170c89028f16d883408f4024bdc57b620ecf9...008e8cefd210847b0fc12be18869ecef9d3c0cb3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1df170c89028f16d883408f4024bdc57b620ecf9...008e8cefd210847b0fc12be18869ecef9d3c0cb3
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