From 372dc2918548db3bf15a6a6ed5b2cdc61bb7ba7a Mon Sep 17 00:00:00 2001 From: kinect-bot Date: Wed, 25 Nov 2026 16:47:13 -0500 Subject: [PATCH] fix(windows-nui): precise 30fps producer cadence (timeBeginPeriod(1)+deadline pacing) so sensor watchdog stays responsive --- fallback/windows-nui/CMakeLists.txt | 2 +- fallback/windows-nui/build.sh | 2 +- fallback/windows-nui/src/sensor.cpp | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fallback/windows-nui/CMakeLists.txt b/fallback/windows-nui/CMakeLists.txt index e15b619..0434607 100644 --- a/fallback/windows-nui/CMakeLists.txt +++ b/fallback/windows-nui/CMakeLists.txt @@ -44,4 +44,4 @@ else() ) endif() -target_link_libraries(kinect10 PRIVATE ole32 oleaut32 uuid) +target_link_libraries(kinect10 PRIVATE ole32 oleaut32 uuid winmm) diff --git a/fallback/windows-nui/build.sh b/fallback/windows-nui/build.sh index 24420ce..0c54f0c 100755 --- a/fallback/windows-nui/build.sh +++ b/fallback/windows-nui/build.sh @@ -27,7 +27,7 @@ SRCS=( INCLUDES=(-I"${HERE}/include" -I"${HERE}/src" -I"${CORE}") COMMON_FLAGS=(-std=c++17 -O2 -Wall -Wextra -shared -static -static-libgcc -static-libstdc++) -LINK_FLAGS=(-Wl,--enable-stdcall-fixup -Wl,--kill-at -lole32 -loleaut32 -luuid) +LINK_FLAGS=(-Wl,--enable-stdcall-fixup -Wl,--kill-at -lole32 -loleaut32 -luuid -lwinmm) mkdir -p "${OUT}" diff --git a/fallback/windows-nui/src/sensor.cpp b/fallback/windows-nui/src/sensor.cpp index 328a077..9150a7f 100644 --- a/fallback/windows-nui/src/sensor.cpp +++ b/fallback/windows-nui/src/sensor.cpp @@ -1,5 +1,7 @@ #include "sensor.h" +#include + #include "shim_log.h" #include @@ -560,6 +562,7 @@ void VirtualKinectSensor::ProducerLoop() { QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&start); uint32_t frame_number = 0; + timeBeginPeriod(1); while (WaitForSingleObject(stop_event_, 0) != WAIT_OBJECT_0) { LARGE_INTEGER now; @@ -616,8 +619,21 @@ void VirtualKinectSensor::ProducerLoop() { SetEvent(frame_end); } - WaitForSingleObject(stop_event_, kFramePeriodMs); + const int64_t target_qpc = + start.QuadPart + + static_cast(frame_number) * frequency.QuadPart / 30; + QueryPerformanceCounter(&now); + const int64_t remaining_qpc = target_qpc - now.QuadPart; + DWORD wait_ms = 0; + if (remaining_qpc > 0) { + wait_ms = static_cast(remaining_qpc * 1000 / frequency.QuadPart); + if (wait_ms > 100u) { + wait_ms = 100u; + } + } + WaitForSingleObject(stop_event_, wait_ms); } + timeEndPeriod(1); ShimLog("producer loop EXIT at tick=%u (stop_event signalled)", frame_number); }