8.2 KiB
fallback/windows-nui/ — clean-room Kinect10.dll NUI shim (todo 14)
A clean-room drop-in Kinect10.dll that implements the Kinect for Windows 1.8
NUI export surface a Kinect v1 app (DanceEvolution Arcade first) imports, sourcing
skeleton and depth/color directly from the shared core engine instead of a real
sensor. It is the library-layer Windows fallback (plan GAP-6); the device-level
USB path (todos 8/9/12) is the primary route, and this shim is the independent
surface that proves playability (IS-3/IS-4) by direct injection into the real MS
NUI runtime's consumer — i.e. it feeds the game, not the host skeletonizer.
Clean-room firewall
Every struct, enum value, packing rule, COM vtable, and exported-function
signature in include/nui_abi.h and include/nui_interfaces.h is derived SOLELY
from public Microsoft Kinect SDK 1.8 header knowledge (NuiApi.h,
NuiSkeleton.h, NuiImageCamera.h, NuiSensor.h) as distilled into
.omo/design/nui-contracts.md. No GPLv3 third-party source (e.g. KinectFaker)
was read or copied. These declarations are ABI/interoperability facts required
for a drop-in replacement; all synthesis logic is the shared core
(core/mapping, core/synth) reused unmodified.
Architecture
tracker (Python, todo 5) Kinect10.dll shim (this module) game
MediaPipe → core/mapping+synth ┌─────────────────────────────────┐ (DEA / SDK sample)
→ FrameContract shared memory ──────────►│ FrameSource (seqlock reader) │
(core/contract/contract.h) │ │ │
│ producer thread @ ~30 Hz │
│ core/mapping → NUI_SKELETON_* │◄── NuiSkeletonGetNextFrame
│ core/synth → depth/color/IR │◄── NuiImageStream*
│ SetEvent(app skeleton/image ev) │
└─────────────────────────────────┘
- Single producer, newest-wins. The shim is a consumer of the exact
FrameContracttriple buffer the tracker publishes (core/contract), read with the same seqlock protocol (src/frame_source.cpp). The USB emitter and this shim are two consumers of one producer, so skeleton/depth stay identical across both Windows paths. - ~30 Hz event model (
src/sensor.cpp, nui-contracts §3). One producer thread ticks on a steadyQueryPerformanceCounterclock, converts the latestFrameDatainto aNUI_SKELETON_FRAMEplus per-streamINuiFrameTextures under aCRITICAL_SECTION, then signals the app's manual-reset event handles.NuiSkeletonGetNextFrame/NuiImageStreamGetNextFrameare fast copies / pointer hand-offs that wait on those events with the caller's timeout, honoringE_NUI_FRAME_NO_DATA/SUPPRESS_NO_FRAME_DATA/TITLE_SETS_TRACKED_SKELETONSand resetting the skeleton event once the newest frame is delivered. - Core reuse (compiled into the DLL):
core/mappingdrivesNuiTransformSmooth(per-skeleton, per-joint Holt filters keyed by tracking id) andNuiTransformDepthImageToSkeleton;core/synthprovides the packed-depth helpers,passthrough_color, andsynthesize_infraredused to fill the image streams.core/contractis the shared-memory layout. - COM objects.
INuiSensor(src/sensor_com.cpp) returned byNuiCreateSensorByIndex/ByIddelegates every method to the sameVirtualKinectSensorthe flat exports drive.INuiFrameTexture(src/frame_texture.cpp) implementsLockRect/GetLevelDesc/BufferLen/Pitch/UnlockRectwith pitch and size matching the reportedNUI_SURFACE_DESC(packed depth →width*2, BGRA color →width*4). Unimplemented optional methods (audio DMO, coordinate-mapper interface) returnE_NOTIMPL, never crash.
Integration seam
The shim opens a named shared-memory region (OpenFileMappingW) named by the
environment variable KINECT_SHIM_SHM (default kinect_virtual_frames). The
tracker must publish its FrameContractPublisher region under the same name on
Windows. When the region is absent or empty, the producer still ticks at 30 Hz and
publishes a no-player frame (dwTrackingID = 0, zeroed depth/color), so the host
app never blocks and NuiSkeletonGetNextFrame reports no tracked skeleton rather
than hanging.
Exported NUI surface (21 functions, undecorated)
NuiGetSensorCount, NuiCreateSensorByIndex, NuiCreateSensorById,
NuiInitialize, NuiShutdown, NuiSetDeviceStatusCallback,
NuiSkeletonTrackingEnable, NuiSkeletonTrackingDisable,
NuiSkeletonGetNextFrame, NuiSkeletonSetTrackedSkeletons, NuiTransformSmooth,
NuiTransformDepthImageToSkeleton, NuiImageStreamOpen,
NuiImageStreamGetNextFrame, NuiImageStreamReleaseFrame,
NuiImageStreamSetImageFrameFlags, NuiImageStreamGetImageFrameFlags,
NuiImageGetColorPixelCoordinatesFromDepthPixel, NuiCameraElevationSetAngle,
NuiCameraElevationGetAngle, NuiSetFrameEndEvent.
This is a superset of the minimum DEA imports named in the plan; the exact DEA
import list comes from spike todo 4 (dumpbin /imports gamekdm.dll), which is
Windows-gated. Over-exporting is safe (a drop-in must export no fewer than the
game imports); if the spike reveals an additional symbol, add it to Kinect10.def
and a stub in src/exports.cpp.
Decoration
__stdcall/WINAPI is used throughout, but the export names are undecorated
(NuiInitialize, not _NuiInitialize@4) to match the real Kinect10.dll that the
game's import table binds to. This is achieved with Kinect10.def (plain names) +
-Wl,--enable-stdcall-fixup,--kill-at. On x64 there is no @N decoration; the
same .def drives both arches.
Cross-build (on this Linux/WSL2 box, no Windows needed)
Provisioned mingw-w64 cross-compilers live at $HOME/.local/mingw-root/usr/bin
(i686-w64-mingw32-g++-posix for 32-bit — DEA's likely arch — and
x86_64-w64-mingw32-g++-win32 for 64-bit). Build both DLLs and audit exports:
cd fallback/windows-nui
bash build.sh # builds build/Kinect10-x86.dll and build/Kinect10-x64.dll
build.sh cross-compiles the six shim sources plus the four reused core sources
into each DLL, links ole32/oleaut32/uuid statically, and dumps the export
name table for both arches. Override MINGW_BIN, CXX32, CXX64 to retarget.
Equivalent CMake path (authoritative MSVC build is run on the user's Windows box):
cmake -S . -B build-x86 -DCMAKE_TOOLCHAIN_FILE=toolchain-mingw-x86.cmake
cmake --build build-x86
cmake -S . -B build-x64 -DCMAKE_TOOLCHAIN_FILE=toolchain-mingw-x64.cmake
cmake --build build-x64
Export audit (what was verified here)
Both DLLs are real PE images (file: PE32 … Intel i386 and
PE32+ … x86-64), and the export name table (objdump -p … | grep '+base[')
lists all 21 symbols above, undecorated, on both arches — 0 missing, 0 extra,
0 decorated. Full output: .omo/evidence/task-14-webcam-kinect-emulator.log.
[~] Runtime gate — BLOCKED, deferred to the user's Windows box
This Linux/WSL2 host cannot run a Kinect v1 app or the MS NUI runtime, so the following are not verified here and are the acceptance surface for todo 13/F5 on Windows:
- In-game / runtime pass. Placing
Kinect10.dllbeside a Kinect SDK 1.8 sample (SkeletonBasics-D2D) orgamekdm.dlland confirming it tracks without a sensor. Unverified here. - INuiSensor vtable byte-order. The flat C exports are the primary, Linux-
auditable surface and most 1.8 titles bind them. The large
INuiSensorvtable's exact method order can only be byte-verified against a real app on Windows; it is reproduced from publicNuiSensor.hordering and both COM and flat paths share one implementation. - Spike-4 import reconciliation. Confirm the exported set covers DEA's actual
Kinect10.dllimports and the requested stream resolution/bitness. - Tracker↔shim shared-memory name on Windows. Python
multiprocessingshared-memory naming must be wired toKINECT_SHIM_SHM; verify end to end on Windows.