Repository navigation
Description
In the Slack Channel, we had opened a discussion regarding an issue of not being able to receive streams through the network in Unity:
Hi all, we are trying to finish our BCI pipeline which gives stimulus presentation in Unity, sends timing/information through LSL to Matlab, processes the data, and returns the results to Unity for selection. We have gotten this to work on a single localhost machine (e.g. Unity/Matlab running on the same machine), however we cannot seem to get it to work across several machines (when Unity is on a remote machine from Matlab).
The set up is as follows-
Computer A (Windows) - 1.) EEG outlet was recorded via g.tec USBamp, and is being streamed online as an EEG outlet via LSL and BCILab.
- 2.) NFB stimulus outlet from Unity was paired with the recorded EEG stream (recorded as a marker stream).
- 3.) 1 & 2 recorded using LabRecorder inlet (successful).
- 4.) BCILab outlet- processed EEG data with paired marker stream sends outlet to Unity for NFB selection.Computer B (Windows) - 1.) Unity inlet, taking information from BCILab processed data (not working).
- 2.) LabRecorder inlet to be sure there is no push/firewall issue (working).
In particular using the LSL4Unity app on Computer B, we find no available streams as inlets. LabRecorder on Computer B, can correctly identify the processed outlet stream from Computer A's BCILab, indicating this is not an issue on Computer A's outlets.Therefore, we are relatively sure the problem is isolated within LSL4Unity. Unfortunately, tracing back the error in Unity on Computer B, we see that in LSL4Unity's Resolver function returns a null value on Computer B when attempting to find results from a variable called resolver.results(), which is directly calling liblsl. (On Computer A, this same call returns one result: LSL.liblsl+StreamInfo).Does anyone have any insight as to what might be causing this issue? We have tried everything we could think of, including attempting to write a lsl_api.cfg file and changing the [multicast] values and scope, as well as the [lab] KnownPeers{} values, to no avail.All we are trying to do, is finalize the 'network' aspect of LSL, and be able to have the Unity inlet on Computer B successfully receive the outlet from BCILab given from Computer A.
With Chad's help, we were able to resolve this issue by bypassing the ContinuousResolver found in AInlet.cs and using liblsl.resolve_streams() instead. Below is the edited AStringInlet class that allowed my program to work over a network connection:
public abstract class AStringInlet : MonoBehaviour
{
public enum UpdateMoment { FixedUpdate, Update }
public UpdateMoment moment;
public string StreamName;
public string StreamType;
private bool expectedStreamHasAName;
private bool expectedStreamHasAType;
liblsl.StreamInfo[] results;
liblsl.StreamInlet inlet;
//liblsl.ContinuousResolver resolver;
private int expectedChannels = 0;
string[] sample;
void Start()
{
expectedStreamHasAName = !StreamName.Equals("");
expectedStreamHasAType = !StreamType.Equals("");
if (!expectedStreamHasAName && !expectedStreamHasAType)
{
Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream.");
this.enabled = false;
return;
}
/* SHAHEED's EDITS */
//Resolve all streams in LSL
results = liblsl.resolve_streams();
/* OLD AINLET CODE */
/*
if (expectedStreamHasAName)
{
Debug.Log("Creating LSL resolver for stream " + StreamName);
resolver = new liblsl.ContinuousResolver("name", StreamName);
}
else if (expectedStreamHasAType)
{
Debug.Log("Creating LSL resolver for stream with type " + StreamType);
resolver = new liblsl.ContinuousResolver("type", StreamType);
}
*/
StartCoroutine(ResolveExpectedStream());
AdditionalStart();
}
/// <summary>
/// Override this method in the subclass to specify what should happen during Start().
/// </summary>
protected virtual void AdditionalStart()
{
//By default, do nothing.
}
IEnumerator ResolveExpectedStream()
{
//OLD AINLET CODE
//var results = resolver.results();
//yield return new WaitUntil(() => results.Length > 0);
//inlet = new liblsl.StreamInlet(results[0]);
/* SHAHEED's EDITs */
// Look at each result and compare with the expected stream
foreach(var result in results){
Debug.Log("Stream: " + result.name() + ", Type: " + result.type());
if(expectedStreamHasAName){
if(result.name() == StreamName){
Debug.Log("Creating LSL Inlet for " + StreamName);
inlet = new liblsl.StreamInlet(result);
}
}
else if(expectedStreamHasAType){
if(result.type() == StreamType){
Debug.Log("Creating LSL Inlet for Stream with Type " + StreamType);
inlet = new liblsl.StreamInlet(result);
}
}
}
expectedChannels = inlet.info().channel_count();
yield return null;
}
protected void pullSamples()
{
sample = new string[expectedChannels];
try
{
double lastTimeStamp = inlet.pull_sample(sample, 0.0f);
if (lastTimeStamp != 0.0)
{
// do not miss the first one found
Process(sample, lastTimeStamp);
// pull as long samples are available
while ((lastTimeStamp = inlet.pull_sample(sample, 0.0f)) != 0)
{
Process(sample, lastTimeStamp);
}
}
}
catch (ArgumentException aex)
{
Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this);
this.enabled = false;
Debug.LogException(aex, this);
}
}
/// <summary>
/// Override this method in the subclass to specify what should happen when samples are available.
/// </summary>
/// <param name="newSample"></param>
protected abstract void Process(string[] newSample, double timeStamp);
void FixedUpdate()
{
if (moment == UpdateMoment.FixedUpdate && inlet != null)
pullSamples();
}
void Update()
{
if (moment == UpdateMoment.Update && inlet != null)
pullSamples();
}
}
Activity
cboulay commentedon Jul 16, 2019
Link to sccn/liblsl#29
jfrey-xx commentedon Jul 16, 2019
Hello,
I think this is due to the timeout, too low for an actual network, plus once the resolve fails there is no new attempts. We had similar issue and fixed that in our branch of LSL4Unity, located at https://github.com/jelenaLis/LSL4Unity -- this commit in particular: jelenaLis@4576012
Sorry for the huge diff, there was some diff in code formatting in top of the fix. If the workaround works for both of you I can try to make a proper pull request if you want to integrate that here, or you can just cherry-pick (actually, there might be some other hack of interest in the branch). Note that the hack need some refinements, e.g. if the connexion breaks.
jfrey-xx commentedon Jul 16, 2019
Note: posted too quickly, actually I did not investigate your own workaround it might be better than to keep calling the ContinuousResolver after launch, what we did ^^
tstenner commentedon Jul 17, 2019
Just a quick idea: does the oneshot resolver (with the normal continuous resolver object) work?
manmermon commentedon Mar 9, 2020
In Ubuntu 18.04, I detected the next problem: I created 2 different StreamOutlet(...) but resolve_streams() [without inputs] always returned a single stream. I tried the next: stream1 = resolve_stream( 'name', 'test1' ) and stream2 = resolve_stream( 'name', 'test2' ) but the issue remained. I tried LabRecorded, but only a single stream is showed.
The problem is the same in Java and Python.
LSL library version: 1.14.0
cboulay commentedon Mar 9, 2020
@manmermon thanks for the report. Is this all one computer or over a network? Can you try providing a unique id to each outlet during creation?
manmermon commentedon Mar 9, 2020
@cboulay only one computer (locahost). I used 2 different unique id.
The Python code to send data:
from pylsl import StreamInfo, StreamOutlet
info1 = StreamInfo('test1', 'value', 1, 0, 'float32', 'myuid2424' )
info2 = StreamInfo('test2', 'value', 1, 0, 'float32', 'myuid2425')
outlet1 = StreamOutlet( info1, 32, 360 )
outlet2 = StreamOutlet( info2, 32, 360 )
cboulay commentedon Mar 9, 2020
And did you push some samples to each stream before trying to resolve them?
(Sorry I'm not on Ubuntu at the moment so I can't test)
manmermon commentedon Mar 9, 2020
Yes, did.
This is the sender:
And this is my receiver:
The output is "length=1"
tstenner commentedon Mar 15, 2020
I've uploaded a test build of the multicast branch, could you try if this fixes it?
manmermon commentedon Mar 26, 2020
I tried the test build and it is not working. The next message is obtained after calling resolve_streams() :
Loguru caught a signal: SIGSEGV
2020-03-26 11:58:23.246 ( 3,302s) [ 101ED700] :0 FATL| Signal: SIGSEGV
Segment violation (generated core)
tstenner commentedon Mar 27, 2020
That shouldn't happen at all.
I've uploaded a build with some more debug information, could you run the unit tests from
bin/lsl_test_exportedand post the results?manmermon commentedon Mar 27, 2020
This is the result:
tstenner commentedon Mar 28, 2020
The good news is that the error is reproducible, the bad news is that the network configuration looks ok. I'll add some more debug messages to see what's (not) happening behind the scenes and upload another build some time next week.
tstenner commentedon Apr 5, 2020
I've updated the debug build, could you download it again, run
LSLAPICFG=install/bin/lslcfgs/debuglog.cfg install/bin/lsl_test_exportedand upload thelsldebuglog.txt?manmermon commentedon Apr 7, 2020
This the result: