ovasCDriverLabStreamingLayer.cpp 19.1 KB
Newer Older
1 2 3

#if defined(TARGET_HAS_ThirdPartyLSL)

4
/*
5
 *
6
 * Notes: This code should be kept compatible with changes to LSL Output plugin in OpenViBE Acquisition Server,
7 8
 * and LSL Export box in Designer.
 *
9
 * This driver makes a few assumptions:
10 11 12
 *
 * Signal streams
 *    - are float32
13 14 15
 *    - dense, i.e. there are no dropped or extra samples in them
 *    - the driver fills a sample block consequently until either the block has been filled or
 *      time runs out. In case of the latter, the chunk is padded with NaNs.
16
 * Markers
17 18 19 20
 *    - are int32
 *    - not dense
 *    - markers are retimed wrt the current signal chunk
 *
21
 * Other notes: Due to network delays, it may be better to disable drift correction or
22
 * set the drift tolerance to high. This is because
23 24
 *  1) Signals are assumed dense, i.e. LSL pull results in samples stamped t,t+1,t+2,...
 *  2) However, Acquisition Server works in real time, so if there is a network delay between
25 26 27
 *     the samples stamped t and t+1, this delay does not indicate a delay in the original signal
 *     and it might not be correct to pad the corresponding signal block during the delay.
 *
28
 * Todo. It might make sense to improve this driver in the future to take into account the LSL
29
 * stamps when constructing each signal block. This is currently not done.
30
 *
31 32 33

 *
 *
34 35 36
 *
 */

37 38 39 40 41
#include <limits> // for NaN

#include "ovasCDriverLabStreamingLayer.h"
#include "ovasCConfigurationLabStreamingLayer.h"

Jussi Lindgren's avatar
Jussi Lindgren committed
42
#include <system/ovCTime.h>
43 44 45 46 47 48

#include <toolkit/ovtk_all.h>
#include <openvibe/ovITimeArithmetics.h>

#include <lsl_cpp.h>

49 50 51
#include <cmath>
#include <algorithm>

52 53 54 55 56
using namespace OpenViBEAcquisitionServer;
using namespace OpenViBE;
using namespace OpenViBE::Kernel;
using namespace std;

57
// In seconds
58
static const float64 g_LSL_samplingRateEstimatationDuration = 2.0;
59 60 61 62
static const float64 g_LSL_resolveTimeOut = 2.0;
static const float64 g_LSL_openTimeOut = 2.0;
static const float64 g_LSL_readTimeOut = 2.0;

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
static uint32 getClosestMultipleOf25(uint32 value)
{
	return uint32(((value + 12) / 25) * 25);
}

static uint32 getClosestPowerOf2(uint32 value)
{
	uint32 l_ui32BitShiftCount = 0;
	while ((1LL << l_ui32BitShiftCount) < value)
	{
		l_ui32BitShiftCount++;
	}

	if (l_ui32BitShiftCount > 0)
	{
		uint32 l_ui32Greater = uint32(1LL << l_ui32BitShiftCount);
		uint32 l_ui32Lesser = l_ui32Greater >> 1;
		if (l_ui32Greater - value < value - l_ui32Lesser)
		{
			return l_ui32Greater;
		}
		else
		{
			return l_ui32Lesser;
		}
	}

	return uint32(1LL << l_ui32BitShiftCount);
}

static uint32 getSmartFallbackSamplingRateEstimate(uint32 ui32LSLSamplingRate, bool bRoundToPowerOfTwoAndMultiple25=true)
{
	if (bRoundToPowerOfTwoAndMultiple25)
	{
		uint32 l_ui32ClosestMultipleOf25 = ::getClosestMultipleOf25(ui32LSLSamplingRate);
		uint32 l_ui32ClosestPowerOfTwo = ::getClosestPowerOf2(ui32LSLSamplingRate);
		uint32 l_ui32ClosestMultipleOf25Diff = uint32(std::abs(int32(l_ui32ClosestMultipleOf25) - int32(ui32LSLSamplingRate)));
		uint32 l_ui32ClosestPowerOfTwoDiff = uint32(std::abs(int32(l_ui32ClosestPowerOfTwo) - int32(ui32LSLSamplingRate)));
		if (l_ui32ClosestMultipleOf25Diff < l_ui32ClosestPowerOfTwoDiff)
		{
			ui32LSLSamplingRate = l_ui32ClosestMultipleOf25;
		}
		else
		{
			ui32LSLSamplingRate = l_ui32ClosestPowerOfTwo;
		}
	}
	return ui32LSLSamplingRate;
}

