@kirknock/node-openxr-video-source
v0.1.1
Published
Live phone camera feeds in a Node.js OpenXR scene: the xrcam protocol client (encrypted WebSocket, reconnects, pause/resume), H.264 decoding through the system's libavcodec (VAAPI, NVDEC or software, via koffi) in one worker per feed, and Babylon.js video
Maintainers
Readme
@kirknock/node-openxr-video-source
Live phone camera feeds as video panes in a Node.js OpenXR scene (Babylon.js,
WebGL2 or WebGPU). Each feed is one phone running the Android camera app
(node-openxr-android-camera-server, protocol in its PROTOCOL.md).
video-source-api/: the xrcam protocol client, no Babylon:protocol.ts,stream-choice.tsandxrcam-socket.ts(copies fromnode-openxr-android-camera-web, kept in step with it), andVideoPanelAPI(video-panel-api.ts: the lasting connection, reconnects, pause/resume,supportedModes()).video-source-node/: the video in the scene:libav.ts+h264-decoder.ts(libavcodec through koffi),feed-worker.ts+video-feed.ts(one worker per feed),frame-slots.ts(shared-memory triple buffer),nv12-material.ts,video-pane.ts(VideoPane),video-pane-plugin.ts(VideoPanePlugin),video-pane-config.ts(VideoPaneConfig, the"videoPanes"section of an app's config file). Tool:openxr-video-probe-decoder.
Linux only, Node.js ≥ 24. Decoding uses the system's libavcodec, FFmpeg 6, 7
or 8 (Ubuntu 24.04: libavcodec60). Hardware decoding needs the VAAPI driver
(vainfo should list H.264) or the NVIDIA driver; a hardware decoder that
doesn't open falls back to software, and the log says why.
openxr-video-probe-decoder lists which decoders open.
Install
npm install @kirknock/node-openxr-video-source @babylonjs/[email protected] [email protected] @napi-rs/[email protected]The peers are shared with the @kirknock/node-openxr-* platform packages.
Modules are imported by path, e.g.
@kirknock/node-openxr-video-source/video-source-node/video-pane-plugin.js.
Usage
import { VideoPaneConfig } from "@kirknock/node-openxr-video-source/video-source-node/video-pane-config.js";
import { VideoPanePlugin } from "@kirknock/node-openxr-video-source/video-source-node/video-pane-plugin.js";
const config = VideoPaneConfig.fromJSON(json.videoPanes ?? {});
const plugin = new VideoPanePlugin(scene, xr, config); // one feed + pane per entry
// later: plugin.storePoses() writes the panes' poses back into config; save it yourselfVideoPane draws its messages ("Waiting for feed", "Paused") with the font
at assets/fonts/DejaVuSans-Bold.ttf, relative to the working directory
(the app ships it); without it the system's font is used.
How the video moves:
- One worker thread per feed (
feed-worker.ts) holds the WebSocket and its decryption, the protocol and the decoder, so the XR frame loop never waits on the network. - Falling behind: when the oldest waiting frame is more than 100 ms old, the worker drops frames to the next keyframe and asks the phone for one.
- Handover: the decoded picture, packed NV12, goes into a triple buffer in
shared memory (
frame-slots.ts); neither side waits. - Upload: each rendered frame uploads it, only when new, into an R8 luma
and an RG8 chroma texture; a GLSL or WGSL shader converts it to RGB
(
nv12-material.ts).
Development
npm ci
npm run build # dist/
npm run lint && npm run typecheck
npm run test:pure # config, xrcam protocol, frame slots, decoder, a feed against fake phones (libavcodec 60+)
npm run test:gl # EGL/GLES 3 context (llvmpipe ok): VideoPane's NV12 shader
npm run probe:decoder
npm run fake-phone -- <key> [port] # serves tests/fixtures/camera.xrcam over xrcam, no phone neededTests run on the nodexr-test runner from
@kirknock/node-openxr-core.
Releasing
Bump version in package.json, commit, then push a matching tag:
npm version patch # or minor / major / prerelease --preid beta
git push --follow-tagsThe Release workflow checks the tag, lints, runs the pure and gl tests (gl
on Mesa llvmpipe), publishes to npm via trusted publishing (with provenance)
and creates a GitHub release with the tarball attached.
License
MIT
