Skip to main content

Crate labstream

Crate labstream 

Source
Expand description

The Lab Streaming Layer, for Rust programs.

This crate is the API that a Rust program uses. It holds no protocol code. The protocol lives in labstream-net, labstream-proto, labstream-wire, and labstream-time, and those crates stay exact to the C++ library at sccn/liblsl. A program that needs a protocol detail can still call them.

§Read a stream

use labstream::{Buffer, Chunk, Inlet, Post, Query};
use std::time::Duration;

let info = labstream::resolve_first(&Query::stream_type("EEG"), Duration::from_secs(5))?
    .expect("an EEG stream");
let mut inlet = Inlet::builder(&info)
    .buffer(Buffer::Seconds(8.0))
    .postprocess(Post::ALL)
    .open(Duration::from_secs(5))?;

for c in inlet.info().channels() {
    println!("{} in {}", c.label, c.unit);
}

let mut chunk = Chunk::<f32>::new(info.channel_count(), 4096);
loop {
    chunk.clear();
    inlet.pull_chunk(&mut chunk, Duration::from_millis(20))?;
    for (t, sample) in chunk.iter() {
        println!("{t} {sample:?}");
    }
}

§Publish a stream

use labstream::{Format, Outlet, StreamInfo};

let info = StreamInfo::builder("MyDevice", "EEG", Format::Float32)
    .rate(250.0)
    .source_id("device-0001")
    .channel_labels(["Fp1", "Fp2", "C3", "C4"])
    .build()?;
let outlet = Outlet::new(info)?;
outlet.push(&[1.0f32, 2.0, 3.0, 4.0])?;

Modules§

calibrate
Device-delay calibration (docs/roadmap.md, step 15). Device-delay calibration against a reference trigger stream (docs/roadmap.md, step 15).
doctor
Network diagnostics for LSL discovery (labstream doctor). Network diagnostics for LSL discovery (labstream doctor).
enc
Opt-in negotiated transport encryption (enc/1, docs/roadmap.md, step 14). Opt-in negotiated transport encryption (enc/1, docs/roadmap.md, step 14).
relay
Local-to-network LSL stream relay (labstream relay). Local-to-network LSL stream relay (docs/roadmap.md, step 4).
sync
Real-time multi-stream sync and resampler (docs/roadmap.md, step 18). Live multi-inlet time-grid aligner and resampler (docs/roadmap.md, step 18).
ws
Opt-in WebSocket bridge for browser reach (docs/roadmap.md, step 13). Zero-dependency RFC 6455 WebSocket bridge for browser reach (docs/roadmap.md, step 13).

Structs§

AlignedSample
One aligned sample on the common monotonic output grid.
Channel
One channel of a stream.
Chunk
A block of samples that the caller keeps and reuses.
ConsumerHealth
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). Snapshot of one consumer queue on an crate::Outlet.
Gap
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). One missing interval in a stream, given as a pair of timestamps.
Inlet
Read samples from one stream.
InletBuilder
The builder for Inlet.
InletHealth
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). Snapshot of the health of one crate::Inlet.
MetadataUpdate
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). One live metadata change emitted by an outlet.
Outlet
Publish samples for other programs to read.
OutletHealth
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). Snapshot of the health of one crate::Outlet.
Post
The post-processing stages that an inlet applies to a timestamp.
Query
A discovery query.
SelectParam
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). The parameter of a select/1 offer and answer (docs/roadmap.md, step 6).
StreamInfo
The description of one stream.
StreamInfoBuilder
The builder for StreamInfo.
SyncConfig
Configuration for StreamAligner and SyncGroup.
SyncGroup
Live multi-stream aligner combining N numeric Inlets onto one common monotonic time grid.
Watcher
Watch the network and keep a current list of streams.

Enums§

Buffer
How much data an inlet holds for the program.
Error
What can go wrong.
Format
The sample format of a stream. A channel format. The values match include/lsl/common.h:64-84.
GapKind
Stream health snapshots, gap descriptors, and live metadata (docs/health.md, docs/extensions.md). Why a gap occurred in the sample stream.

Traits§

Scalar
A numeric type that an inlet can read and an outlet can write.

Functions§

as_f64
Read one value as a number, whatever format it arrived in.
as_text
Read one value as text.
clock
The local clock, in seconds.
resolve_all
Find every stream that matches, for the whole timeout.
resolve_at_least
Find at least this many streams, then stop.
resolve_first
Find one stream that matches, and stop at the first answer.