113 114 115 116 117 118 119 120
//___________________________________________________________________//
//                                                                   //

CDriverLabStreamingLayer::CDriverLabStreamingLayer(IDriverContext& rDriverContext)
	:IDriver(rDriverContext)
	,m_oSettings("AcquisitionServer_Driver_LabStreamingLayer", m_rDriverContext.getConfigurationManager())
	,m_pCallback(NULL)
	,m_ui32SampleCountPerSentBlock(0)
121
	,m_ui32LSLFallbackSamplingRate(0)
122 123
	,m_pSample(NULL)
	,m_pBuffer(NULL)
124
	,m_pSignalInlet(NULL)
125
	,m_pMarkerInlet(NULL)
126
	,m_bLimitSpeed(false)
127
{
128 129 130
	// The following class allows saving and loading driver settings from the acquisition server .conf file
	m_oSettings.add("Header", &m_oHeader);
	// To save your custom driver settings, register each variable to the SettingsHelper
131
	m_oSettings.add("LimitSpeed",       &m_bLimitSpeed);
132
	m_oSettings.add("SignalStreamName", &m_sSignalStream);
133
	m_oSettings.add("SignalStreamID",   &m_sSignalStreamID);
134
	m_oSettings.add("MarkerStreamName", &m_sMarkerStream);
135
	m_oSettings.add("MarkerStreamID",   &m_sMarkerStreamID);
136 137 138 139 140 141 142 143 144
	m_oSettings.add("FallbackSamplingRate", &m_ui32LSLFallbackSamplingRate);
	m_oSettings.load();

	/*
	for (uint32 i = 1; i < 260; i++)
	{
		rDriverContext.getLogManager() << LogLevel_Error << i << " --> " << getSmartFallbackSamplingRateEstimate(i) << "\n";
	}
	*/
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
}

CDriverLabStreamingLayer::~CDriverLabStreamingLayer(void)
{
}

const char* CDriverLabStreamingLayer::getName(void)
{
	return "LabStreamingLayer (LSL)";
}

//___________________________________________________________________//
//                                                                   //

