[vlc-commits] [Git][videolan/vlc][3.0.x] win32: inhibit: restrict SystemParametersInfo calls to Windows XP

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Sep 3 08:13:47 UTC 2025



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
262a5d95 by Steve Lhomme at 2025-09-03T07:48:41+00:00
win32: inhibit: restrict SystemParametersInfo calls to Windows XP

As mentioned in !7651 the 2 different APIs we use may race each other.
So we select one based on the OS uses.

We use the same detection for XP vs Vista as already done in D3D9.

Co-authored-by: Icham AIDIBE <blouf at blouf.org>

- - - - -


1 changed file:

- modules/video_output/win32/inhibit.c


Changes:

=====================================
modules/video_output/win32/inhibit.c
=====================================
@@ -36,6 +36,9 @@ struct vlc_inhibit_sys
     vlc_cond_t cond;
     vlc_thread_t thread;
     bool signaled;
+#if _WIN32_WINNT < 0x0600 // _WIN32_WINNT_VISTA
+    bool isVistaOrGreater;
+#endif
     unsigned int mask;
 };
 
@@ -51,9 +54,14 @@ static void Inhibit (vlc_inhibit_t *ih, unsigned mask)
 
 static void RestoreStateOnCancel( void* p_opaque )
 {
-    VLC_UNUSED(p_opaque);
-    SetThreadExecutionState( ES_CONTINUOUS );
-    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, NULL, 0);
+#if _WIN32_WINNT < 0x0600 // _WIN32_WINNT_VISTA
+    vlc_inhibit_t *ih = (vlc_inhibit_t*)p_opaque;
+    vlc_inhibit_sys_t *sys = ih->p_sys;
+    if (!sys->isVistaOrGreater)
+        SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0);
+    else
+#endif
+        SetThreadExecutionState( ES_CONTINUOUS );
 }
 
 static void* Run(void* obj)
@@ -62,6 +70,14 @@ static void* Run(void* obj)
     vlc_inhibit_sys_t *sys = ih->p_sys;
     EXECUTION_STATE prev_state = ES_CONTINUOUS;
 
+#if _WIN32_WINNT < 0x0600 // _WIN32_WINNT_VISTA
+    HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+    if (likely(hKernel32 != NULL))
+        sys->isVistaOrGreater = GetProcAddress(hKernel32, "EnumResourceLanguagesExW") != NULL;
+    else
+        sys->isVistaOrGreater = false;
+#endif
+
     vlc_sem_post(&sys->sem);
     while (true)
     {
@@ -82,15 +98,23 @@ static void* Run(void* obj)
         if (suspend)
         {
             /* Prevent monitor from powering off */
-            prev_state = SetThreadExecutionState( ES_DISPLAY_REQUIRED |
+#if _WIN32_WINNT < 0x0600 // _WIN32_WINNT_VISTA
+            if (!sys->isVistaOrGreater)
+                SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
+            else
+#endif
+                prev_state = SetThreadExecutionState( ES_DISPLAY_REQUIRED |
                                                   ES_SYSTEM_REQUIRED |
                                                   ES_CONTINUOUS );
-            SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, NULL, 0);
         }
         else
         {
-            SetThreadExecutionState( prev_state );
-            SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, NULL, 0);
+#if _WIN32_WINNT < 0x0600 // _WIN32_WINNT_VISTA
+            if (!sys->isVistaOrGreater)
+                SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0);
+            else
+#endif
+                SetThreadExecutionState( prev_state );
         }
     }
     vlc_assert_unreachable();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/262a5d95f5f6f23ec7fd9aef02bcd5c36dae5fb2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/262a5d95f5f6f23ec7fd9aef02bcd5c36dae5fb2
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