fix(windows-nui): precise 30fps producer cadence (timeBeginPeriod(1)+deadline pacing) so sensor watchdog stays responsive
This commit is contained in:
1 parent
4209340387
commit
372dc29185
3 files changed
+19
-3
No files matched your search
@@ -44,4 +44,4 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(kinect10 PRIVATE ole32 oleaut32 uuid)
|
||||
target_link_libraries(kinect10 PRIVATE ole32 oleaut32 uuid winmm)
|
||||
@@ -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}"
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "sensor.h"
|
||||
|
||||
#include <timeapi.h>
|
||||
|
||||
#include "shim_log.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -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<int64_t>(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<DWORD>(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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user