boolean CDriverLabStreamingLayer::initialize(
	const uint32 ui32SampleCountPerSentBlock,
	IDriverCallback& rCallback)
{
	if(m_rDriverContext.isConnected()) return false;

165 166
	// Find the signal stream
	const std::vector<lsl::stream_info> l_vStreams = lsl::resolve_stream("name", m_sSignalStream.toASCIIString(), 1, g_LSL_resolveTimeOut);
167
	if(!l_vStreams.size()) {
168
		m_rDriverContext.getLogManager() << LogLevel_Error << "Error resolving signal stream with name [" << m_sSignalStream.toASCIIString() << "]\n";
169 170
		return false;
	}
171 172 173 174 175 176 177 178 179 180
	for(uint32 i=0;i<l_vStreams.size();i++)
	{
		m_oSignalStream = l_vStreams[i];
		if(l_vStreams[i].source_id() == std::string(m_sSignalStreamID.toASCIIString()))
		{
			// This is the best one
			break;
		}
		m_rDriverContext.getLogManager() << LogLevel_Trace << "Finally resolved signal stream to " << m_oSignalStream.name().c_str() << ", id " << m_oSignalStream.source_id().c_str() << "\n";
	}
181

182 183
	// Find the marker stream
	if(m_sMarkerStream!=CString("None"))
184
	{
185
		const std::vector<lsl::stream_info> l_vMarkerStreams = lsl::resolve_stream("name", m_sMarkerStream.toASCIIString(), 1, g_LSL_resolveTimeOut);
186
		if(!l_vMarkerStreams.size()) {
187
			m_rDriverContext.getLogManager() << LogLevel_Error <<  "Error resolving marker stream with name [" << m_sMarkerStream.toASCIIString() << "]\n";
188 189
			return false;
		}
190 191 192 193 194 195 196 197 198 199
		for(uint32 i=0;i<l_vMarkerStreams.size();i++)
		{
			m_oMarkerStream = l_vMarkerStreams[i];
			if(l_vMarkerStreams[i].source_id() == std::string(m_sMarkerStreamID.toASCIIString()))
			{
				// This is the best one
				break;
			}
		}
		m_rDriverContext.getLogManager() << LogLevel_Trace << "Finally resolved marker stream to " << m_oMarkerStream.name().c_str() << ", id " << m_oMarkerStream.source_id().c_str() << "\n";
200 201 202
	}
	else
	{
203 204 205
		// We do not have a marker stream. This is ok.
	}

206 207 208
	// Get the channel names. We open a temporary inlet for this, it will be closed after going out of scope. The actual inlet will be opened in start().
	m_rDriverContext.getLogManager() << LogLevel_Trace << "Polling channel names\n";
	lsl::stream_inlet l_oTmpInlet(m_oSignalStream, 360, 0, false);
209 210
	try
	{
211
		l_oTmpInlet.open_stream(g_LSL_openTimeOut);
212 213 214
	}
	catch(...)
	{
215 216 217 218 219
		m_rDriverContext.getLogManager() << LogLevel_Error <<  "Failed to open signal stream with name [" << m_oSignalStream.name().c_str() << "] for polling channel names\n";
		return false;
	}

	lsl::stream_info l_oFullInfo;
220 221
	try
	{
222
		l_oFullInfo = l_oTmpInlet.info(g_LSL_readTimeOut);
223 224 225
	}
	catch(...)
	{
226 227 228 229
		m_rDriverContext.getLogManager() << LogLevel_Error <<  "Timeout reading full stream info for [" << m_oSignalStream.name().c_str() << "] for polling channel names\n";
		return false;
	}

230 231 232
	// Now sets channel count and names
	m_oHeader.setChannelCount(m_oSignalStream.channel_count());

233
	const lsl::xml_element l_oChannels = l_oFullInfo.desc().child("channels");
234
	lsl::xml_element l_oChannel = l_oChannels.child("channel");
235 236 237 238 239 240 241 242 243 244 245
	for(uint32 i=0;i<m_oHeader.getChannelCount(); i++)
	{
		const char *l_sLabel = l_oChannel.child_value("label");

		if(l_sLabel)
		{
			m_oHeader.setChannelName(i, l_sLabel);
		}

		l_oChannel = l_oChannel.next_sibling("channel");
	}
246 247 248

	// Buffer to store a single sample
	m_pBuffer = new float32[m_oHeader.getChannelCount()];
249 250 251 252 253
	if(!m_pBuffer)
	{
		m_rDriverContext.getLogManager() << LogLevel_Error <<  "Memory allocation problem\n";
		return false;
	}
254

255
	// Buffer to store the signal chunk
256 257 258
	m_pSample=new float32[m_oHeader.getChannelCount()*ui32SampleCountPerSentBlock];
	if(!m_pSample)
	{
259
		m_rDriverContext.getLogManager() << LogLevel_Error <<  "Memory allocation problem\n";
260 261
		return false;
	}
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

	// Now sets sampling rate

	uint32 l_ui32LSLSamplingRate = static_cast<uint32>(m_oSignalStream.nominal_srate());
	if(l_ui32LSLSamplingRate == 0)
	{
		// Check GUI fallback
		if(m_ui32LSLFallbackSamplingRate != 0)
		{
			l_ui32LSLSamplingRate = m_ui32LSLFallbackSamplingRate;
			m_rDriverContext.getLogManager() << LogLevel_Info << "LSL sampling rate is not defined, falls back to [" << l_ui32LSLSamplingRate << "] - You can change this in the driver settings\n";
		}
		else
		{
			// Autodetection was requested, let`s go for a round
			m_rDriverContext.getLogManager() << LogLevel_Info << "LSL sampling rate is not defined, falls back to [" << CString("Autodetection") << "] - You can change this in the driver settings\n";

			try
			{
				l_oTmpInlet.open_stream(g_LSL_openTimeOut);

				// First drop all available samples
				while (l_oTmpInlet.samples_available() != 0)
				{
					l_oTmpInlet.pull_sample(m_pBuffer, m_oHeader.getChannelCount(), g_LSL_readTimeOut);
				}

				// Now capture incoming samples over a period of 2 secs
				uint32 l_ui32SampleCount = 0;
				float64 l_f64StartCaptureTime = l_oTmpInlet.pull_sample(m_pBuffer, m_oHeader.getChannelCount(), g_LSL_readTimeOut);
				float64 l_f64CurrentCaptureTime = l_f64StartCaptureTime;
				while(l_f64CurrentCaptureTime != 0.0 && l_f64CurrentCaptureTime-l_f64StartCaptureTime < g_LSL_samplingRateEstimatationDuration)
				{
295
					double l_fPulledSampleTime = l_oTmpInlet.pull_sample(m_pBuffer, m_oHeader.getChannelCount(), g_LSL_readTimeOut);
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
					if (l_fPulledSampleTime != 0)
					{
						l_ui32SampleCount++;
						l_f64CurrentCaptureTime = l_fPulledSampleTime;
					}
					else
					{
						m_rDriverContext.getLogManager() << LogLevel_Error << "Timed out while receiving samples from LSL stream, avoiding auto detection.\n";
						delete[] m_pBuffer;
						delete[] m_pSample;
						return false;
					}
				}

				// Finally set estimated sampling rate
				float64 l_f64Duration = l_f64CurrentCaptureTime-l_f64StartCaptureTime;
				uint32 l_ui32RawLSLSamplingRate = uint32(l_ui32SampleCount / l_f64Duration);
				uint32 l_ui32SmartLSLSamplingRate = getSmartFallbackSamplingRateEstimate(l_ui32RawLSLSamplingRate);

				if (l_ui32SmartLSLSamplingRate != l_ui32RawLSLSamplingRate)
				{
					m_rDriverContext.getLogManager() << LogLevel_Info << "Acquired " << l_ui32SampleCount << " on a duration of " << l_f64Duration << " seconds, sampling rate might be approx " << l_ui32RawLSLSamplingRate << " hz (adjusted to " << l_ui32SmartLSLSamplingRate << " hz to conform with typical EEG sampling rates).\n";
				}
				else
				{
					m_rDriverContext.getLogManager() << LogLevel_Info << "Acquired " << l_ui32SampleCount << " on a duration of " << l_f64Duration << " seconds, sampling rate might be approx " << l_ui32SmartLSLSamplingRate << " hz.\n";
				}

				l_ui32LSLSamplingRate = l_ui32SmartLSLSamplingRate;
			}
			catch(...)
			{
				m_rDriverContext.getLogManager() << LogLevel_Error << "Failed to detected actual LSL sampling rate\n";
				delete [] m_pBuffer;
				delete [] m_pSample;
				return false;
			}
		}
	}

	m_oHeader.setSamplingFrequency(l_ui32LSLSamplingRate);

	if(l_ui32LSLSamplingRate != m_oSignalStream.nominal_srate())
	{
		m_rDriverContext.getLogManager() << LogLevel_Info
			<< "Opened an LSL stream with " << m_oSignalStream.channel_count()
			<< " channels and a nominal rate of " << m_oSignalStream.nominal_srate() << " hz.\n";
	}
	else
	{
		m_rDriverContext.getLogManager() << LogLevel_Info
			<< "Opened an LSL stream with " << m_oSignalStream.channel_count()
			<< " channels and a nominal rate of " << m_oSignalStream.nominal_srate() << " hz"
			<< " adjusted to " << l_ui32LSLSamplingRate << " hz.\n";
	}

352 353 354 355 356 357 358 359 360 361 362
	// Stores parameters
	m_pCallback=&rCallback;
	m_ui32SampleCountPerSentBlock=ui32SampleCountPerSentBlock;
	return true;
}

