Configuration (lsl_api.cfg)
liblsl reads its settings from an optional configuration file, lsl_api.cfg.
Without a file, liblsl uses built-in defaults, and these work for most labs.
Use a file when you need to change network ports, limit or widen stream
discovery, separate labs that share a network, turn on logging, or tune timing.
The code that reads the settings is in src/api_config.cpp. The file parser
is in src/util/inireader.cpp.
Where liblsl looks for the configuration
liblsl uses the first source below that exists and loads without error. It reads only that one source. Settings from several files are never merged.
Content passed to
lsl_set_config_content(). No file is read.The file named in the
LSLAPICFGenvironment variable.The file passed to
lsl_set_config_filename().lsl_api.cfgin the current working directory of the program.~/lsl_api/lsl_api.cfgin the user’s home directory./etc/lsl_api/lsl_api.cfg.If none of these loads: the built-in defaults.
Details per platform:
Working directory (4) is where the program was started from. This is not always the folder that contains the program.
Home directory (5): liblsl takes the home directory from
HOME, thenUSERPROFILE, thenHOMEDRIVE+HOMEPATH. On Windows this is usually%USERPROFILE%\lsl_api\lsl_api.cfg, for exampleC:\Users\alice\lsl_api\lsl_api.cfg. Editing it needs no admin rights.System file (6): on Linux and macOS this is
/etc/lsl_api/lsl_api.cfgand applies to all users. On Windows the same path is relative to the root of the current drive, usuallyC:\etc\lsl_api\lsl_api.cfg.LSLAPICFG(2) points to one file for one shell or one program run, for exampleLSLAPICFG=/tmp/special.cfg ./LabRecorder, orexport LSLAPICFG=/tmp/special.cfgfor all programs started afterwards.
If the file named by LSLAPICFG or lsl_set_config_filename() cannot be
read, liblsl logs an error and continues with the next location.
If a file exists but contains an error (see File syntax),
liblsl logs an error and tries the next location. If lsl_set_config_content()
was given invalid content, liblsl logs an error and falls back to the file
search.
When the configuration is read
The configuration is read once per process, the first time liblsl needs a
setting. In practice this is when the program creates its first stream info,
outlet, inlet or resolver, or calls lsl_protocol_version(). After that,
liblsl never reads it again. To apply a changed file, restart the program.
lsl_set_config_content() and lsl_set_config_filename() (declared in
include/lsl/common.h) only work if you call them before any other liblsl
function. Later calls have no effect. Example:
#include <lsl_c.h>
int main(void) {
lsl_set_config_content("[lab]\nSessionID = lab-7\n[log]\nlevel = -1\n");
/* ... now create outlets, inlets, resolvers ... */
}
File syntax
The file uses a simple INI format: [section] lines, followed by
key = value lines.
; A comment
[ports]
BasePort = 16572
[lab]
KnownPeers = {192.168.1.17, 192.168.1.18}
The parser is strict. Keep these rules in mind:
A comment line must start with
;in the first column.#is not a comment. Comments at the end of a line are not supported: they become part of the value.A section line must start with
[in the first column.Every other non-blank line must contain
=. Empty values (file =) are an error. To use a default, leave the line out.Each key may appear only once per section.
Keys are case-sensitive. A misspelled key (
TimeProbeMaxRttinstead ofTimeProbeMaxRTT) is silently ignored. Unknown keys and sections are also ignored.Spaces around keys and values are removed. Quotes are not removed, so do not quote values.
Booleans are
1or0. Only1means true. Any other value, includingtrue, means false.Numbers use
.as decimal separator. A value that is not a number is read as0.Lists are written in braces:
{a, b, c}. A value without braces is read as an empty list.
Specify only the settings you want to change. This keeps your file working when defaults change in later versions.
Settings
Settings marked Rarely needed should only be changed if you know why.
Settings that must match on all machines in a lab. liblsl does not check
this, but machines with different values may not find each other’s streams:
the [ports] settings, SessionID, IPv6, and the multicast addresses
(ResolveScope and the address lists). It is safest to copy the same file to
every machine.
[ports]
Key |
Default |
Meaning |
|---|---|---|
|
|
UDP port for stream discovery queries (multicast, broadcast and machine-local). |
|
|
First port of the range that outlets use for their data (TCP) and service (UDP) ports. Resolvers also take a UDP port from this range to receive replies. |
|
|
Number of ports in the range, from |
|
|
If the range is full, let the operating system pick any free port. Such outlets cannot be found by the range probes and need open firewall ports outside the range. |
|
|
Which IP versions to use: |
[multicast]
These settings control UDP stream discovery. See stream discovery for how discovery works.
ResolveScope picks which address lists are used and the multicast TTL
(time-to-live: how many routers a packet may cross). Each scope includes all
smaller scopes:
|
Adds these addresses |
TTL |
|---|---|---|
|
|
0 |
|
|
1 |
|
|
24 |
|
|
32 |
|
|
255 |
IPv4 addresses are dropped if IPv6 = force, and IPv6 addresses are dropped
if IPv6 = disable. An address that cannot be parsed makes the file invalid.
Key |
Default |
Meaning |
|---|---|---|
|
|
Discovery scope, see the table above. Use the smallest scope that works. |
|
|
Addresses for discovery on the same machine. liblsl also probes these on every port of the port range, so all local streams are found. |
|
|
IPv4 broadcast and multicast addresses for the local subnet. |
|
|
IPv4 multicast addresses for the site. |
|
|
Rarely needed. IPv4 multicast addresses for the organization scope. |
|
|
Rarely needed. IPv4 multicast addresses for the global scope. |
|
|
Rarely needed. The IPv6 group. liblsl adds the scope prefix ( |
|
|
Rarely needed. If not empty, replaces the whole address list built from |
|
|
Rarely needed. If 0 or more, replaces the TTL chosen by |
|
(empty) |
Rarely needed. Local address that the outlets’ discovery sockets bind to. Empty means all interfaces. |
|
|
Rarely needed. Local interface addresses to join multicast groups on and send queries from. IPv6 addresses need the interface index as scope, for example |
[lab]
Key |
Default |
Meaning |
|---|---|---|
|
|
Host names or IP addresses of machines that may provide streams. liblsl sends discovery queries directly to each port of the port range on these hosts. This works where multicast and broadcast are blocked. |
|
|
Name of a logical recording session. Resolvers only list outlets with the same |
|
|
Rarely needed. If |
[tuning]
All times are in seconds unless stated otherwise. These settings are
rarely needed. See time synchronization for the
Time* settings.
Key |
Default |
Meaning |
|---|---|---|
|
|
Network protocol version. Lower it (for example to |
|
|
How often an inlet checks whether its connection has stalled. |
|
|
If recovery is enabled, an inlet that has received no data for this long re-resolves the stream. It reconnects only if the outlet has disappeared and one replacement is found. |
|
value of |
For synchronous (blocking) outlets: a consumer that cannot take a sample within this time is disconnected. |
|
|
Minimum wait between multicast discovery waves. |
|
|
How long to wait for replies to a multicast discovery wave. |
|
|
Extra wait between waves when unicast ( |
|
|
How long to wait for replies to unicast and TCP discovery queries. |
|
|
Extra pause between waves in continuous (background) resolvers. |
|
|
Windows only: system timer resolution in ms requested for the program’s lifetime. |
|
|
How many discovery query results each outlet caches. |
|
|
Time between clock offset updates. |
|
|
Probes that must succeed for an offset update. |
|
|
Probes sent per offset update. |
|
|
Time between probes. |
|
|
Extra time to wait for the last probe replies. |
|
|
Memory pre-allocated for samples in an outlet, in ms of data (regular-rate streams). |
|
|
The same, in samples, for irregular-rate streams. |
|
|
Like |
|
|
Like |
|
|
TCP send buffer size of outlet connections, in bytes. |
|
|
TCP receive buffer size of outlet connections, in bytes. |
|
|
Default half-time of the time-stamp smoothing post-processing option. |
|
|
Restart the time-stamp smoothing when a time stamp is off the fitted line by more than this many seconds and by more than |
|
|
The same threshold in sample periods. pyxdf uses |
|
|
If |
[log]
Key |
Default |
Meaning |
|---|---|---|
|
|
Most detailed level to log: |
|
(not set) |
Append log messages to this file. When set, nothing is logged to the terminal. |
Messages logged before the configuration is read use the logging library’s
defaults. Some detailed messages only exist in LSL_DEBUGLOG=ON builds.
Recipes
Change the port range
To move liblsl to ports 3051 to 3067:
[ports]
MulticastPort = 3051
BasePort = 3052
PortRange = 16
Use this on every machine in the lab. For an outlet to be reachable through a
firewall, open TCP and UDP from BasePort to BasePort + PortRange - 1, and
UDP on MulticastPort. A machine that only runs inlets needs the UDP range
open for discovery replies.
Change the multicast scope
The default scope is site. To let streams be found across a campus whose
routers forward multicast:
[multicast]
ResolveScope = organization
To keep discovery inside the local subnet, use ResolveScope = link. With
ResolveScope = machine, only streams on the same computer are found by
multicast. If your site has rules for multicast addresses, change the address
lists or use AddressesOverride and TTLOverride.
Define the local lab
List the lab’s machines when multicast and broadcast do not work, or to reach machines across routers or the internet:
[lab]
KnownPeers = {192.168.1.17, 137.243.177.26, testing.example.org}
To also stop multicast discovery, add ResolveScope = machine under
[multicast]. Remote hosts must allow the port range through their firewall.
To split one network into independent recording setups, give each setup its
own session name. Machines only see streams with the same SessionID:
[lab]
SessionID = lab-001b
Anyone on the network can still see and capture the traffic. Use operating system and network settings to protect data.
Discover streams over TCP
If a firewall blocks UDP discovery, liblsl can probe the port range over TCP as a last resort:
[lab]
ResolveOverTCP = 1
KnownPeers = {192.168.1.17}
Each resolve then makes one connection attempt per port per host, at most 16 at a time.
Closed ports are refused at once, but filtered ports (dropped by a firewall) hold one of the
16 slots until the probe is cancelled after UnicastMaxRTT, so with several hosts later ports
may never be probed. Use it only for the local machine or a short KnownPeers list. Write 1,
not true.
Turn on logging
To investigate a problem or attach a log to a bug report:
[log]
level = 0
file = lsllog.txt
Use level = -1 to see only warnings and errors. Leave out file to log to
the terminal.
Tune for wireless networks
These settings have been found to make time synchronization and discovery more robust over WiFi:
[tuning]
TimeProbeMaxRTT = 0.100
TimeProbeInterval = 0.010
TimeProbeCount = 10
TimeUpdateInterval = 0.25
MulticastMinRTT = 0.100
MulticastMaxRTT = 30