Files
kinect/docs/spike-linux.md
kinect-bot e6d4e510d3
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python tracker (pytest) (push) Canceled after 0s
feat(contract,spikes): frozen IPC data contract + Linux/Windows spikes (wave 2)
2026-11-25 03:54:41 -05:00

24 KiB

Spike - Linux USB protocol + "does a real tracker skeletonize synthetic depth" (todo 3)

STATUS: Enumeration/attach path BLOCKED in this environment; skeletonization crux UNPROVEN here. This spike was executed on a Linux/WSL2 host (kernel 6.6.87.2-microsoft-standard-WSL2) with no usbip userspace, no OpenNI2, no NiTE2, and no Kinect viewer tools. The USB probes below are real, verbatim, observed command output. The Kinect v1 USB protocol section is drawn from the real libfreenect source (master @ commit 09a1f098, retrieved 2026-11-25) with per-fact file/line citations. The skeletonization crux was NOT executed (no host tracker is installed); it is documented as UNPROVEN with an exact runbook to prove it if the user supplies OpenNI2 + NiTE2. No skeleton result is claimed.

Closes plan GAP-4 (Linux half). Plan todo 3; blocks todo 8 (exact protocol) and todo 15 (fallback decision). References: libfreenect USB protocol (github.com/OpenKinect/libfreenect src/), OpenNI2-FreenectDriver, usbip/vhci-hcd, NiTE2 skeleton sample.

Evidence: .omo/evidence/task-3-webcam-kinect-emulator.probe.log (verbatim probe transcript).


0. Go/no-go summary (read this first)

Question Verdict in THIS environment Consequence
Can this box run the usbip/vhci device-attach path (plan todos 9/10)? NO - BLOCKED. The vhci-hcd module exists and modprobe -n resolves it, but the usbip userspace binary is absent and no vhci controller is present/loaded. The Linux device-attach proof (todos 9/10) cannot run here. It needs usbip/linux-tools installed and the module loaded, or a native-Linux host. The WSL2 kernel ships the module, so a custom-kernel rebuild is not strictly required - see §2.
Is the Kinect v1 (1414) USB protocol understood well enough to spec the todo-8 emitter? YES. Device topology, identity, init/control sequence, firmware handshake, and depth/video iso framing are extracted from libfreenect with citations (§3). One gap is flagged: the exact camera command-header byte layout (§3.4). Todo 8 has a concrete minimal descriptor/control set (§4).
Does a real host tracker skeletonize synthetic depth (the kill-gate crux)? UNPROVEN here. No OpenNI2/NiTE2 installed; cannot execute. Per the plan, the crux kill-gate is satisfied by whichever of spike 3 or spike 4 can first test it. This box cannot; spike 4 (Windows MS NUI) must carry it, OR the user installs OpenNI2+NiTE2 and runs §5 here. If NEITHER spike 3 nor spike 4 can test it before build waves 4-11, that is a HALT-and-re-plan condition (plan Execution strategy / todo 4).

1. Environment probe (verbatim)

Host: /home/athapa/kinect-wt/wave2. Commands run 2026-11-25; [exit=N] is the shell exit code.

$ pwd
/home/athapa/kinect-wt/wave2
$ uname -r
6.6.87.2-microsoft-standard-WSL2
[exit=0]
$ modprobe -n vhci-hcd 2>&1
[exit=0]
$ ls /sys/devices/platform/vhci_hcd* 2>&1
ls: cannot access '/sys/devices/platform/vhci_hcd*': No such file or directory
[exit=2]
$ which usbip
[exit=1]
$ lsmod | grep -i vhci
[exit=1]

Supplementary probes (module resolution + tracker/tooling inventory):

$ modprobe -n -v vhci-hcd 2>&1
insmod /lib/modules/6.6.87.2-microsoft-standard-WSL2/kernel/drivers/usb/common/usb-common.ko
insmod /lib/modules/6.6.87.2-microsoft-standard-WSL2/kernel/drivers/usb/core/usbcore.ko
insmod /lib/modules/6.6.87.2-microsoft-standard-WSL2/kernel/drivers/usb/usbip/usbip-core.ko
insmod /lib/modules/6.6.87.2-microsoft-standard-WSL2/kernel/drivers/usb/usbip/vhci-hcd.ko
[exit=0]
$ modinfo -F filename vhci-hcd 2>&1
/lib/modules/6.6.87.2-microsoft-standard-WSL2/kernel/drivers/usb/usbip/vhci-hcd.ko
[exit=0]

