pub struct Inlet { /* private fields */ }Expand description
A connected inlet.
A background thread reads the socket and decodes samples into a bounded queue. The application pulls from that queue.
The split matters. A reader that decoded inside pull would leave the
socket unread while the application worked, so a loss would land in the
outlet’s queue instead of this one. liblsl runs the same background thread
(src/data_receiver.h).
Implementations§
Source§impl Inlet
impl Inlet
Sourcepub fn open(info: &StreamInfo, timeout: Duration) -> Result<Self>
pub fn open(info: &StreamInfo, timeout: Duration) -> Result<Self>
Open a feed to a resolved stream. SPEC.md 4 and 6.
The call runs the whole handshake, including the two test pattern samples that open every feed.
Sourcepub fn open_with_buffer(
info: &StreamInfo,
timeout: Duration,
buffer_samples: i32,
) -> Result<Self>
pub fn open_with_buffer( info: &StreamInfo, timeout: Duration, buffer_samples: i32, ) -> Result<Self>
Open a feed and choose the size of the queue, in samples.
The value also goes out in Max-Buffer-Length, which carries a count of
samples. A caller that thinks in seconds converts first. SPEC.md 8.6.
Sourcepub fn open_recovering(
info: &StreamInfo,
timeout: Duration,
buffer_samples: i32,
) -> Result<Self>
pub fn open_recovering( info: &StreamInfo, timeout: Duration, buffer_samples: i32, ) -> Result<Self>
Open a feed and choose whether the inlet finds the stream again after a restart of its source. SPEC.md 10.1.
liblsl enables recovery by default (include/lsl_cpp.h:915).
Sourcepub fn open_selected(
info: &StreamInfo,
timeout: Duration,
buffer_samples: i32,
recover: bool,
selection: SelectParam,
) -> Result<Self>
pub fn open_selected( info: &StreamInfo, timeout: Duration, buffer_samples: i32, recover: bool, selection: SelectParam, ) -> Result<Self>
Open a feed requesting channel and/or rate selection (select/1,
docs/roadmap.md, step 6).
If the outlet supports select/1, the returned inlet delivers only the
selected channels at the selected rate, and Inlet::info and
Inlet::fullinfo reflect the narrowed stream. If the outlet does not
support select/1 (for example a liblsl outlet), the inlet falls back
cleanly to the full stream and Inlet::selection returns None.
Sourcepub fn set_postprocessing(&mut self, options: u32)
pub fn set_postprocessing(&mut self, options: u32)
Choose the post-processing stages. SPEC.md 8.5.
The default applies none, so a timestamp arrives as the sender wrote it.
When flags::DEVICE_DELAY is enabled and no explicit delay was set via
Inlet::set_device_delay, the inlet reads
<desc><synchronization><offset_mean> from the stream description.
Sourcepub fn set_device_delay(&mut self, delay_s: f64)
pub fn set_device_delay(&mut self, delay_s: f64)
Set an explicit calibrated device delay (in seconds) subtracted when
flags::DEVICE_DELAY is enabled (docs/roadmap.md, step 15).
Sourcepub fn device_delay(&self) -> f64
pub fn device_delay(&self) -> f64
The device delay (in seconds) currently configured on the post-processor.
Sourcepub fn set_postprocessing_all(&mut self)
pub fn set_postprocessing_all(&mut self)
Apply every stage: clock sync, then jitter removal, then the clamp.
Sourcepub fn time_correction(&self) -> Option<f64>
pub fn time_correction(&self) -> Option<f64>
The measured offset between the two clocks, or None before the first
burst finishes.
Add this value to a timestamp to move it onto the local clock. The
CLOCKSYNC stage does that on its own.
Sourcepub fn wait_for_time_correction(&self, timeout: Duration) -> Option<f64>
pub fn wait_for_time_correction(&self, timeout: Duration) -> Option<f64>
Wait for a first offset measurement.
Sourcepub fn time_uncertainty(&self) -> Option<f64>
pub fn time_uncertainty(&self) -> Option<f64>
The round-trip time of the estimate that the offset came from.
Sourcepub fn clock_drift(&self) -> Option<f64>
pub fn clock_drift(&self) -> Option<f64>
Estimated relative clock drift (d(offset)/d(t_local) in s/s) from the
opt-in drift clock (docs/roadmap.md, step 17), or None before the
first burst completes.
Sourcepub fn smooth_time_correction(&self, remote_ts: f64) -> Option<f64>
pub fn smooth_time_correction(&self, remote_ts: f64) -> Option<f64>
Smooth offset local - remote evaluated for remote_ts using the
opt-in drift clock (docs/roadmap.md, step 17).
Sourcepub fn info(&self) -> &StreamInfo
pub fn info(&self) -> &StreamInfo
The description of the connected stream.
This is the short description that discovery returned. It carries an
empty description tree. Call Inlet::fullinfo for the tree.
Sourcepub fn fullinfo(&self, timeout: Duration) -> Result<StreamInfo>
pub fn fullinfo(&self, timeout: Duration) -> Result<StreamInfo>
Read the whole description, with the description tree.
The short description that a discovery answer carries has no tree
(src/stream_info_impl.cpp:160). The tree travels on the data port.
This opens its own connection, the way info_receiver does
(src/info_receiver.cpp:60), and leaves the feed connection alone.
When select/1 is active on this connection, the returned description
carries the selected channel count, selected rate, and selected channel
metadata under <desc><channels>.
Sourcepub fn selection(&self) -> Option<SelectParam>
pub fn selection(&self) -> Option<SelectParam>
The active select/1 selection negotiated with the outlet, or None
when the full stream is delivered.
Sourcepub fn pull(&mut self, timeout: Duration) -> Result<Option<Sample>>
pub fn pull(&mut self, timeout: Duration) -> Result<Option<Sample>>
Read one sample.
Returns Ok(None) when the timeout passes with no whole sample.
The timestamp passes through the post-processing stages that
Inlet::set_postprocessing selected. With none selected the value is
the one that the sender wrote.
With CLOCKSYNC selected, the first call waits for the first offset
measurement, for up to 5 s. The timeout of the call does not limit that
wait. liblsl waits the same time (src/stream_inlet_impl.h:44).
Sourcepub fn pull_numeric_into(
&mut self,
format: Format,
dst: &mut [u8],
timeout: Duration,
) -> Result<Option<f64>>
pub fn pull_numeric_into( &mut self, format: Format, dst: &mut [u8], timeout: Duration, ) -> Result<Option<f64>>
Read one numeric sample directly into dst (native-endian bytes),
returning its timestamp.
On a shm/1 connection, copies directly from shared memory into dst
with zero heap allocation and zero mutex locks.
Sourcepub fn pull_packed(&mut self, timeout: Duration) -> Result<Option<PackedSample>>
pub fn pull_packed(&mut self, timeout: Duration) -> Result<Option<PackedSample>>
Read one PackedSample without allocating a Vec<Value>.
Sourcepub fn pull_chunk(
&mut self,
out: &mut Vec<Sample>,
max: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk( &mut self, out: &mut Vec<Sample>, max: usize, timeout: Duration, ) -> Result<usize>
Read every sample that waits, up to max, with one lock.
The samples go to the end of out. The call gives how many it added.
Every timestamp passes through the stages that
Inlet::set_postprocessing selected, in the order of one
Inlet::pull for each sample.
The timeout applies to the first sample only. The call never waits for
max samples, because a program that shows live signals must show what
arrived.
With CLOCKSYNC selected, the first call can wait up to 5 s for the
first offset measurement, as Inlet::pull does.
This is the call for a fast stream. Inlet::pull takes the queue lock
and reads the clock for each sample. A stream of 8 channels at 1000 Hz
therefore costs 1000 locks each second with pull, and one lock for each
block here.
Sourcepub fn pull_chunk_packed(
&mut self,
out: &mut Vec<PackedSample>,
max: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_packed( &mut self, out: &mut Vec<PackedSample>, max: usize, timeout: Duration, ) -> Result<usize>
Read every waiting PackedSample, up to max, with one lock and
without allocating a Vec<Value>.
Sourcepub fn pull_chunk_f32(
&mut self,
data: &mut Vec<f32>,
timestamps: &mut Vec<f64>,
max_samples: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_f32( &mut self, data: &mut Vec<f32>, timestamps: &mut Vec<f64>, max_samples: usize, timeout: Duration, ) -> Result<usize>
Read up to max_samples into flat f32 and timestamp buffers with one lock.
Sourcepub fn pull_chunk_f64(
&mut self,
data: &mut Vec<f64>,
timestamps: &mut Vec<f64>,
max_samples: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_f64( &mut self, data: &mut Vec<f64>, timestamps: &mut Vec<f64>, max_samples: usize, timeout: Duration, ) -> Result<usize>
Read up to max_samples into flat f64 and timestamp buffers with one lock.
Sourcepub fn pull_chunk_i32(
&mut self,
data: &mut Vec<i32>,
timestamps: &mut Vec<f64>,
max_samples: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_i32( &mut self, data: &mut Vec<i32>, timestamps: &mut Vec<f64>, max_samples: usize, timeout: Duration, ) -> Result<usize>
Read up to max_samples into flat i32 and timestamp buffers with one lock.
Sourcepub fn pull_chunk_i16(
&mut self,
data: &mut Vec<i16>,
timestamps: &mut Vec<f64>,
max_samples: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_i16( &mut self, data: &mut Vec<i16>, timestamps: &mut Vec<f64>, max_samples: usize, timeout: Duration, ) -> Result<usize>
Read up to max_samples into flat i16 and timestamp buffers with one lock.
Sourcepub fn pull_chunk_i8(
&mut self,
data: &mut Vec<i8>,
timestamps: &mut Vec<f64>,
max_samples: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_i8( &mut self, data: &mut Vec<i8>, timestamps: &mut Vec<f64>, max_samples: usize, timeout: Duration, ) -> Result<usize>
Read up to max_samples into flat i8 and timestamp buffers with one lock.
Sourcepub fn pull_chunk_i64(
&mut self,
data: &mut Vec<i64>,
timestamps: &mut Vec<f64>,
max_samples: usize,
timeout: Duration,
) -> Result<usize>
pub fn pull_chunk_i64( &mut self, data: &mut Vec<i64>, timestamps: &mut Vec<f64>, max_samples: usize, timeout: Duration, ) -> Result<usize>
Read up to max_samples into flat i64 and timestamp buffers with one lock.
Sourcepub fn samples_available(&self) -> usize
pub fn samples_available(&self) -> usize
How many samples wait for the application.
Sourcepub fn samples_dropped(&self) -> u64
pub fn samples_dropped(&self) -> u64
How many samples the queue has dropped.
Nothing on the wire carries this number, so a peer cannot learn it. SPEC.md 8.7. This exists for a local report only.
Sourcepub fn samples_lost(&self) -> Option<u64>
pub fn samples_lost(&self) -> Option<u64>
How many samples never reached this inlet, since it opened.
The count comes from the seq/1 numbers (docs/extensions.md). It
shows a sample that the outlet dropped from a full queue, and the
samples between a lost connection and the next one. The value is
None when the current connection does not use seq/1, for example
with a liblsl outlet. None means unknown, not zero.
The inlet queue drops after this count, so a full total adds
Inlet::samples_dropped.
Sourcepub fn samples_resent(&self) -> Option<u64>
pub fn samples_resent(&self) -> Option<u64>
How many samples came from the history of the outlet, since the inlet opened.
After a lost connection, an outlet with the resume/1 feature sends
the samples of the dropout again (docs/extensions.md, section
resume). These samples arrive late, with their original
timestamps. Inlet::samples_lost does not count them.
The value is None when the current connection does not use
resume/1. None means unknown, not zero.
Sourcepub fn on_udp(&self) -> bool
pub fn on_udp(&self) -> bool
True while the samples of the connection arrive on UDP, with the
dgram/1 feature. docs/extensions.md, section dgram.
Sourcepub fn on_shm(&self) -> bool
pub fn on_shm(&self) -> bool
True while the samples of the connection arrive through shared memory,
with the shm/1 feature (docs/extensions.md, section shm).
Sourcepub fn is_compressed(&self) -> bool
pub fn is_compressed(&self) -> bool
True while wire compression (comp/1) is active on this connection.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
True while negotiated transport encryption (enc/1) is active on this
connection (docs/roadmap.md, step 14).
Sourcepub fn has_live_metadata(&self) -> bool
pub fn has_live_metadata(&self) -> bool
True when the current connection negotiated meta/1 live metadata
(docs/roadmap.md, step 16).
Sourcepub fn pending_metadata_count(&self) -> usize
pub fn pending_metadata_count(&self) -> usize
Number of unread live metadata updates currently queued on this inlet.
Sourcepub fn pull_metadata(&self) -> Vec<MetadataUpdate>
pub fn pull_metadata(&self) -> Vec<MetadataUpdate>
Drain all pending live metadata updates in order.
Sourcepub fn pull_metadata_one(&self) -> Option<MetadataUpdate>
pub fn pull_metadata_one(&self) -> Option<MetadataUpdate>
Pop the oldest pending live metadata update, if any.
Sourcepub fn metadata(&self) -> BTreeMap<String, MetadataUpdate>
pub fn metadata(&self) -> BTreeMap<String, MetadataUpdate>
Snapshot the latest live metadata value received for each key.
Sourcepub fn compression_ratio(&self) -> Option<f64>
pub fn compression_ratio(&self) -> Option<f64>
Ratio wire_bytes / raw_bytes observed on this connection when
comp/1 is active, or None when uncompressed or before data arrives.
Sourcepub fn buffer_capacity(&self) -> usize
pub fn buffer_capacity(&self) -> usize
The size of the queue, in samples.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
True once the connection ended and every sample has been pulled.
Sourcepub fn health(&self) -> InletHealth
pub fn health(&self) -> InletHealth
Snapshot the health of this inlet in one call. docs/health.md.
Source§impl Inlet
impl Inlet
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
True while the reader is attached to a source.
A recovery sets this to false until the stream is found again.
Sourcepub fn recoveries(&self) -> u64
pub fn recoveries(&self) -> u64
How many times the connection has been rebuilt. SPEC.md 10.1.
Sourcepub fn current_info(&self) -> StreamInfo
pub fn current_info(&self) -> StreamInfo
The stream that the reader is attached to now.
A recovery replaces this, and the instance identifier changes while the name and the source identifier stay.