Files
kinect/fallback/windows-nui/README.md
T
kinect-bot ec169053c3
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s
fix(windows-nui): pin export ordinals to real Kinect10.dll (fixes ordinal 22 import), add 5 missing exports, MSVC-buildable
2026-11-25 15:20:55 -05:00

149 lines
8.4 KiB
Markdown

# 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
`FrameContract` triple 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 steady `QueryPerformanceCounter` clock, converts the latest
`FrameData` into a `NUI_SKELETON_FRAME` plus per-stream `INuiFrameTexture`s under
a `CRITICAL_SECTION`, then signals the app's manual-reset event handles.
`NuiSkeletonGetNextFrame` / `NuiImageStreamGetNextFrame` are fast copies /
pointer hand-offs that wait on those events with the caller's timeout, honoring
`E_NUI_FRAME_NO_DATA` / `SUPPRESS_NO_FRAME_DATA` / `TITLE_SETS_TRACKED_SKELETONS`
and resetting the skeleton event once the newest frame is delivered.
- **Core reuse** (compiled into the DLL): `core/mapping` drives `NuiTransformSmooth`
(per-skeleton, per-joint Holt filters keyed by tracking id) and
`NuiTransformDepthImageToSkeleton`; `core/synth` provides the packed-depth
helpers, `passthrough_color`, and `synthesize_infrared` used to fill the image
streams. `core/contract` is the shared-memory layout.
- **COM objects.** `INuiSensor` (`src/sensor_com.cpp`) returned by
`NuiCreateSensorByIndex/ById` delegates every method to the same
`VirtualKinectSensor` the flat exports drive. `INuiFrameTexture`
(`src/frame_texture.cpp`) implements `LockRect`/`GetLevelDesc`/`BufferLen`/
`Pitch`/`UnlockRect` with pitch and size matching the reported `NUI_SURFACE_DESC`
(packed depth → `width*2`, BGRA color → `width*4`). Unimplemented optional
methods (audio DMO, coordinate-mapper interface) return `E_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 (25 named + 1 NONAME, pinned ordinals)
The export ordinals match the real Kinect for Windows 1.8 `Kinect10.dll`
(v1.8.0.595) **exactly**, confirmed against a `dumpbin /exports` of the genuine
DLL: ordinal base 1, a NONAME function at ordinal 1, then ordinals 5-29 (2/3/4
unused), e.g. `NuiInitialize @14`, `NuiSetDeviceStatusCallback @22`. This matters
because DEA imports by ordinal, not by name (the loader error "the ordinal 22
could not be located" is a by-ordinal import of `NuiSetDeviceStatusCallback`); an
ordinal mismatch fails the import even when the name is present. The authoritative
map lives in `Kinect10.def`.
Functions whose synthesis is out of scope are present only so a by-ordinal import
resolves at load: `NuiGetAudioSource` (no audio) reports no source,
`NuiSkeletonCalculateBoneOrientations` returns S_OK (the game derives pose from
joint positions), and the undocumented `NuiCreateCoordinateMapperFromParameters` /
`NuiCreateDepthFilter` return E_NOTIMPL. This is a **superset** of the minimum DEA
imports; if a future `dumpbin /imports gamekdm.dll` reveals an additional symbol,
add it to `Kinect10.def` at its real ordinal 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:
```sh
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):
```sh
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.dll` beside a Kinect SDK 1.8
sample (SkeletonBasics-D2D) or `gamekdm.dll` and 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 `INuiSensor` vtable's
exact method order can only be byte-verified against a real app on Windows; it is
reproduced from public `NuiSensor.h` ordering and both COM and flat paths share
one implementation.
- **Spike-4 import reconciliation.** Confirm the exported set covers DEA's actual
`Kinect10.dll` imports and the requested stream resolution/bitness.
- **Tracker↔shim shared-memory name on Windows.** Python `multiprocessing`
shared-memory naming must be wired to `KINECT_SHIM_SHM`; verify end to end on
Windows.