$ pkg-config --modversion libopenni2
/bin/bash: line 1: pkg-config: command not found
[exit=127]
$ dpkg-query -W libopenni2-0 libopenni2-dev
dpkg-query: no packages found matching libopenni2-0
dpkg-query: no packages found matching libopenni2-dev
[exit=1]
$ printenv OPENNI2_INCLUDE OPENNI2_REDIST NITE2_INCLUDE NITE2_REDIST
[exit=1]

$ for b in freenect-glview NiViewer SimpleViewer usbip python3 cmake gcc; do ...; done
freenect-glview -> MISSING
NiViewer -> MISSING
SimpleViewer -> MISSING
usbip -> MISSING
python3 -> /usr/bin/python3
cmake -> /home/athapa/.local/bin/cmake
gcc -> /usr/bin/gcc
$ ls /usr/lib/OpenNI2 ...
ls: cannot access '/usr/lib/OpenNI2': No such file or directory

2. vhci/usbip finding and its consequence

Finding (correction to the prior recon's expectation). The prior recon assumed the vhci-hcd kernel module is absent on this WSL2 kernel. That is not what this box shows. The module file is present and modprobe -n -v vhci-hcd resolves the full dependency chain (usb-common -> usbcore -> usbip-core -> vhci-hcd), and modinfo -F filename vhci-hcd returns the .ko path. So this stock WSL2 kernel (6.6.87.2-microsoft-standard-WSL2) does ship the usbip/vhci modules.

What is actually missing here is twofold, and it is still blocking:

  1. No usbip userspace (which usbip -> exit 1; linux-tools/usbip package not installed). The device-attach path needs the usbip tool (or a raw-gadget userspace server) to speak the USB/IP protocol to vhci-hcd.
  2. No vhci controller active (ls /sys/devices/platform/vhci_hcd* -> not found; lsmod | grep vhci -> exit 1, module not loaded). modprobe -n is a dry run; the module was never actually loaded, and nothing has created the vhci_hcd platform device / sysfs attach points.

Consequence for the plan. The Linux device-attach path (plan todos 9 and 10) is BLOCKED as the box stands, but the blocker is lighter than "needs a custom kernel":

  • The likely-sufficient fix on this WSL2 kernel: sudo modprobe vhci-hcd to load the module (which should create /sys/devices/platform/vhci_hcd.0 and /sys/.../vhci_hcd/), then install the usbip userspace (Debian/Ubuntu: apt install linux-tools-generic / usbip, or build tools/usb/usbip from the kernel tree). This must be verified, not assumed - the module file existing does not guarantee it loads cleanly under the MS WSL2 kernel, and WSL2's init may lack the udev/sysfs plumbing usbip expects.
  • The fallback if modprobe vhci-hcd fails to load or the sysfs attach points do not appear: a custom WSL2 kernel built with CONFIG_USBIP_VHCI_HCD=m/=y (.wslconfig -> kernel=), or a native-Linux host. Either way the attach path cannot be exercised in the current state.
  • Todo 9/10 acceptance (lsusb shows the Kinect VID/PID; freenect-glview/OpenNI enumerates it) cannot be met here today: usbip, freenect-glview, NiViewer/SimpleViewer, and the OpenNI2 runtime are all absent. These todos must be marked blocked on (a) usbip userspace + a loaded vhci controller and (b) an installed OpenNI2 (+FreenectDriver) viewer, or run on a native-Linux box.

cmake, gcc, and python3 are present, so the pure build/compile portions of later todos can run here; the device-attach and host-tracker portions cannot.

3. Kinect v1 (model 1414) USB protocol - what a virtual device must emit

All citations are to libfreenect master @ 09a1f098 (src/), retrieved 2026-11-25. Line numbers are from those retrieved files.

3.1 Composite topology and USB identity

The Kinect v1 is not a single composite USB device with multiple interfaces - it presents as three independent USB devices behind an internal hub, all with vendor 0x045e (Microsoft):

Sub-device idVendor idProduct Role
Camera 0x045e 0x02ae (PID_NUI_CAMERA) Depth + color/IR iso streams (the stream the tracker needs)
Audio 0x045e 0x02ad (PID_NUI_AUDIO) 4-mic array; also the firmware-upload target (§3.5)
Motor 0x045e 0x02b0 (PID_NUI_MOTOR) Tilt + accelerometer + LED (control transfers only)
  • Constants: freenect_internal.h:137-140 (VID_MICROSOFT 0x45e, PID_NUI_AUDIO 0x02ad, PID_NUI_CAMERA 0x02ae, PID_NUI_MOTOR 0x02b0).
  • Enumeration counts only the camera PID (fnusb_is_camera, usb_libusb10.c:75-79); the audio and motor siblings are then found by shared parent hub / same bus (fnusb_find_sibling_device, usb_libusb10.c:94-152, called from fnusb_open_subdevices, usb_libusb10.c:381-546). A virtual Kinect must therefore expose the three functions as sibling devices on a common (virtual) hub, not as one multi-interface device, so the host's sibling-matching succeeds.
  • Model discriminator: the original "1414" Kinect is identified by bcdDevice == 267 (0x010B) on the camera descriptor (usb_libusb10.c:431); any other bcdDevice (or PID_K4W_CAMERA) is treated as a newer model that drops the standalone motor and does motor control via the audio device (usb_libusb10.c:431-456, device_does_motor_control_with_audio). The emitter should report bcdDevice = 267 to be handled on the simple 1414 path, which also sets zero_plane_res = 322 (usb_libusb10.c:455; non-1414 uses 334 at usb_libusb10.c:438).
  • Camera interface: the host claims interface 0 of the camera device (libusb_claim_interface(dev->usb_cam.dev, 0), usb_libusb10.c:318, in fnusb_claim_camera at usb_libusb10.c:296). For the 1414 it does not change alt setting; the alt-setting-1 switch at usb_libusb10.c:329 is K4W-only. The camera device's interface 0 must carry the two iso IN endpoints (§3.3) with a non-zero alt setting whose iso endpoints have the right wMaxPacketSize.

3.2 Init / control-transfer sequence

Camera bring-up runs in freenect_camera_init (cameras.c:1251-1273), which performs a sequence of command reads before streaming:

Order Call Opcode Reply size Citation
1 freenect_fetch_reg_info 0x16 (ALGORITHM_PARAMS); cmd[5] = {ParamID 0x40, format 0, resolution, fps, offset} 118 bytes cameras.c:664-680
2 freenect_fetch_reg_pad_info 0x16 8 bytes cameras.c:742-756
3 freenect_fetch_zero_plane_info 0x04 (GET_FIXED_PARAMS) zero_plane_res = 322 for 1414 cameras.c:794-804
4 set video mode (RGB 640x480) + depth mode (11-bit 640x480) register writes (§3.3) - cameras.c:1265-1266
5 freenect_fetch_reg_const_shift 0x16 4 bytes cameras.c:769-783

These replies feed the registration/depth-to-mm math; a virtual device must return correctly-sized, self-consistent payloads (the host checks the exact byte counts and errors out otherwise, e.g. cameras.c:678-680). Each command carries an incrementing tag (cam_tag, freenect_internal.h:240) that the reply must echo.

Stream start is a sequence of register writes (write_register(dev, reg, value)), not special opcodes:

Depth start (freenect_start_depth, cameras.c:880-899):

write_register(0x105, 0x00)  // disable projector auto-cycle
write_register(0x06,  0x00)  // reset depth stream
write_register(0x12,  0x03)  // depth format: 0x03 = 11-bit (0x02 = 10-bit)
write_register(0x13,  0x01)  // depth resolution 640x480
write_register(0x14,  0x1e)  // depth FPS = 30
write_register(0x06,  0x02)  // START depth stream
write_register(0x17,  0x00)  // disable depth horizontal flip

Video start (freenect_start_video, cameras.c:1030-1050): writes mode/res/fps registers then write_register(0x05, 0x01) (or 0x03 with projector cycling) to start, and 0x47 = 0x00 to disable video hflip. Stop = 0x06=0x00 (depth) / 0x05=0x00 (video) (cameras.c:1065,1087). Mirror toggles live at register 0x17 (depth) and 0x47 (video) (flags.c:37-43).

The virtual device must accept and ACK all of these register writes (and the §3.2 reads) and only begin pushing iso frames after the 0x06=0x02 / 0x05=0x01 start writes.

3.3 Depth / video stream framing (iso)

  • Endpoints: depth = iso IN 0x82, video = iso IN 0x81 (cameras.c:871, :1021).
  • Per-packet size: DEPTH_PKTSIZE 1760, VIDEO_PKTSIZE 1920, each with a 12-byte header; so payload per packet is DEPTH_PKTDSIZE 1748, VIDEO_PKTDSIZE 1908 (freenect_internal.h:131-135). Iso transfer geometry on Linux: PKTS_PER_XFER 16, NUM_XFERS 16, buffer DEPTH_PKTBUF/VIDEO_PKTBUF = 1920 (usb_libusb10.h).
  • Packet header (struct pkt_hdr, cameras.c:76-85), 12 bytes, little-endian timestamp:
    uint8  magic[2] = {0x52, 0x42}   // 'R','B'  (checked at cameras.c:102)
    uint8  pad
    uint8  flag                      // start/mid/end-of-frame marker (below)
    uint8  unk1
    uint8  seq                       // per-packet sequence, increments; wraps at 256
    uint8  unk2
    uint8  unk3
    uint32 timestamp                 // little-endian (fn_le32), cameras.c:214
    
  • Frame markers (flag): base flag per stream - depth base 0x70, video base 0x80 (cameras.c:849, :913). Within a frame: Start-Of-Frame = base|1, Middle = base|2, End-Of-Frame = base|5 (cameras.c:110-112). So depth packets carry 0x71/0x72/0x75, video 0x81/0x82/0x85. The host re-syncs on these; the emitter must set them correctly or the host drops the frame (cameras.c:159-200).
  • Depth bit format (default): FREENECT_DEPTH_11BIT, 640x480 @ 30 fps. On the wire it is 11-bit packed (8 pixels per 11 bytes, MSB-first), unpacked by convert_packed11_to_16bit (cameras.c:345-374; depth-mode table cameras.c:65-73). A virtual device replaying depth must pack to this exact 11-bit layout for the default mode (register 0x12=0x03). The host can also request 10-bit (0x12=0x02), packed variants, registered, and MM modes (same table), but 11-bit is the libfreenect default and the simplest target.
  • Color default is Bayer/RGB 640x480 @ 30 (cameras.c:42-62); IR modes also exist. For the DEA / NUI depth+skeleton goal, depth is the load-bearing stream; color can start as a static/valid Bayer frame.

3.4 Gap: exact camera command-header byte layout (flagged for todo 8)

The register reads/writes in §3.2 go through libfreenect helpers send_cmd(...) / write_register(...) / read_register(...). In the retrieved master src/cameras.c (45,395 bytes, 1,296 lines) these helpers are used but their definitions are not present in that file or in any sibling src/*.c/*.h fetched (verified: the strings send_cmd / write_register first appear only at their call sites, lines 677 and 880, with no definition or forward declaration in cameras.c, usb_libusb10.c/.h, core.c, audio.c, registration.c/.h, loader.c/.h, flags.c/.h, cameras.h, or freenect_internal.h). The OpenKinect wiki protocol page (openkinect.org/wiki/Protocol_Documentation and /USB_Devices) returned HTTP 403 to automated fetch, so the camera command-header magic/length/opcode/tag byte order could not be captured from an authoritative source in this spike. Do not treat any specific camera command-header magic bytes as established by this spike.

What is established: the command envelope carries an incrementing cam_tag (freenect_internal.h:240) that the reply echoes, and uses the opcodes in §3.2's table (0x16 ALGORITHM_PARAMS, 0x04 GET_FIXED_PARAMS, plus the register read/write ops). The analogous audio bootloader envelope is fully visible (§3.5) and is a good structural model (magic | tag | len | cmd | addr).

Action for todo 8: extract the exact send_cmd/write_register byte layout by (a) reading the libfreenect send_cmd definition directly from a working local checkout/build of libfreenect (it is in the compiled library; the master tree webfetch elided it), and/or (b) a usbmon/Wireshark capture of a real or reference Kinect init. Treat §3.2/§3.3 as the behavioral contract and §3.4 as the one byte-level detail to pin before freezing the emitter's control parser.

3.5 Firmware-upload handshake

Firmware upload is audio-sub-device-only; the camera and motor need no firmware upload (loader.c; usb_libusb10.c:548-592). Flow:

  • A fresh audio device enumerates in bootloader mode with 1 interface. The host detects "already loaded" by fnusb_num_interfaces(&dev->usb_audio) >= 2 (usb_libusb10.c:554-555); if fewer, it uploads audios.bin (upload_firmware, loader.c:125) and waits for the device to re-enumerate with the same serial and 2 interfaces (usb_libusb10.c:620-660).
  • Bootloader command envelope (loader.c:84-90, check_version_string), 24-byte struct, all LE:
    uint32 magic = 0x06022009
    uint32 tag           // = audio_tag, increments per command (loader.c:120)
    uint32 bytes
    uint32 cmd
    uint32 addr
    ...                  // bootloader_command, dumped as 24 bytes (loader.c:38)
    
    Commands go out on bulk endpoint 1; replies come in on bulk endpoint 0x81 (loader.c:56,99,106). The status reply has magic == 0x0a6fe000 and must echo the tag (loader.c:62-68).

Implication for the virtual Kinect (minimal path): because only the audio device requires firmware, a first-cut emitter can present the audio device already in "loaded" state (>= 2 interfaces) so the host skips the firmware dance entirely, OR omit the audio device if the host stack tolerates a camera-only Kinect. The depth/color/skeleton path depends on the camera device (§3.1-3.3), which never needs a firmware upload. Audio firmware emulation is therefore deferrable and is not on the critical path to the depth-fidelity crux.

4. Minimal descriptor / control set for the todo-8 emitter

Concrete contract the emitter (todo 8) must satisfy to make a host stack enumerate and stream:

  1. Three sibling USB devices on one virtual hub, all idVendor=0x045e:
    • Camera idProduct=0x02ae, bcdDevice=267 (0x010B); one configuration; interface 0 with an alt setting exposing two iso IN endpoints: 0x82 (depth) and 0x81 (video), each with wMaxPacketSize sufficient for 1760/1920-byte packets (negotiated via fnusb_get_max_iso_packet_size).
    • Audio idProduct=0x02ad - present with >= 2 interfaces so the host treats firmware as already loaded (§3.5), or omitted if the target stack allows camera-only.
    • Motor idProduct=0x02b0 - control-transfer-only; needed for the 1414 path if the host enables the motor subdevice (FREENECT_DEVICE_MOTOR).
  2. Control endpoint 0 must answer:
    • Standard descriptor requests for the three devices above.
    • The command reads of §3.2 with correctly-sized replies: 0x16/ParamID 0x40 -> 118 bytes; 0x16 pad-info -> 8 bytes; 0x04 -> 322 bytes (zero-plane, 1414); 0x16 const-shift -> 4 bytes - each echoing the incrementing cam_tag. (Exact command-header byte layout: §3.4, pin before freeze.)
    • The register writes of §3.2 (0x105,0x06,0x12,0x13,0x14,0x17 for depth; 0x05,0x47 + mode regs for video), ACKed; only start iso frames after 0x06=0x02 / 0x05=0x01.
  3. Iso IN data on 0x82/0x81: 12-byte pkt_hdr (magic 'RB', correct flag SOF/MOF/EOF per §3.3, incrementing seq, LE timestamp) + payload, depth packed 11-bit (register 0x12=0x03) at 640x480, color as a valid Bayer/RGB 640x480 frame.
  4. No skeleton is ever emitted (the device never computes it; the host stack does) - consistent with plan todo 8's "Must NOT emit a skeleton."

This is the "minimal descriptor/control set" that unblocks todo 8. The only item not fully byte-specified by this spike is §3.4 (camera command-header framing).

5. Skeletonization crux - UNPROVEN here, with the exact runbook to prove it

Status: UNPROVEN in this environment. The crux question - does a real host tracker produce a stable, moving skeleton from synthetic (webcam-derived) articulated depth? - cannot be executed on this box: there is no OpenNI2 runtime and no NiTE2 tracker installed (§1: dpkg finds neither libopenni2-0 nor -dev; pkg-config absent; /usr/lib/OpenNI2 absent; OPENNI2_*/NITE2_* env unset; NiViewer/SimpleViewer MISSING). No skeleton result is claimed by this spike.

