Command-line tools: labstream top and labstream play (roadmap step 12)¶
Status: complete (crates/labstream-cli). docs/roadmap.md, step 12,
gives the success criterion.
The purpose¶
Developers and lab operators need two small tools in the library:
labstream top. Discovers active LSL streams on the network and shows each stream in a terminal with its measured rate, transport path, latency, lost count, drop count, resend count, recoveries, and gap count. It reads those values from the step 11 health API (Inlet::health) and updates one time each second.labstream play. Reads an XDF 1.0 recording and publishes its streams as live LSL outlets with the exact sample bits and timestamp intervals of the file. A developer can test Phasic or another consumer with no hardware.
labstream top¶
| Option | Behavior |
|---|---|
--interval SECONDS |
Update period in seconds (default 1.0). |
--count N |
Stop after N updates (default runs until interrupted). |
--session ID |
Override the session query (default uses the active configuration). |
--no-clear |
Print each table below the previous one with no terminal clear sequence. |
--json |
Write one JSON object for each update tick with exact InletHealth fields. |
Each tick drains pending samples on every open inlet to measure the live rate
in Hz, reads Inlet::health, and writes the updated table or JSON line.
labstream play¶
labstream play <FILE.xdf> [--speed FACTOR] [--loop] [--wait] [--stream NAME] [--name-prefix PREFIX] [--linger SECONDS]
| Option | Behavior |
|---|---|
<FILE.xdf> |
Path to an uncompressed XDF 1.0 file. |
--speed FACTOR |
Wall-clock pacing multiplier (default 1.0). |
--loop |
Replay continuously, advancing timestamps monotonically across loops. |
--wait |
Wait until at least one consumer connects to each outlet before playback starts. |
--stream NAME |
Replay only streams whose name matches NAME. Repeat or separate with commas. |
--name-prefix PREFIX |
Prepend PREFIX to each published stream name. |
--linger SECONDS |
Keep outlets open after the last sample so consumers pull the tail (default 0.3). |
XDF 1.0 decoding and timing¶
crates/labstream-cli/src/xdf.rs parses XDF 1.0 chunks with no external
dependency:
- Tag 1 (
FileHeader): file version XML. - Tag 2 (
StreamHeader): 4-byte stream ID and full<info>XML (parsed withStreamInfo::from_fullinfo_xml, preserving<desc>channel metadata). - Tag 3 (
Samples): 4-byte stream ID, varlen sample count, per-sample timestamp byte width (0deduced fromnominal_srateor8IEEE-754 LEf64), and raw little-endian channel values (float32,double64,int32,int16,int8,int64, and varlenstring). - Tag 4 (
ClockOffset): 4-byte stream ID, collection time, and clock offset. The first clock offset of each stream aligns multiple streams onto one timeline without distorting inter-sample intervals. - Tag 5 (
Boundary) and Tag 6 (StreamFooter): skipped cleanly.
For each stream s with first sample timestamp t0, first clock offset
off, and global minimum aligned time t_min, sample i at file timestamp
t_i is published with timestamp:
For any two samples i and j of the same stream, published_ts(j) -
published_ts(i) equals t_j - t_i, and every channel value keeps the exact
bits read from the XDF file.
Platform support¶
Both labstream top and labstream play use standard Rust threads, I/O, and
labstream-net. Linux, Windows, and macOS get the exact same behavior.
Measured results¶
cargo test -p labstream-cli: all 10 unit and live tests pass in 1.5 s, covering all seven sample formats (bit-exactf32/f64/integers/strings with NUL bytes), deduced XDF timestamps, real LabRecorder recordingconformance/captures/verify.xdf(6 streams, 50-sample live replay with bit-exact values and intervals within1e-8s), andTopMonitormatchingInlet::healthat a 1 s update cadence.- Live smoke test (
labstream play conformance/captures/verify.xdf --stream Verify-rustobserved bylabstream top --count 3 --no-clear):topdiscoveredVerify-rust(EEG, 8 ch) and reported live rate (98.0 Hz), path (UDP), latency (0.1 ms), and zero loss, drop, resend, recovery, and gap counts. - Two machines (Linux and Windows over Wi-Fi):
- Windows
cargo test -p labstream-net --test health_live(4/4 pass in 1.26 s) andcargo test -p labstream-cli(10/10 pass in 1.55 s). - Linux
labstream play conformance/captures/verify.xdf --stream Verify-rust,Verify-Markers-rust --loopwatched by Windowslabstream.exe topwith no--peerflag: discovered both streams over Wi-Fi, reported1.0 Hz(Verify-Markers-rust) and98-100 Hz(Verify-rust) onUDPwith2-3 mslatency and zero loss, drops, resends, recoveries, or gaps.
labstream relay¶
labstream relay [--name NAME] [--type TYPE] [--query PRED] [--name-suffix TEXT] [--session ID] [--out-session ID] [--disk-mb MIB] [--disk-dir DIR] [--ram-mb MIB] [--local-only] [--ws-port PORT] [--ws-bind ADDR] [--ws-allow IP] [--ws-marker-stream NAME] [--duration SECONDS]
labstream relay (roadmap step 4) attaches to existing LSL outlets (such as
liblsl device drivers on the same machine) and republishes them through
labstream outlets carrying seq/1, resume/1, dgram/1, and optional
disk store-and-forward (--disk-mb). Each relayed stream keeps the full
<desc> tree, sample bits, and raw timestamps of the source stream, adds a
<labstream_relay> tag to <desc>, and marks source_id with -relay so
inlets and labstream_streaminfo_is_relayed can tell relayed streams from
source streams.
With --ws-port PORT (roadmap step 13), labstream relay also starts the
opt-in RFC 6455 WebSocket bridge (labstream::ws::WsBridge) bound to
127.0.0.1 by default. Browser clients decode binary LSL frames with
labstream-wasm and publish markers onto --ws-marker-stream.
labstream calibrate¶
labstream calibrate --target NAME --reference NAME [--channel INDEX] [--threshold VALUE] [--pulses N] [--timeout SECONDS] [--json]
labstream calibrate (roadmap step 15) measures fixed device delay between a
target sensor stream and a reference trigger or marker stream with sub-sample
edge interpolation. The reported offset goes into
<desc><synchronization><offset_mean> through StreamInfo::set_device_delay.
Conformance plan¶
- XDF parser unit tests. Round-trip all seven LSL sample formats (exact
bit equality including negative zero, NaN, int boundaries, and strings with
NUL bytes), deduced timestamps (
ts_bytes = 0), clock offset alignment, and parsing the real LabRecorder recordingconformance/captures/verify.xdf. - Live
playtest. Replay an XDF file with multiple formats (including float32 EEG and string markers) and confirm that a live LSL inlet receives the exact bits and exact inter-sample timestamp intervals. - Live
toptest. Open a live outlet, runTopMonitor(and thelabstream top --count 2 --jsonCLI), and confirm thattopreports the same values asInlet::healthand updates once per second.