boolean CDriverLabStreamingLayer::start(void)
{
	if(!m_rDriverContext.isConnected()) return false;
	if(m_rDriverContext.isStarted()) return false;

363 364
	m_pSignalInlet = new lsl::stream_inlet(m_oSignalStream, 360, 0, false);
	if(!m_pSignalInlet)
365
	{
366
		m_rDriverContext.getLogManager() << LogLevel_Error << "Error getting signal inlet for [" << m_oSignalStream.name().c_str()  << "]\n";
367 368 369
		return false;
	}

370 371
	try
	{
372
		m_pSignalInlet->open_stream(g_LSL_openTimeOut);
373 374 375
	}
	catch(...)
	{
376
		m_rDriverContext.getLogManager() << LogLevel_Error <<  "Failed to open signal stream with name [" << m_oSignalStream.name().c_str() << "]\n";
377 378 379
		return false;
	}

380
	if(m_sMarkerStream!=CString("None"))
381
	{
382
		m_pMarkerInlet = new lsl::stream_inlet(m_oMarkerStream, 360, 0, false);
383 384 385 386 387 388
		if(!m_pMarkerInlet)
		{
			m_rDriverContext.getLogManager() << LogLevel_Error <<  "Error getting marker inlet for [" << m_oMarkerStream.name().c_str()  << "]\n";
			return false;
		}

389 390
		try
		{
391
			m_pMarkerInlet->open_stream(g_LSL_openTimeOut);
392 393 394
		}
		catch(...)
		{
395
			m_rDriverContext.getLogManager() << LogLevel_Error << "Failed to open marker stream with name [" << m_oSignalStream.name().c_str()  << "]\n";
396 397 398 399
			return false;
		}
	}

400 401 402
	m_ui64StartTime=System::Time::zgetTime();
	m_ui64SampleCount = 0;

403 404 405 406 407 408 409 410 411
	return true;
}

