Skip to main content

stream_inlet

Namespace: LSLLIB  ·  Library: LSL Library

#include <lsl/lsl_stream_inlet.h>

class LSLLIB::stream_inlet

Client-side LSL endpoint: connects to a resolved outlet over TCP and exposes pulled samples as float chunks.

src/examples/ex_lsl/main.cpp
stream_info source = outlet.info(); // normally an entry of resolve_stream("name", "ex_lsl_eeg")
source.set_data_host("127.0.0.1");
stream_inlet inlet(source);
inlet.open_stream();
QElapsedTimer clock;
clock.start();
while (!outlet.have_consumers() && clock.elapsed() < 5000) { // samples pushed before the outlet accepts the inlet are not delivered
QThread::msleep(5);
}
outlet.push_sample({1.0f, 2.0f, 3.0f});
outlet.push_chunk({{4.0f, 5.0f, 6.0f}, {7.0f, 8.0f, 9.0f}});

std::vector<std::vector<float>> received;
clock.restart();
while (received.size() < 3 && clock.elapsed() < 5000) {
QThread::msleep(20);
for (const std::vector<float>& sample : inlet.pull_chunk<float>()) { // one vector per sample
received.push_back(sample);
}
}
inlet.close_stream();
src/examples/ex_lsl/main.cpp
const std::vector<stream_info> found = resolve_stream("name", "ex_lsl_eeg", 1.5); // multicast discovery

Public Methods​

stream_inlet(info)​

Construct a new stream_inlet from a resolved stream_info.

Parameters:


~stream_inlet()​

Destructor.

Closes the connection if still open.


open_stream()​

Open the TCP connection to the outlet and begin receiving data.


close_stream()​

Close the TCP connection to the outlet.


samples_available()​

Check whether new samples are available in the internal buffer.

Also performs a non-blocking read from the TCP socket to collect any pending data.

Returns:

  • bool — True if at least one complete sample is available.

pull_chunk()​

Pull a chunk of multichannel data from the inlet.

Returns all complete samples currently in the buffer. Template is provided for API compatibility with liblsl; only float is supported in this implementation.

Returns:

  • std::vector< std::vector< T > > — A vector of samples, where each sample is a vector of channel values.

pull_chunk_float()​

Pull a chunk of float data (non-template version).

Returns:

  • std::vector< std::vector< float > > — A vector of samples, where each sample is a vector of float channel values.

Example​

Used in examples​

ex_lsl​

LSL library: publish a stream, discover it and receive its samples over loopback.

src/examples/ex_lsl/main.cpp, line 80
stream_info source = outlet.info(); // normally an entry of resolve_stream("name", "ex_lsl_eeg")
source.set_data_host("127.0.0.1");
stream_inlet inlet(source);
inlet.open_stream();
QElapsedTimer clock;
clock.start();
while (!outlet.have_consumers() && clock.elapsed() < 5000) { // samples pushed before the outlet accepts the inlet are not delivered
QThread::msleep(5);
}
outlet.push_sample({1.0f, 2.0f, 3.0f});
outlet.push_chunk({{4.0f, 5.0f, 6.0f}, {7.0f, 8.0f, 9.0f}});

Authors of this file​