Class StreamInlet
A stream inlet.
Inlets are used to receive streaming data (and meta-data) from the lab network.
Namespace: LSL4Unity
Assembly: cs.temp.dll.dll
Syntax
public class StreamInlet : LSLObject, IDisposable
Constructors
StreamInlet(StreamInfo, Int32, Int32, Boolean, ProcessingOptions)
Initializes a new instance of Stream
Declaration
public StreamInlet(StreamInfo info, int maxBuflen = 360, int maxChunklen = 0, bool recover = true, ProcessingOptions postproc_flags = ProcessingOptions.None)
Parameters
Type | Name | Description |
---|---|---|
Stream |
info | A resolved stream info object (as coming from one of the resolver functions). |
Int32 | maxBuflen | Optionally the maximum amount of data to buffer (in seconds if there is a nominal sampling rate, otherwise x100 in samples). Recording applications want to use a fairly large buffer size here, while real-time applications would only buffer as much as they need to perform their next calculation. |
Int32 | maxChunklen | Optionally the maximum size, in samples, at which chunks are transmitted (the default corresponds to the chunk sizes used by the sender). Recording applications can use a generous size here (leaving it to the network how to pack things), while real-time applications may want a finer (perhaps 1-sample) granularity. If left unspecified (=0), the sender determines the chunk granularity. |
Boolean | recover | Try to silently recover lost streams that are recoverable (=those that that have a SourceId set).
In all other cases (recover is false or the stream is not recoverable) functions may throw a Lost |
Processing |
postproc_flags |
Remarks
The Stream
Methods
CloseStream()
Drop the current data stream.
All samples that are still buffered or in flight will be dropped and transmission and buffering of data for this inlet will be stopped. If an application stops being interested in data from a source (temporarily or not) but keeps the outlet alive, it should call CloseStream() to not waste unnecessary system and network resources.
Declaration
public void CloseStream()
DestroyLSLObject(IntPtr)
Declaration
protected override void DestroyLSLObject(IntPtr obj)
Parameters
Type | Name | Description |
---|---|---|
Int |
obj |
Overrides
Info(Double)
Retrieve the complete information of the given stream, including the extended description.
Can be invoked at any time of the stream's lifetime.
Declaration
public StreamInfo Info(double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Double | timeout | Optional timeout of the operation (default: no timeout). |
Returns
Type | Description |
---|---|
Stream |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
OpenStream(Double)
Subscribe to the data stream.
All samples pushed in at the other end from this moment onwards will be queued and
eventually be delivered in response to Pull
Declaration
public void OpenStream(double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Double | timeout | Optional timeout of the operation (default: no timeout). |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullChunk(Char[,], Double[], Double)
Pull a chunk of data from the inlet.
Declaration
public int PullChunk(char[, ] buffer, double[] times, double timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
Char[,] | buffer | A pre-allocated buffer where the channel data shall be stored. |
Double[] | times | A pre-allocated buffer where time stamps shall be stored. |
Double | timeout | Optionally the timeout for this operation, if any. When the timeout expires, the function may return before the entire buffer is filled. The default value of 0.0 will retrieve only data available for immediate pickup. |
Returns
Type | Description |
---|---|
Int32 | Number of samples written to the data and timestamp buffers. |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullChunk(Double[,], Double[], Double)
Pull a chunk of data from the inlet.
Declaration
public int PullChunk(double[, ] buffer, double[] times, double timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | buffer | A pre-allocated buffer where the channel data shall be stored. |
Double[] | times | A pre-allocated buffer where time stamps shall be stored. |
Double | timeout | Optionally the timeout for this operation, if any. When the timeout expires, the function may return before the entire buffer is filled. The default value of 0.0 will retrieve only data available for immediate pickup. |
Returns
Type | Description |
---|---|
Int32 | Number of samples written to the data and timestamp buffers. |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullChunk(Int16[,], Double[], Double)
Pull a chunk of data from the inlet.
Declaration
public int PullChunk(short[, ] buffer, double[] times, double timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
Int16[,] | buffer | A pre-allocated buffer where the channel data shall be stored. |
Double[] | times | A pre-allocated buffer where time stamps shall be stored. |
Double | timeout | Optionally the timeout for this operation, if any. When the timeout expires, the function may return before the entire buffer is filled. The default value of 0.0 will retrieve only data available for immediate pickup. |
Returns
Type | Description |
---|---|
Int32 | Number of samples written to the data and timestamp buffers. |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullChunk(Int32[,], Double[], Double)
Pull a chunk of data from the inlet.
Declaration
public int PullChunk(int[, ] buffer, double[] times, double timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32[,] | buffer | A pre-allocated buffer where the channel data shall be stored. |
Double[] | times | A pre-allocated buffer where time stamps shall be stored. |
Double | timeout | Optionally the timeout for this operation, if any. When the timeout expires, the function may return before the entire buffer is filled. The default value of 0.0 will retrieve only data available for immediate pickup. |
Returns
Type | Description |
---|---|
Int32 | Number of samples written to the data and timestamp buffers. |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullChunk(Single[,], Double[], Double)
Pull a chunk of data from the inlet.
Declaration
public int PullChunk(float[, ] buffer, double[] times, double timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
Single[,] | buffer | A pre-allocated buffer where the channel data shall be stored. |
Double[] | times | A pre-allocated buffer where time stamps shall be stored. |
Double | timeout | Optionally the timeout for this operation, if any. When the timeout expires, the function may return before the entire buffer is filled. The default value of 0.0 will retrieve only data available for immediate pickup. |
Returns
Type | Description |
---|---|
Int32 | Number of samples written to the data and timestamp buffers. |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullChunk(String[,], Double[], Double)
Pull a chunk of data from the inlet.
Declaration
public int PullChunk(string[, ] buffer, double[] times, double timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
String[,] | buffer | A pre-allocated buffer where the channel data shall be stored. |
Double[] | times | A pre-allocated buffer where time stamps shall be stored. |
Double | timeout | Optionally the timeout for this operation, if any. When the timeout expires, the function may return before the entire buffer is filled. The default value of 0.0 will retrieve only data available for immediate pickup. |
Returns
Type | Description |
---|---|
Int32 | Number of samples written to the data and timestamp buffers. |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullSample(Char[], Double)
Pull a sample from the inlet and read it into an array of values. Handles type checking and conversion.
Declaration
public double PullSample(char[] sample, double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Char[] | sample | An array to hold the resulting values. |
Double | timeout | Optional, the timeout for this operation, if any. Use 0.0 to make the function non-blocking. |
Returns
Type | Description |
---|---|
Double | The capture time of the sample on the remote machine, or 0.0 if no new sample was available.
To remap this time stamp to the local clock, add the value returned by Time |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullSample(Double[], Double)
Pull a sample from the inlet and read it into an array of values. Handles type checking and conversion.
Declaration
public double PullSample(double[] sample, double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Double[] | sample | An array to hold the resulting values. |
Double | timeout | Optional, the timeout for this operation, if any. Use 0.0 to make the function non-blocking. |
Returns
Type | Description |
---|---|
Double | The capture time of the sample on the remote machine, or 0.0 if no new sample was available.
To remap this time stamp to the local clock, add the value returned by Time |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullSample(Int16[], Double)
Pull a sample from the inlet and read it into an array of values. Handles type checking and conversion.
Declaration
public double PullSample(short[] sample, double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Int16[] | sample | An array to hold the resulting values. |
Double | timeout | Optional, the timeout for this operation, if any. Use 0.0 to make the function non-blocking. |
Returns
Type | Description |
---|---|
Double | The capture time of the sample on the remote machine, or 0.0 if no new sample was available.
To remap this time stamp to the local clock, add the value returned by Time |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullSample(Int32[], Double)
Pull a sample from the inlet and read it into an array of values. Handles type checking and conversion.
Declaration
public double PullSample(int[] sample, double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | sample | An array to hold the resulting values. |
Double | timeout | Optional, the timeout for this operation, if any. Use 0.0 to make the function non-blocking. |
Returns
Type | Description |
---|---|
Double | The capture time of the sample on the remote machine, or 0.0 if no new sample was available.
To remap this time stamp to the local clock, add the value returned by Time |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullSample(Single[], Double)
Pull a sample from the inlet and read it into an array of values. Handles type checking and conversion.
Declaration
public double PullSample(float[] sample, double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Single[] | sample | An array to hold the resulting values. |
Double | timeout | Optional, the timeout for this operation, if any. Use 0.0 to make the function non-blocking. |
Returns
Type | Description |
---|---|
Double | The capture time of the sample on the remote machine, or 0.0 if no new sample was available.
To remap this time stamp to the local clock, add the value returned by Time |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
PullSample(String[], Double)
Pull a sample from the inlet and read it into an array of values. Handles type checking and conversion.
Declaration
public double PullSample(string[] sample, double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
String[] | sample | An array to hold the resulting values. |
Double | timeout | Optional, the timeout for this operation, if any. Use 0.0 to make the function non-blocking. |
Returns
Type | Description |
---|---|
Double | The capture time of the sample on the remote machine, or 0.0 if no new sample was available.
To remap this time stamp to the local clock, add the value returned by Time |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
SamplesAvailable()
Query whether samples are currently available for immediate pickup.
Declaration
public int SamplesAvailable()
Returns
Type | Description |
---|---|
Int32 | Number of samples available. |
Remarks
that it is not a good idea to use Samplespull_*()
call would block:
to be sure, set the pull timeout to 0.0 or an acceptably low value.
If the underlying implementation supports it, the value will be the number of samples available (otherwise it will be 1 or 0).
TimeCorrection(Double)
Retrieve an estimated time correction offset for the given stream.
The first call to this function takes several miliseconds until a reliable first estimate is obtained. Subsequent calls are instantaneous (and rely on periodic background updates). The precision of these estimates should be below 1 ms (empirically within +/-0.2 ms).
Declaration
public double TimeCorrection(double timeout = 32000000)
Parameters
Type | Name | Description |
---|---|---|
Double | timeout | Optional timeout to acquire the first time-correction estimate (default: no timeout). |
Returns
Type | Description |
---|---|
Double | The time correction estimate. This is the number that needs to be added to a time stamp
that was remotely generated via |
Exceptions
Type | Condition |
---|---|
Lost |
If the stream source has been lost. |
WasClockReset()
Query whether the clock was potentially reset since the last call to Was
This is a rarely-used function that is only useful to applications that combine multiple Time
Declaration
public bool WasClockReset()
Returns
Type | Description |
---|---|
Boolean |
|