boolean CDriverLabStreamingLayer::loop(void)
{
	if(!m_rDriverContext.isConnected()) return false;
	if(!m_rDriverContext.isStarted()) return true;

	const uint32 l_ui32nChannels = m_oHeader.getChannelCount();
412

413 414 415 416
	bool l_bTimeOut = false;
	uint32 l_ui32TimeOutAt = 0;
	bool l_bBlockStartTimeSet = false;
	float64 l_f64BlockStartTime = 0;
417

418 419 420 421
	// receive signal from the stream
	for(uint32 i=0;i<m_ui32SampleCountPerSentBlock;i++)
	{
		double captureTime = 0;
422 423
		try
		{
424
			captureTime = m_pSignalInlet->pull_sample(m_pBuffer,l_ui32nChannels,g_LSL_readTimeOut);
425 426 427
		}
		catch (...)
		{
428
			m_rDriverContext.getLogManager() << LogLevel_Error <<  "Failed to get signal sample from [" << m_oSignalStream.name().c_str()  << "]\n";
429 430
			return false;
		}
431
		if(captureTime!=0)
432
		{
433 434
			if(!l_bBlockStartTimeSet)
			{
435 436 437 438 439 440
				l_bBlockStartTimeSet = true;
				l_f64BlockStartTime = captureTime;
				//m_rDriverContext.getLogManager() << LogLevel_Info << "First cap time is " << captureTime << "\n";
			}

			// Sample ok, fill
441 442
			for(uint32 j=0;j<l_ui32nChannels;j++)
			{
443
				m_pSample[j*m_ui32SampleCountPerSentBlock+i] = m_pBuffer[j];
444 445
			}
		}
446 447 448 449 450 451
		else
		{
			// Timeout
			l_ui32TimeOutAt = i;
			l_bTimeOut = true;
			break;
452
		}
453
	}
454

455 456 457 458
	if(l_bTimeOut)
	{
		// We fill the rest of the buffer with NaNs
		for(uint32 i=l_ui32TimeOutAt;i<m_ui32SampleCountPerSentBlock;i++)
459
		{
460 461 462 463
			for(uint32 j=0;j<l_ui32nChannels;j++)
			{
				m_pSample[j*m_ui32SampleCountPerSentBlock+i] =  std::numeric_limits<float>::quiet_NaN();
			}
464
		}
465
		m_rDriverContext.getLogManager() << LogLevel_Info << "Timeout reading sample from " << l_ui32TimeOutAt << ", filled rest of block with NaN\n";
466
	}
467

468
	if(m_bLimitSpeed)
469
	{
470
		// If we were faster than what the AS expects, sleep.
471
		// n.b. This sleep may not be accurate on Windows (it may oversleep)
472 473 474 475 476 477
		const uint64 l_ui64TimeNow = System::Time::zgetTime() - m_ui64StartTime;
		const uint64 l_ui64TimeLimitForBuffer = ITimeArithmetics::sampleCountToTime(m_oHeader.getSamplingFrequency(), m_ui64SampleCount+m_ui32SampleCountPerSentBlock);

		if(l_ui64TimeNow < l_ui64TimeLimitForBuffer)
		{
			const uint64 l_ui64TimeToSleep = l_ui64TimeLimitForBuffer - l_ui64TimeNow;
478

479 480 481 482
//			std::cout << "PostNap " << ITimeArithmetics::timeToSeconds(l_ui64TimeToSleep)*1000 << "ms at " << m_ui64SampleCount+m_ui32SampleCountPerSentBlock << "\n";

			System::Time::zsleep(l_ui64TimeToSleep);
		}
483 484
	}

485
	m_ui64SampleCount += m_ui32SampleCountPerSentBlock;
486

487
	m_pCallback->setSamples(m_pSample);
488

489 490 491 492
	// receive and pass markers. Markers are timed wrt the beginning of the signal block.
	OpenViBE::CStimulationSet l_oStimulationSet;
	if(m_pMarkerInlet)
	{
493
		while(true)
494 495 496
		{
			int32 l_i32Marker;
			double captureTime = 0;
497 498
			try
			{
499
				captureTime = m_pMarkerInlet->pull_sample(&l_i32Marker,1,0); // timeout is 0 here on purpose, either we have markers or not
500 501 502
			}
			catch(...)
			{
503 504 505
				m_rDriverContext.getLogManager() << LogLevel_Error << "Failed to get marker from [" << m_oMarkerStream.name().c_str()  << "]\n";
				return false;
			}
506
			if(captureTime==0)
507 508 509 510 511 512
			{
				// no more markers available at the moment
				break;
			}
			// float64 l_f64Correction = m_pMarkerInlet->time_correction();
			// float64 l_f64StimTime = captureTime + l_f64Correction - l_f64FirstCaptureTime;
513

514 515 516 517 518 519
			// For openvibe, we need to set the stimulus time relative to the start of the chunk
			const float64 l_f64StimTime = captureTime - l_f64BlockStartTime;

			// m_rDriverContext.getLogManager() << LogLevel_Info << "Got a marker " << l_i32Marker << " at " << captureTime << " -> "
			//	<< l_f64StimTime << "s."
			//	<< "\n";
520 521 522 523 524 525 526 527

			l_oStimulationSet.appendStimulation(static_cast<uint64>(l_i32Marker), ITimeArithmetics::secondsToTime(l_f64StimTime), 0);
			// std::cout << "date " << l_f64StimTime << "\n";
		}
	}

	m_pCallback->setStimulationSet(l_oStimulationSet);

528 529 530 531 532
	// LSL is not forcing the sample stream to confirm to the nominal sample rate. Hence, data may be incoming
	// with slower or faster speed than implied by the rate (a little like reading from a file). In some
	// cases it may be meaningful to disable the following drift correction from the AS settings.
	m_rDriverContext.correctDriftSampleCount(m_rDriverContext.getSuggestedDriftCorrectionSampleCount());

533 534 535 536 537 538 539 540
	return true;
}

