From 9f2c1fc58c3a507c0f2a822299c85656f53bf944 Mon Sep 17 00:00:00 2001 From: Jean-Charles Mammana Date: Sun, 8 Mar 2026 20:57:38 +0100 Subject: [PATCH] Disable WLAN AutoConfig during streaming to eliminate Wi-Fi jitter Windows WLAN AutoConfig performs periodic background scans (~30s intervals) that cause 50-400ms latency spikes during game streaming over Wi-Fi. The existing media streaming mode (wlan_intf_opcode_media_streaming_mode) does not prevent these scans on all drivers. This disables WLAN AutoConfig (wlan_intf_opcode_autoconf_enabled) when entering low latency mode, which is the programmatic equivalent of: netsh wlan set autoconfig enabled=no interface="Wi-Fi" AutoConfig is explicitly re-enabled in exitLowLatencyMode() before closing the WLAN handle to ensure network discovery is restored. Also adds error logging for the existing media streaming mode call. --- src/PlatformSockets.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/PlatformSockets.c b/src/PlatformSockets.c index 41e7dd80..f165812f 100644 --- a/src/PlatformSockets.c +++ b/src/PlatformSockets.c @@ -969,6 +969,23 @@ void enterLowLatencyMode(void) { if (error == ERROR_SUCCESS) { Limelog("WLAN interface %d is now in low latency mode\n", i); } + else { + Limelog("WLAN interface %d failed to enter low latency mode (error %u)\n", i, error); + } + + // Disable WLAN AutoConfig to prevent OS-level background scanning that causes + // periodic latency spikes (50-400ms) independently of driver-level BG scan settings. + // This is the programmatic equivalent of: netsh wlan set autoconfig enabled=no interface="Wi-Fi" + // It will be automatically re-enabled when we close the WLAN handle in exitLowLatencyMode(). + value = FALSE; + error = pfnWlanSetInterface(WlanHandle, &wlanInterfaceList->InterfaceInfo[i].InterfaceGuid, + wlan_intf_opcode_autoconf_enabled, sizeof(value), &value, NULL); + if (error == ERROR_SUCCESS) { + Limelog("WLAN interface %d cyclic background scan disabled\n", i); + } + else { + Limelog("WLAN interface %d failed to disable cyclic background scan (error %u)\n", i, error); + } } } @@ -979,7 +996,28 @@ void enterLowLatencyMode(void) { void exitLowLatencyMode(void) { #if defined(LC_WINDOWS_DESKTOP) - // Closing our WLAN client handle will undo our optimizations + // Re-enable WLAN AutoConfig before closing the handle to ensure + // network discovery is restored even if the handle close doesn't undo it. + if (WlanHandle != NULL && pfnWlanSetInterface != NULL && pfnWlanEnumInterfaces != NULL) { + PWLAN_INTERFACE_INFO_LIST wlanInterfaceList; + if (pfnWlanEnumInterfaces(WlanHandle, NULL, &wlanInterfaceList) == ERROR_SUCCESS) { + DWORD i; + for (i = 0; i < wlanInterfaceList->dwNumberOfItems; i++) { + BOOL value = TRUE; + DWORD error = pfnWlanSetInterface(WlanHandle, &wlanInterfaceList->InterfaceInfo[i].InterfaceGuid, + wlan_intf_opcode_autoconf_enabled, sizeof(value), &value, NULL); + if (error == ERROR_SUCCESS) { + Limelog("WLAN interface %d cyclic background scan re-enabled\n", i); + } + else { + Limelog("WLAN interface %d failed to re-enable cyclic background scan (error %u)\n", i, error); + } + } + pfnWlanFreeMemory(wlanInterfaceList); + } + } + + // Closing our WLAN client handle will undo our other optimizations if (WlanHandle != NULL) { pfnWlanCloseHandle(WlanHandle, NULL); WlanHandle = NULL;