HALT condition (from the plan). The depth-fidelity crux is a kill-gate. Per the plan's Execution strategy and todo 4: the crux is satisfied by whichever of spike 3 (Linux, if NiTE2 supplied) or spike 4 (Windows MS NUI runtime) can first test it; if neither can confirm that a real host tracker skeletonizes synthetic depth before build waves 4-11, HALT and re-plan the depth model (e.g. a monocular-depth network producing a denser, more Kinect-like depth map) before committing to waves 4-11. Since this box cannot test it, the Linux half is UNPROVEN and the responsibility falls to spike 4 on the real Windows MS NUI runtime unless the user installs the Linux tracker and runs the procedure below.

Runbook to prove/disprove the crux on Linux (run only if the user supplies OpenNI2 + NiTE2). NiTE2 is EOL and non-redistributable: it is used only if the user already has it; it is never bundled.

  1. Install the attach + stream stack on a capable host (native Linux, or WSL2 after sudo modprobe vhci-hcd succeeds and creates /sys/devices/platform/vhci_hcd.0):
    sudo modprobe vhci-hcd && ls -d /sys/devices/platform/vhci_hcd*   # must now exist
    sudo apt-get install -y usbip linux-tools-generic                  # or build kernel tools/usb/usbip
    # OpenNI2 2.2.0.33+ (user-supplied or distro), e.g. unpack to ~/OpenNI2
    # Build libfreenect with the OpenNI2 driver:
    git clone https://github.com/OpenKinect/libfreenect && cd libfreenect
    mkdir build && cd build && cmake .. -DBUILD_OPENNI2_DRIVER=ON && make
    # copy lib/OpenNI2-FreenectDriver/libFreenectDriver.so into OpenNI2 Drivers/ repo
    
  2. Install NiTE2 (user-supplied) and set NITE2_REDIST/NITE2_INCLUDE; the NiTE2 package ships the UserViewer sample (skeleton tracker over OpenNI2).
  3. Bring up the virtual Kinect (todos 8+9): start the emitter, usbip attach it through vhci-hcd; confirm lsusb shows 045e:02ae and NiViewer (OpenNI SimpleViewer) renders the virtual device's depth. This proves enumeration + stream correctness.
  4. Feed two depth sequences via the emitter (pre-recorded, deterministic - never a live human):
    • A recorded real-person Kinect depth sequence (ground-truth control).
    • A synthetic articulated-depth sequence generated from webcam + pose (the thing under test).
  5. Run NiTE2 UserViewer against the virtual device for each sequence and record the observable:
    • PASS: UserViewer reports a tracked user and renders a stable skeleton whose joints move with the recorded subject on the synthetic sequence (not only the real one), held across several seconds without constant loss. Capture a screen recording + the NiTE user/skeleton state log to .omo/evidence/task-3-webcam-kinect-emulator.*.
    • FAIL: NiTE never acquires a user, or the skeleton is unstable/absent on synthetic depth while fine on real depth. Record the failure mode (no-user, flickering joints, wrong scale). A FAIL here (with spike 4 also unable to pass) is the HALT-and-re-plan trigger for the depth model.

Until step 5 passes on synthetic depth (here or in spike 4), the depth-fidelity crux stays UNPROVEN and waves 4-11 are gated.

6. What this spike did and did not do

  • Did (observed): environment/vhci/usbip capability probe (§1-2, verbatim); extracted the Kinect v1 1414 USB protocol from libfreenect master with citations (§3-4); confirmed the host tracker stack is absent (§1, §5).
  • Did NOT (honest gaps): did not stand up a usbip virtual device (no usbip userspace, no loaded vhci controller); did not render depth in a viewer (no freenect-glview/NiViewer); did not run any skeleton tracker (no OpenNI2/NiTE2); did not capture the camera command-header byte layout (§3.4; wiki returned HTTP 403, and master cameras.c elides the send_cmd/write_register bodies). No test was run that is reported as passing.