boolean CDriverLabStreamingLayer::stop(void)
{
	if(!m_rDriverContext.isConnected()) return false;
	if(!m_rDriverContext.isStarted()) return false;

541
	if(m_pSignalInlet)
542
	{
543
		m_pSignalInlet->close_stream();
544

545 546
		delete m_pSignalInlet;
		m_pSignalInlet = NULL;
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
	}

	if(m_pMarkerInlet)
	{
		m_pMarkerInlet->close_stream();

		delete m_pMarkerInlet;
		m_pMarkerInlet = NULL;
	}

	return true;
}

boolean CDriverLabStreamingLayer::uninitialize(void)
{
	if(!m_rDriverContext.isConnected()) return false;
	if(m_rDriverContext.isStarted()) return false;

	if(m_pBuffer)
	{
		delete[] m_pBuffer;
		m_pBuffer=NULL;
	}

571 572 573 574 575 576
	if(m_pSample)
	{
		delete[] m_pSample;
		m_pSample=NULL;
	}

577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
	m_pCallback=NULL;

	return true;
}

//___________________________________________________________________//
//                                                                   //
boolean CDriverLabStreamingLayer::isConfigurable(void)
{
	return true; // change to false if your device is not configurable
}

boolean CDriverLabStreamingLayer::configure(void)
{
	// Change this line if you need to specify some references to your driver attribute that need configuration, e.g. the connection ID.
592
	CConfigurationLabStreamingLayer m_oConfiguration(m_rDriverContext,
593 594
		OpenViBE::Directories::getDataDir() + "/applications/acquisition-server/interface-LabStreamingLayer.ui",
		m_oHeader,
595
		m_bLimitSpeed,
596
		m_sSignalStream,
597 598
		m_sSignalStreamID,
		m_sMarkerStream,
599 600 601
		m_sMarkerStreamID,
		m_ui32LSLFallbackSamplingRate);

602 603 604 605 606
	if(!m_oConfiguration.configure(m_oHeader))
	{
		return false;
	}
	m_oSettings.save();
607

608 609 610
	return true;
}

611
#endif