├── .gitignore ├── Binaries └── Win64 │ ├── liblsl64-debug.dll │ ├── liblsl64.dll │ ├── test_inlet.exe │ └── test_outlet.exe ├── Config └── FilterPlugin.ini ├── LICENSE ├── LabStreamingLayer.uplugin ├── README.md ├── Resources ├── Icon128.png ├── LSLInput.PNG └── LSLOutput.PNG ├── Source ├── LSL │ ├── LSL.Build.cs │ ├── Private │ │ ├── FLSL.cpp │ │ ├── LSLInletComponent.cpp │ │ ├── LSLOutletComponent.cpp │ │ └── LSLPrivatePCH.h │ └── Public │ │ ├── FLSL.h │ │ ├── LSLInletComponent.h │ │ ├── LSLOutletComponent.h │ │ └── LSLTypes.h └── ThirdParty │ └── liblsl │ ├── bin │ ├── lsl.dll │ └── lslver.exe │ ├── include │ ├── lsl │ │ ├── common.h │ │ ├── inlet.h │ │ ├── outlet.h │ │ ├── resolver.h │ │ ├── streaminfo.h │ │ ├── types.h │ │ └── xml.h │ ├── lsl_c.h │ └── lsl_cpp.h │ └── lib │ └── lsl.lib ├── Tests ├── CMakeLists.txt ├── SimpleControlSignalOutlet.py ├── test_inlet.cpp └── test_outlet.cpp └── zip_marketplace.py /.gitignore: -------------------------------------------------------------------------------- 1 | UE4Editor* 2 | UnrealEditor* 3 | .fuse* 4 | Intermediate/* 5 | UE4-* 6 | Tests/build* 7 | *.zip 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | *.obj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | #*.so 21 | #*.dylib 22 | #*.dll 23 | 24 | # Fortran module files 25 | *.mod 26 | 27 | # Compiled Static libraries 28 | #*.lai 29 | #*.la 30 | #*.a 31 | #*.lib 32 | 33 | # Executables 34 | #*.exe 35 | *.out 36 | *.app 37 | -------------------------------------------------------------------------------- /Binaries/Win64/liblsl64-debug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Binaries/Win64/liblsl64-debug.dll -------------------------------------------------------------------------------- /Binaries/Win64/liblsl64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Binaries/Win64/liblsl64.dll -------------------------------------------------------------------------------- /Binaries/Win64/test_inlet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Binaries/Win64/test_inlet.exe -------------------------------------------------------------------------------- /Binaries/Win64/test_outlet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Binaries/Win64/test_outlet.exe -------------------------------------------------------------------------------- /Config/FilterPlugin.ini: -------------------------------------------------------------------------------- 1 | [FilterPlugin] 2 | ; This section lists additional files which will be packaged along with your plugin. Paths should be listed relative to the root plugin directory, and 3 | ; may include "...", "*", and "?" wildcards to match directories, files, and individual characters respectively. 4 | ; 5 | ; Examples: 6 | ; /README.txt 7 | ; /Extras/... 8 | ; /Binaries/ThirdParty/*.dll 9 | /LICENCE 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2014-2018 Chadwick Boulay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LabStreamingLayer.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "LabStreamingLayer Plugin", 6 | "Description": "Inlet/Outlet for LabStreamingLayer", 7 | "Category": "Input Devices", 8 | "CreatedBy": "Chadwick Boulay", 9 | "CreatedByURL": "", 10 | "DocsURL": "https://labstreaminglayer.readthedocs.io/", 11 | "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/e204576bd4de4bfdaad28c06133def5c", 12 | "SupportURL": "https://github.com/labstreaminglayer/plugin-UE4", 13 | "EngineVersion": "5.2", 14 | "CanContainContent": true, 15 | "IsBetaVersion": false, 16 | "IsExperimentalVersion": false, 17 | "Installed": false, 18 | "Modules": [ 19 | { 20 | "Name": "LSL", 21 | "Type": "Runtime", 22 | "LoadingPhase": "PreDefault", 23 | "WhitelistPlatforms": [ 24 | "Win64" 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lsl-ue4 2 | 3 | LabStreamingLayer [plugin for Unreal Engine](https://docs.unrealengine.com/en-US/ProductionPipelines/Plugins/index.html) 4 | 5 | * LSL 1.14.0 6 | * UE 4.26 to 5.1 7 | 8 | # Usage Instructions 9 | 10 | ## Install 11 | 12 | This plugin is also available on the [Marketplace](https://www.unrealengine.com/marketplace/en-US/product/labstreaminglayer-plugin). 13 | 14 | To add it to your project, copy this entire folder into your `/[Project Root]/Plugins/` folder or you can even git clone it in there: `[Project Root]\Plugins> git clone https://github.com/labstreaminglayer/plugin-UE4.git LSL` or `git submodule add https://github.com/labstreaminglayer/plugin-UE4.git LSL` if you are already working in a git repo. If you want to use this plugin across multiple projects, it might be better to place it in your `/[UE4 Root]/Engine/Plugins/` folder. The UE4 Editor must be restarted after moving the plugin. You may be asked to rebuild the module when the editor relaunches; please choose "Yes" to rebuild. 15 | 16 | To verify the plugin is installed, open the Plugins menu (Edit > Plugins) and the plugin should be listed under the "Input Devices" category, possibly under the Project section at the bottom. 17 | 18 | ## Using LSL in a UE4 project 19 | 20 | ### Receiving external data with an LSL Inlet 21 | 22 | Inlets are available as 'scene components'. Typically that means attaching such a component to an object that needs access to a LSL data stream. The inlet component must be configured so that its [`continuous_resolver`](https://github.com/sccn/liblsl/blob/master/include/lsl_cpp.h#L1754-L1762) member can search for the desired stream. On every tick, the resolver checks to see if that stream is found and, if so, it creates its [`stream_inlet`](https://github.com/sccn/liblsl/blob/master/include/lsl_cpp.h#L1004-L1011) member and the resolver is deleted. On subsequent ticks the data will be pulled from the inlet then broadcast to `OnStreamUpdatedFloat`. 23 | 24 | Multiple different objects can each have a unique inlet to the same stream. This isn't very efficient because it means extra data buffers and tcp/ip communication for each object accessing that stream. If you find that you have multiple objects that need to access the same stream, it is instead better to group those objects under a parent object with a single LSLInlet component, then the child objects can bind to the OnStreamUpdatedFloat event. 25 | 26 | Here are some simple step-by-step instructions to a minimal LSL Inlet integration in a UE4 project. 27 | 28 | 0. Run a LSL stream on your network. It must have a `float` data type (and for this example, at least 2 channels). 29 | 1. Place an Actor (e.g. Cube) into the scene at Location (250, 0, 100). 30 | 2. In its transform property, make sure to set it to Movable. 31 | 3. Select the Actor, then Add Component, and under Custom, choose LSLInlet. 32 | 4. Provide the Stream Name and/or Stream Type to your float stream from step 0. 33 | 5. Convert the object to a Blueprint 34 | 6. Edit the blueprint. 35 | 7. Add a Vector variable called InitialLocation. 36 | 8. Add a float variable called ScaleFactor, click on the Eye to make it public, and set its default value to something reasonable (e.g. 50). 37 | 9. Select the Event Graph tab. 38 | 10. Wire GetActorLocation to SET Initial Location on Event BeginPlay (see screenshot). 39 | 11. Right-click on the LSLInlet component, choose events, and "On Stream Updated Float". 40 | 12. Connect the Float Array of the above component to 2 different Get (reference) nodes, indexing 0 and 1. 41 | 13. Connect those two floats to a Make Vector. Then scale the resulting vector by Scale Factor and add it to the initial location. 42 | 14. Connect the scaled and shifted vector to a Set Actor Location node that is updated by On Stream Updated Float. 43 | 15. Run the game and the cube should move according to the input. 44 | 45 | ![LSL Inlet](https://github.com/labstreaminglayer/plugin-UE4/raw/master/Resources/LSLInput.PNG "LSL Inlet in UE4") 46 | 47 | If the stream that you are connected to dies then one of two things will happen. If the stream has a UUID then the inlet will persist and simply continue to attempt fetching until the stream reappears. If the stream does not have a UUID then it cannot be reconnected; instead the inlet is destroyed and the resolver is recreated to search for another stream with matching predicate. The latter event will also trigger an error broadcast to the `OnStreamCaughtException` event. 48 | 49 | ### Sending event markers out with an LSL Outlet 50 | 51 | We are going to use overlap events in a sphere object to trigger sending markers over LSL. We need a way to have transient overlap events, both for onset and offset. I am going to use the cube from the inlet example above that will move (via LSL Inlet data) to overlap the target sphere, but you could use anything you want to create the overlap events. 52 | 53 | 1. Place a Sphere actor into the scene at (250, -150, 100). 54 | 2. Create and edit its Blueprint. 55 | 3. Add a LSLOutlet component. 56 | 4. Edit the LSLOutlet details. Stream Name: "UE4 Sphere"; Stream Type: "Markers"; Sampling Rate: 0.0; Channel Format: `string`. Add a Channel. 57 | 5. Drag and drop the LSLOutlet component onto the event graph. 58 | 6. From its instance node, drag off and create a "Push Sample String" node. 59 | 7. Wire the "Event ActorBeginOverlap" node to the Push Sample String node. 60 | 8. Drag off from the Push Sample String Node's "Data" port, and add a "Make Array" node. 61 | 9. Edit the Make Array first element to whatever string you want to indicate begin overlap. Try "Ouch!". (You could also wire in public variables so you could set these strings from the Editor.) 62 | 10. Repeat steps 5-9 except for "ActorEndOverlap". 63 | 11. Make sure the actor and the object that will overlap with it both have their collision setup properly. [See here for more info.](https://docs.unrealengine.com/en-US/InteractiveExperiences/Physics/Collision/Overview/index.html) Briefly, they both need "Generate Overlap Events" checked and the collision settings need Overlap checked for "World Dynamic". 64 | 12. Run the game and view the strings in another process with LSL. If you have Python and pylsl installed, this is as simple as `python -m pylsl.examples.ReceiveStringMarkers` 65 | 66 | ![LSL Outlet](https://github.com/labstreaminglayer/plugin-UE4/raw/master/Resources/LSLOutput.PNG "LSL Outlet in UE4") 67 | 68 | # Known Issues 69 | 70 | * The LSLInletComponent only supports float, double, and string data types. And the double data will be cast to float before being made available in blueprints. 71 | -------------------------------------------------------------------------------- /Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Resources/Icon128.png -------------------------------------------------------------------------------- /Resources/LSLInput.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Resources/LSLInput.PNG -------------------------------------------------------------------------------- /Resources/LSLOutput.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Resources/LSLOutput.PNG -------------------------------------------------------------------------------- /Source/LSL/LSL.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | using UnrealBuildTool; 4 | using System.IO; 5 | 6 | namespace UnrealBuildTool.Rules 7 | { 8 | 9 | public class LSL : ModuleRules 10 | { 11 | private string ModulePath 12 | { 13 | get { return ModuleDirectory; } 14 | } 15 | 16 | private string ThirdPartyPath 17 | { 18 | get { return Path.GetFullPath(Path.Combine(ModulePath, "..", "ThirdParty")); } 19 | } 20 | 21 | private string BinariesPath 22 | { 23 | get { return Path.GetFullPath(Path.Combine(ModulePath, "..", "..", "Binaries")); } 24 | } 25 | 26 | private string LibraryPath 27 | { 28 | get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "liblsl", "lib")); } 29 | } 30 | 31 | private string DllPath 32 | { 33 | get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "liblsl", "bin")); } 34 | } 35 | 36 | public LSL(ReadOnlyTargetRules Target) : base(Target) 37 | { 38 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 39 | bEnableExceptions = true; 40 | 41 | PrivateIncludePaths.AddRange(new string[] 42 | { 43 | Path.Combine(ModuleDirectory, "Private"), 44 | Path.Combine(ThirdPartyPath, "liblsl", "include"), 45 | }); 46 | 47 | PublicIncludePaths.AddRange(new string[] 48 | { 49 | Path.Combine(ModuleDirectory, "Public"), 50 | Path.Combine(ThirdPartyPath, "liblsl", "include"), 51 | }); 52 | 53 | PublicDependencyModuleNames.AddRange(new string[] 54 | { 55 | "Engine", 56 | "Core", 57 | "CoreUObject", 58 | "InputCore", 59 | "Projects", 60 | }); 61 | 62 | LoadLSLLib(Target); 63 | } 64 | 65 | public bool LoadLSLLib(ReadOnlyTargetRules Target) 66 | { 67 | if (Target.Platform == UnrealTargetPlatform.Win64) 68 | { 69 | PublicAdditionalLibraries.Add(Path.Combine(LibraryPath, "lsl.lib")); 70 | PublicDelayLoadDLLs.Add("lsl.dll"); 71 | RuntimeDependencies.Add(Path.Combine(DllPath, "lsl.dll")); 72 | } 73 | else if (Target.Platform == UnrealTargetPlatform.Mac) 74 | { 75 | PublicDelayLoadDLLs.Add(Path.Combine(DllPath, "liblsl.dylib")); 76 | RuntimeDependencies.Add(Path.Combine(DllPath, "liblsl.dylib")); 77 | } 78 | 79 | return true; 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Source/LSL/Private/FLSL.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #include "FLSL.h" 4 | #include "LSLPrivatePCH.h" 5 | #include "Interfaces/IPluginManager.h" 6 | 7 | DEFINE_LOG_CATEGORY(LogLSL) 8 | IMPLEMENT_MODULE(FLSL, LSL) 9 | 10 | void FLSL::StartupModule() 11 | { 12 | // Get the base directory of this plugin 13 | FString BaseDir = IPluginManager::Get().FindPlugin("LabStreamingLayer")->GetBaseDir(); 14 | 15 | // Add on the relative location of the third party dll and load it 16 | FString LibraryPath; 17 | 18 | #if PLATFORM_WINDOWS 19 | LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/liblsl/bin/lsl.dll")); 20 | #elif PLATFORM_MAC 21 | LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/liblsl/bin/liblsl.dylib")); 22 | #endif // PLATFORM_WINDOWS 23 | 24 | LibLslHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr; 25 | } 26 | 27 | void FLSL::ShutdownModule() 28 | { 29 | // Free the dll handle 30 | FPlatformProcess::FreeDllHandle(LibLslHandle); 31 | LibLslHandle = nullptr; 32 | } 33 | -------------------------------------------------------------------------------- /Source/LSL/Private/LSLInletComponent.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #include "LSLInletComponent.h" 4 | #include "LSLPrivatePCH.h" 5 | #include 6 | #include 7 | 8 | // Sets default values for this component's properties 9 | ULSLInletComponent::ULSLInletComponent() 10 | : StreamName(""), StreamType("") 11 | { 12 | bWantsInitializeComponent = true; 13 | PrimaryComponentTick.bCanEverTick = true; 14 | } 15 | 16 | void ULSLInletComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) 17 | { 18 | if (my_inlet != nullptr) 19 | { 20 | delete my_inlet; 21 | my_inlet = nullptr; 22 | } 23 | if (my_resolver != nullptr) 24 | { 25 | delete my_resolver; 26 | my_resolver = nullptr; 27 | } 28 | Super::EndPlay(EndPlayReason); 29 | } 30 | 31 | // Called every frame 32 | void ULSLInletComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) 33 | { 34 | Super::TickComponent( DeltaTime, TickType, ThisTickFunction ); 35 | 36 | if (my_inlet) 37 | { 38 | double timestamp = 1.0; 39 | try { 40 | 41 | 42 | while (timestamp > 0.0) 43 | { 44 | if (StreamDataFormat == EChannelFormat::cfmt_float32) 45 | { 46 | timestamp = my_inlet->pull_sample(FloatDataArray.GetData(), FloatDataArray.Num(), 0.0); 47 | if (timestamp > 0.0) 48 | { 49 | //UE_LOG(LogLSL, Log, TEXT("Pulled sample with timestamp %f and value %f"), timestamp, FloatDataArray[0]); 50 | //std::cout << "Timestamp" << timestamp << std::endl; 51 | OnStreamUpdatedFloat.Broadcast(FloatDataArray, DeltaTime); 52 | } 53 | } 54 | else if (StreamDataFormat == EChannelFormat::cfmt_double64) 55 | { 56 | timestamp = my_inlet->pull_sample(double_vec.data(), double_vec.size(), 0.0); 57 | if (timestamp > 0.0) 58 | { 59 | // UE_LOG(LogLSL, Log, TEXT("Pulled sample with timestamp %f and value %f"), timestamp, double_vec[0]); 60 | //std::cout << "Timestamp" << timestamp << std::endl; 61 | // Cast double to float 62 | for (size_t i = 0; i < double_vec.size(); i++) 63 | { 64 | FloatDataArray[i] = (float)double_vec[i]; 65 | } 66 | OnStreamUpdatedFloat.Broadcast(FloatDataArray, DeltaTime); 67 | } 68 | } 69 | else if (StreamDataFormat == EChannelFormat::cfmt_string) 70 | { 71 | timestamp = my_inlet->pull_sample(string_vec.data(), string_vec.size(), 0.0); 72 | if (timestamp > 0.0) 73 | { 74 | FString unrealString(string_vec[0].c_str()); 75 | // UE_LOG(LogLSL, Log, TEXT("Pulled string sample with timestamp %f and value %s"), timestamp, *unrealString); 76 | for (size_t i = 0; i < string_vec.size(); i++) 77 | { 78 | StringDataArray[i] = string_vec[i].c_str(); 79 | } 80 | OnStreamUpdatedString.Broadcast(StringDataArray, DeltaTime); 81 | } 82 | } 83 | } 84 | 85 | } 86 | catch (lsl::timeout_error& e) 87 | { 88 | delete my_inlet; 89 | my_inlet = nullptr; 90 | FString unrealErrorString(e.what()); 91 | UE_LOG(LogLSL, Warning, TEXT("Caught lsl::timeout_error: %s"), *unrealErrorString); 92 | OnStreamCaughtException.Broadcast(unrealErrorString); 93 | } 94 | } 95 | else 96 | { 97 | if (!my_resolver) 98 | { 99 | FString pred; 100 | if (StreamName != FString(TEXT(""))) 101 | { 102 | pred += "name='" + StreamName + "'"; 103 | } 104 | else if (StreamType != FString(TEXT(""))) 105 | { 106 | pred += "type='" + StreamType + "'"; 107 | } 108 | std::string pred_string(TCHAR_TO_UTF8(*pred)); 109 | my_resolver = new lsl::continuous_resolver(pred_string); 110 | } 111 | 112 | std::vector results = my_resolver->results(); 113 | if (!results.empty()) 114 | { 115 | UE_LOG(LogLSL, Log, TEXT("Stream found. Creating inlet.")); 116 | my_inlet = new lsl::stream_inlet(results[0], MaxBufLen, MaxChunkLen); 117 | StreamDataFormat = EChannelFormat(my_inlet->info().channel_format()); 118 | FloatDataArray.SetNumZeroed(0); 119 | double_vec.resize(0); 120 | StringDataArray.SetNumZeroed(0); 121 | if (StreamDataFormat == EChannelFormat::cfmt_float32) 122 | { 123 | FloatDataArray.SetNumZeroed(my_inlet->info().channel_count()); 124 | } 125 | else if (StreamDataFormat == EChannelFormat::cfmt_double64) 126 | { 127 | FloatDataArray.SetNumZeroed(my_inlet->info().channel_count()); 128 | double_vec.resize(my_inlet->info().channel_count()); 129 | } 130 | else if (StreamDataFormat == EChannelFormat::cfmt_string) 131 | { 132 | StringDataArray.SetNumZeroed(my_inlet->info().channel_count()); 133 | string_vec.resize(my_inlet->info().channel_count()); 134 | } 135 | 136 | // resolver can rest now 137 | delete my_resolver; 138 | my_resolver = nullptr; 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Source/LSL/Private/LSLOutletComponent.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #include "LSLOutletComponent.h" 4 | #include "LSLPrivatePCH.h" 5 | #include 6 | 7 | // Sets default values for this component's properties 8 | ULSLOutletComponent::ULSLOutletComponent() : 9 | StreamName(), 10 | StreamType(), 11 | SamplingRate(LSL_IRREGULAR_RATE), 12 | ChannelFormat(EChannelFormat::cfmt_float32), 13 | StreamID("NoStreamID") 14 | { 15 | // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features 16 | // off to improve performance if you don't need them. 17 | bWantsInitializeComponent = true; 18 | } 19 | 20 | // Called when the game starts 21 | void ULSLOutletComponent::BeginPlay() 22 | { 23 | Super::BeginPlay(); 24 | //lsl_streaminfo lsl_myinfo = lsl_create_streaminfo(TCHAR_TO_ANSI(*StreamName), TCHAR_TO_ANSI(*StreamType), ChannelCount, SamplingRate, (lsl_channel_format_t)ChannelFormat, TCHAR_TO_ANSI(*StreamID)); 25 | UE_LOG(LogLSL, Log, TEXT("Attempting to create stream outlet with name %s, type %s, sampling rate %d."), *StreamName, *StreamType, SamplingRate); 26 | lsl::stream_info data_info( 27 | TCHAR_TO_ANSI(*StreamName), 28 | TCHAR_TO_ANSI(*StreamType), 29 | (int16)Channels.Num(), 30 | (double)SamplingRate, 31 | lsl::channel_format_t(ChannelFormat), 32 | TCHAR_TO_ANSI(*StreamID) 33 | ); 34 | lsl::xml_element channels = data_info.desc().append_child("channels"); 35 | for (auto& ch : Channels) 36 | { 37 | channels.append_child("channel") 38 | .append_child_value("label", TCHAR_TO_UTF8(*(ch.Label))) 39 | .append_child_value("unit", TCHAR_TO_UTF8(*(ch.Unit))); 40 | } 41 | 42 | //TODO: Check to see if the stream already exists. 43 | my_outlet = new lsl::stream_outlet(data_info); 44 | } 45 | 46 | void ULSLOutletComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) 47 | { 48 | if (my_outlet != nullptr) 49 | { 50 | delete my_outlet; 51 | my_outlet = nullptr; 52 | } 53 | Super::EndPlay(EndPlayReason); 54 | } 55 | 56 | //push_sample functions 57 | void ULSLOutletComponent::PushSampleFloat(TArray data) 58 | { 59 | PushSample(data); 60 | } 61 | 62 | 63 | /* 64 | void ULSLOutletComponent::PushSampleDouble(TArray data) 65 | { 66 | my_outlet->push_sample(data.GetData()); 67 | } 68 | */ 69 | 70 | void ULSLOutletComponent::PushSampleLong(TArray data) 71 | { 72 | PushSample(data); 73 | } 74 | 75 | /* 76 | void ULSLOutletComponent::PushSampleInt(TArray data) 77 | { 78 | my_outlet->push_sample(data.GetData()); 79 | } 80 | */ 81 | 82 | /* 83 | void ULSLOutletComponent::PushSampleShort(TArray data) 84 | { 85 | my_outlet->push_sample(data.GetData()); 86 | } 87 | */ 88 | 89 | void ULSLOutletComponent::PushSampleString(TArray data) 90 | { 91 | if (my_outlet == nullptr) return; 92 | std::vector strVec; 93 | int32 b; 94 | for(b=0; b < data.Num(); b++) 95 | { 96 | strVec.push_back(TCHAR_TO_UTF8(*data[b])); 97 | } 98 | my_outlet->push_sample(strVec); 99 | } 100 | 101 | /* 102 | void ULSLOutletComponent::PushSampleChar(TArray data) 103 | { 104 | lsl_push_sample_ctp(lsl_myoutlet,const_cast(data),0.0,true); 105 | } 106 | */ 107 | -------------------------------------------------------------------------------- /Source/LSL/Private/LSLPrivatePCH.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #include "Modules/ModuleManager.h" 4 | #include "Core.h" 5 | #include "Engine.h" 6 | #include "FLSL.h" 7 | 8 | // You should place include statements to your module's private header files here. You only need to 9 | // add includes for headers that are used in most of your module's source files though. 10 | -------------------------------------------------------------------------------- /Source/LSL/Public/FLSL.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #pragma once 4 | 5 | #include "Modules/ModuleManager.h" 6 | 7 | DECLARE_LOG_CATEGORY_EXTERN(LogLSL, Log, All); 8 | 9 | /** 10 | * The public interface to this module. 11 | */ 12 | 13 | class FLSL : public IModuleInterface //, public IModularFeature? 14 | { 15 | public: 16 | virtual void StartupModule(); 17 | virtual void ShutdownModule(); 18 | 19 | private: 20 | void* LibLslHandle; 21 | }; 22 | -------------------------------------------------------------------------------- /Source/LSL/Public/LSLInletComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #pragma once 4 | 5 | #include "Components/SceneComponent.h" 6 | #pragma warning (push) 7 | #pragma warning (disable: 4800) 8 | #define LSL_CPP11 1 9 | #include "lsl_cpp.h" 10 | #pragma warning (pop) 11 | #include "LSLTypes.h" 12 | #include "LSLInletComponent.generated.h" 13 | 14 | 15 | 16 | UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) 17 | class LSL_API ULSLInletComponent : public USceneComponent 18 | { 19 | GENERATED_BODY() 20 | 21 | public: 22 | // Sets default values for this component's properties 23 | ULSLInletComponent(); 24 | 25 | virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; 26 | 27 | // Called every frame 28 | virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override; 29 | 30 | // Name of stream. Used to resolve stream. 31 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL) 32 | FString StreamName; 33 | 34 | // Type of stream. Used to resolve stream if name not present. 35 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL) 36 | FString StreamType; 37 | 38 | // Maximum buffer length in seconds if there is a nominal sampling rate, otherwise x100 in samples 39 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL) 40 | int32 MaxBufLen = 10; 41 | 42 | // The maximum size, in samples, at which chunks are transmitted. (0 = the chunk sizes used by the sender) 43 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL) 44 | int32 MaxChunkLen = 0; 45 | 46 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = LSL) 47 | EChannelFormat StreamDataFormat = EChannelFormat::cfmt_undefined; 48 | 49 | // Delegate triggered once per frame update for stream 50 | UPROPERTY(BlueprintAssignable, Category = LSL) 51 | FLSLStreamUpdatedFloatDelegate OnStreamUpdatedFloat; 52 | 53 | // Delegate triggered once per frame update for stream 54 | UPROPERTY(BlueprintAssignable, Category = LSL) 55 | FLSLStreamUpdatedStringDelegate OnStreamUpdatedString; 56 | 57 | UPROPERTY(BlueprintAssignable, Category = LSL) 58 | FLSLStreamCaughtExceptionDelegate OnStreamCaughtException; 59 | 60 | // TODO: More types of DataArrays 61 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = LSL) 62 | TArray FloatDataArray; 63 | 64 | UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = LSL) 65 | TArray StringDataArray; 66 | 67 | protected: 68 | lsl::stream_inlet *my_inlet; 69 | lsl::continuous_resolver* my_resolver; 70 | std::vector string_vec; 71 | std::vector double_vec; 72 | }; 73 | -------------------------------------------------------------------------------- /Source/LSL/Public/LSLOutletComponent.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #pragma once 4 | 5 | #include "Components/SceneComponent.h" 6 | #include "LSLTypes.h" 7 | #include "FLSL.h" 8 | #pragma warning (push) 9 | #pragma warning (disable: 4800) 10 | #define LSL_CPP11 1 11 | #include "lsl_cpp.h" 12 | #pragma warning (pop) 13 | #include "LSLOutletComponent.generated.h" 14 | 15 | 16 | UCLASS(Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) 17 | class LSL_API ULSLOutletComponent : public USceneComponent 18 | { 19 | GENERATED_BODY() 20 | 21 | public: 22 | // Sets default values for this component's properties 23 | ULSLOutletComponent(); 24 | 25 | // Called when the game starts 26 | virtual void BeginPlay() override; 27 | 28 | virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; 29 | 30 | // Name of stream. Used to build stream info 31 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL, meta = (ExposeOnSpawn = "true")) 32 | FString StreamName; 33 | 34 | // Type of stream. Used to build stream info 35 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL, meta = (ExposeOnSpawn = "true")) 36 | FString StreamType; 37 | 38 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL, meta = (ExposeOnSpawn = "true")) 39 | float SamplingRate; 40 | 41 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL, meta = (ExposeOnSpawn = "true")) 42 | EChannelFormat ChannelFormat; 43 | 44 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL, meta = (ExposeOnSpawn = "true")) 45 | FString StreamID; 46 | 47 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LSL, meta = (ExposeOnSpawn = "true")) 48 | TArray Channels; 49 | 50 | UFUNCTION(BlueprintCallable, Category = LSL) 51 | void PushSampleFloat(TArray data); 52 | 53 | //UFUNCTION(BlueprintCallable, Category = LSL) 54 | //void PushSampleDouble(TArray data); 55 | 56 | UFUNCTION(BlueprintCallable, Category = LSL) 57 | void PushSampleLong(TArray data); 58 | 59 | //UFUNCTION(BlueprintCallable, Category = LSL) 60 | //void PushSampleInt(TArray data); 61 | 62 | //UFUNCTION(BlueprintCallable, Category = LSL) 63 | //void PushSampleShort(TArray data); 64 | 65 | UFUNCTION(BlueprintCallable, Category = LSL) 66 | void PushSampleString(TArray data); 67 | 68 | /* 69 | UFUNCTION(BlueprintCallable, Category = LSL) 70 | void PushSampleChar(TArray data); 71 | */ 72 | template 73 | void PushSample(TArray data); 74 | 75 | protected: 76 | 77 | lsl::stream_outlet *my_outlet = nullptr; 78 | 79 | }; 80 | 81 | template 82 | inline void ULSLOutletComponent::PushSample(TArray data) { 83 | if (my_outlet == nullptr) { 84 | UE_LOG(LogLSL, Warning, TEXT("%s outlet isn't valid, can't push sample"), *(GetFName().ToString())); 85 | return; 86 | } 87 | if (data.Num() == 0) { 88 | UE_LOG(LogLSL, Warning, TEXT("Trying to push empty sample to %s, skipping"), *(GetFName().ToString())); 89 | return; 90 | } 91 | my_outlet->push_sample(data.GetData()); 92 | } 93 | -------------------------------------------------------------------------------- /Source/LSL/Public/LSLTypes.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Chadwick Boulay 2 | 3 | #pragma once 4 | 5 | #include "LSLTypes.generated.h" 6 | 7 | //--------------------------------------------------- 8 | // Delegate types 9 | //--------------------------------------------------- 10 | 11 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FLSLStreamUpdatedStringDelegate, const TArray&, StringArray, float, DeltaSeconds); 12 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FLSLStreamUpdatedFloatDelegate, const TArray&, FloatArray, float, DeltaSeconds); 13 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLSLStreamCaughtExceptionDelegate, const FString&, ErrorString); 14 | 15 | UENUM(BlueprintType) 16 | enum class EChannelFormat : uint8 17 | { 18 | cfmt_undefined =0 UMETA(DisplayName="undefined"), 19 | cfmt_float32 =1 UMETA(DisplayName="float32"), 20 | cfmt_double64 =2 UMETA(DisplayName="double64"), 21 | cfmt_string =3 UMETA(DisplayName="string"), 22 | cfmt_int32 =4 UMETA(DisplayName="int32"), 23 | cfmt_int16 =5 UMETA(DisplayName="int16"), 24 | cfmt_int8 =6 UMETA(DisplayName="int8"), 25 | cfmt_int64 =7 UMETA(DisplayName="int64") 26 | }; 27 | 28 | USTRUCT(BlueprintType) 29 | struct FChannelData 30 | { 31 | GENERATED_USTRUCT_BODY() 32 | 33 | UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = LSL) FString Label; 34 | UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = LSL) FString Unit; 35 | }; 36 | 37 | UCLASS() 38 | class ULSLTypes : public UObject 39 | { 40 | GENERATED_BODY() 41 | }; 42 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/bin/lsl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Source/ThirdParty/liblsl/bin/lsl.dll -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/bin/lslver.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Source/ThirdParty/liblsl/bin/lslver.exe -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //! @file common.h Global constants for liblsl 4 | 5 | #if defined(LIBLSL_FFI) 6 | // Skip any typedefs that might confuse a FFI header parser, e.g. cffi 7 | #elif defined(_MSC_VER) && _MSC_VER < 1600 8 | typedef signed char int8_t; 9 | typedef signed short int16_t; 10 | typedef signed int int32_t; 11 | typedef signed long long int64_t; 12 | typedef unsigned int uint32_t; 13 | #else 14 | #include 15 | #endif 16 | 17 | #if defined(_MSC_VER) && _MSC_VER < 1900 18 | #define __func__ __FUNCTION__ 19 | #endif 20 | 21 | /// LIBLSL_C_API expands function attributes needed for the linker 22 | #if defined(LIBLSL_STATIC) || defined(LIBLSL_FFI) 23 | #define LIBLSL_C_API 24 | #elif defined _WIN32 || defined __CYGWIN__ 25 | #if defined LIBLSL_EXPORTS 26 | #define LIBLSL_C_API __declspec(dllexport) 27 | #else 28 | #define LIBLSL_C_API __declspec(dllimport) 29 | #ifndef LSLNOAUTOLINK 30 | #pragma comment(lib, "lsl.lib") 31 | #endif 32 | #endif 33 | #pragma warning(disable : 4275) 34 | #else // Linux / OS X 35 | #define LIBLSL_C_API __attribute__((visibility("default"))) 36 | #endif 37 | 38 | /// Constant to indicate that a stream has variable sampling rate. 39 | #define LSL_IRREGULAR_RATE 0.0 40 | 41 | /** 42 | * Constant to indicate that a sample has the next successive time stamp. 43 | * 44 | * This is an optional optimization to transmit less data per sample. 45 | * The stamp is then deduced from the preceding one according to the stream's 46 | * sampling rate (in the case of an irregular rate, the same time stamp as 47 | * before will is assumed). */ 48 | #define LSL_DEDUCED_TIMESTAMP -1.0 49 | 50 | /// A very large time value (ca. 1 year); can be used in timeouts. 51 | #define LSL_FOREVER 32000000.0 52 | 53 | /** 54 | * Constant to indicate that there is no preference about how a data stream 55 | * shall be chunked for transmission. 56 | * (can be used for the chunking parameters in the inlet or the outlet). 57 | */ 58 | #define LSL_NO_PREFERENCE 0 59 | 60 | /// Data format of a channel (each transmitted sample holds an array of channels), 4 bytes wide 61 | typedef enum { 62 | /** For up to 24-bit precision measurements in the appropriate physical unit (e.g., microvolts). 63 | * Integers from -16777216 to 16777216 are represented accurately. */ 64 | cft_float32 = 1, 65 | /** For universal numeric data as long as permitted by network & disk budget. 66 | * The largest representable integer is 53-bit. */ 67 | cft_double64 = 2, 68 | /** For variable-length ASCII strings or data blobs, such as video frames, complex event 69 | descriptions, etc. */ 70 | cft_string = 3, 71 | /** For high-rate digitized formats that require 32-bit precision. 72 | * Depends critically on meta-data to represent meaningful units. 73 | * Useful for application event codes or other coded data. */ 74 | cft_int32 = 4, 75 | /** For very high rate signals (40Khz+) or consumer-grade audio. 76 | * For professional audio float is recommended. */ 77 | cft_int16 = 5, 78 | /// For binary signals or other coded data. Not recommended for encoding string data. 79 | cft_int8 = 6, 80 | /** 64 bit integers. Support for this type is not yet exposed in all languages. 81 | * Also, some builds of liblsl will not be able to send or receive data of this type. */ 82 | cft_int64 = 7, 83 | /// Can not be transmitted. 84 | cft_undefined = 0, 85 | 86 | // prevent compilers from assuming an instance fits in a single byte 87 | _cft_maxval = 0x7f000000 88 | } lsl_channel_format_t; 89 | 90 | // Abort compilation if lsl_channel_format_t isn't exactly 4 bytes wide 91 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L 92 | _Static_assert(sizeof(lsl_channel_format_t) == 4, "lsl_channel_format_t size breaks the LSL ABI"); 93 | #elif defined(__cplusplus) && __cplusplus >= 201103L 94 | static_assert (sizeof(lsl_channel_format_t) == 4, "lsl_channel_format_t size breaks the LSL ABI"); 95 | #elif !defined(LIBLSL_FFI) 96 | static char _lsl_channel_format_size_check[1 - 2*!(sizeof(lsl_channel_format_t)==4)]; 97 | #endif 98 | 99 | /// Post-processing options for stream inlets. 100 | typedef enum { 101 | /** No automatic post-processing; return the ground-truth time stamps for manual 102 | post-processing. This is the default behavior of the inlet. */ 103 | proc_none = 0, 104 | 105 | /** Perform automatic clock synchronization; equivalent to manually adding the time_correction() 106 | value to the received time stamps. */ 107 | proc_clocksync = 1, 108 | 109 | /** Remove jitter from time stamps. 110 | * 111 | * This will apply a smoothing algorithm to the received time stamps; the smoothing needs to see 112 | * a minimum number of samples (30-120 seconds worst-case) until the remaining jitter is 113 | * consistently below 1ms. */ 114 | proc_dejitter = 2, 115 | 116 | /** Force the time-stamps to be monotonically ascending. 117 | * 118 | * Only makes sense if timestamps are dejittered. */ 119 | proc_monotonize = 4, 120 | 121 | /** Post-processing is thread-safe (same inlet can be read from by multiple threads); 122 | * uses somewhat more CPU. */ 123 | proc_threadsafe = 8, 124 | 125 | /// The combination of all possible post-processing options. 126 | proc_ALL = 1 | 2 | 4 | 8, 127 | 128 | // prevent compilers from assuming an instance fits in a single byte 129 | _proc_maxval = 0x7f000000 130 | } lsl_processing_options_t; 131 | 132 | /// Possible error codes. 133 | typedef enum { 134 | /// No error occurred 135 | lsl_no_error = 0, 136 | 137 | /// The operation failed due to a timeout. 138 | lsl_timeout_error = -1, 139 | 140 | /// The stream has been lost. 141 | lsl_lost_error = -2, 142 | 143 | /// An argument was incorrectly specified (e.g., wrong format or wrong length). 144 | lsl_argument_error = -3, 145 | 146 | /// Some other internal error has happened. 147 | lsl_internal_error = -4, 148 | 149 | // prevent compilers from assuming an instance fits in a single byte 150 | _lsl_error_code_maxval = 0x7f000000 151 | } lsl_error_code_t; 152 | 153 | /// Flags for outlet_ex and inlet_ex 154 | typedef enum { 155 | /// Keep legacy behavior: max_buffered / max_buflen is in seconds; use asynch transfer. 156 | transp_default = 0, 157 | 158 | /// The supplied max_buf value is in samples. 159 | transp_bufsize_samples = 1, 160 | 161 | /// The supplied max_buf should be scaled by 0.001. 162 | transp_bufsize_thousandths = 2, 163 | 164 | // prevent compilers from assuming an instance fits in a single byte 165 | _lsl_transport_options_maxval = 0x7f000000 166 | } lsl_transport_options_t; 167 | 168 | /// Return an explanation for the last error 169 | extern LIBLSL_C_API const char *lsl_last_error(void); 170 | 171 | /** 172 | * LSL version the binary was compiled against 173 | * 174 | * Used either to check if the same version is used 175 | * (`if(lsl_protocol_version()!=LIBLSL_COMPILE_HEADER_VERSION`) … 176 | * or to require a certain set of features: 177 | * ``` 178 | * #if LIBLSL_COMPILE_HEADER_VERSION > 113 179 | * do_stuff(); 180 | * #endif 181 | * ``` 182 | * */ 183 | #define LIBLSL_COMPILE_HEADER_VERSION 114 184 | 185 | /** 186 | * Protocol version. 187 | * 188 | * The major version is `protocol_version() / 100;` 189 | * The minor version is `protocol_version() % 100;` 190 | * 191 | * Clients with different minor versions are protocol-compatible while clients 192 | * with different major versions will refuse to work together. 193 | */ 194 | extern LIBLSL_C_API int32_t lsl_protocol_version(); 195 | 196 | /** 197 | * Version of the liblsl library. 198 | * 199 | * The major version is `library_version() / 100;` 200 | * The minor version is `library_version() % 100;` 201 | */ 202 | extern LIBLSL_C_API int32_t lsl_library_version(); 203 | 204 | /** 205 | * Get a string containing library information. 206 | * 207 | * The format of the string shouldn't be used for anything important except giving a debugging 208 | * person a good idea which exact library version is used. */ 209 | extern LIBLSL_C_API const char *lsl_library_info(void); 210 | 211 | /** 212 | * Obtain a local system time stamp in seconds. 213 | * 214 | * The resolution is better than a millisecond. 215 | * This reading can be used to assign time stamps to samples as they are being acquired. 216 | * If the "age" of a sample is known at a particular time (e.g., from USB transmission 217 | * delays), it can be used as an offset to lsl_local_clock() to obtain a better estimate of 218 | * when a sample was actually captured. See lsl_push_sample() for a use case. 219 | */ 220 | extern LIBLSL_C_API double lsl_local_clock(); 221 | 222 | /** 223 | * Deallocate a string that has been transferred to the application. 224 | * 225 | * Rarely used: the only use case is to deallocate the contents of 226 | * string-valued samples received from LSL in an application where 227 | * no free() method is available (e.g., in some scripting languages). 228 | */ 229 | extern LIBLSL_C_API void lsl_destroy_string(char *s); 230 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/inlet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common.h" 3 | #include "types.h" 4 | 5 | 6 | /// @file inlet.h Stream inlet functions 7 | 8 | /** @defgroup lsl_inlet The lsl_inlet object 9 | * @{ 10 | */ 11 | 12 | /** 13 | * Construct a new stream inlet from a resolved stream info. 14 | * @param info A resolved stream info object (as coming from one of the resolver functions). 15 | * @note The inlet makes a copy of the info object at its construction. 16 | * @note The stream_inlet may also be constructed with a fully-specified stream_info, if the desired 17 | * channel format and count is already known up-front, but this is strongly discouraged and should 18 | * only ever be done if there is no time to resolve the stream up-front (e.g., due to limitations 19 | * in the client program). 20 | * @param max_buflen Optionally the maximum amount of data to buffer (in seconds if there is a 21 | * nominal sampling rate, otherwise x100 in samples). 22 | * 23 | * Recording applications want to use a fairly large buffer size here, while real-time applications 24 | * would only buffer as much as they need to perform their next calculation. 25 | * 26 | * A good default is 360, which corresponds to 6 minutes of data. 27 | * @param max_chunklen Optionally the maximum size, in samples, at which chunks are transmitted. 28 | * If specified as 0, the chunk sizes preferred by the sender are used. 29 | * Recording applications can use a generous size here (leaving it to the network how to pack 30 | * things), while real-time applications may want a finer (perhaps 1-sample) granularity. 31 | * @param recover Try to silently recover lost streams that are recoverable (=those that that have a 32 | * source_id set). 33 | * 34 | * It is generally a good idea to enable this, unless the application wants to act in a special way 35 | * when a data provider has temporarily crashed. 36 | * 37 | * If recover is 0 or the stream is not recoverable, most outlet functions will return an 38 | * #lsl_lost_error if the stream's source is lost. 39 | * @return A newly created lsl_inlet handle or NULL in the event that an error occurred. 40 | */ 41 | extern LIBLSL_C_API lsl_inlet lsl_create_inlet(lsl_streaminfo info, int32_t max_buflen, int32_t max_chunklen, int32_t recover); 42 | /** @copydoc lsl_create_inlet() 43 | * @param flags An integer that is the result of bitwise OR'ing one or more options from 44 | * #lsl_transport_options_t together (e.g., #transp_bufsize_samples) 45 | */ 46 | extern LIBLSL_C_API lsl_inlet lsl_create_inlet_ex(lsl_streaminfo info, int32_t max_buflen, 47 | int32_t max_chunklen, int32_t recover, lsl_transport_options_t flags); 48 | 49 | /** 50 | * Destructor. 51 | * The inlet will automatically disconnect if destroyed. 52 | */ 53 | extern LIBLSL_C_API void lsl_destroy_inlet(lsl_inlet in); 54 | 55 | /** 56 | * Retrieve the complete information of the given stream, including the extended description. 57 | * Can be invoked at any time of the stream's lifetime. 58 | * @param in The lsl_inlet object to act on. 59 | * @param timeout Timeout of the operation. Use LSL_FOREVER to effectively disable it. 60 | * @param[out] ec Error code: if nonzero, can be either lsl_timeout_error (if the timeout has 61 | * expired) or #lsl_lost_error (if the stream source has been lost). 62 | * @return A copy of the full streaminfo of the inlet or NULL in the event that an error happened. 63 | * @note It is the user's responsibility to destroy it when it is no longer needed. 64 | */ 65 | extern LIBLSL_C_API lsl_streaminfo lsl_get_fullinfo(lsl_inlet in, double timeout, int32_t *ec); 66 | 67 | /** 68 | * Subscribe to the data stream. 69 | * 70 | * All samples pushed in at the other end from this moment onwards will be queued and 71 | * eventually be delivered in response to pull_sample() calls. 72 | * Pulling a sample without some preceding lsl_open_stream() is permitted (the stream will then be 73 | * opened implicitly). 74 | * @param in The lsl_inlet object to act on. 75 | * @param timeout Optional timeout of the operation. Use LSL_FOREVER to effectively disable it. 76 | * @param[out] ec Error code: if nonzero, can be either #lsl_timeout_error (if the timeout has 77 | * expired) or lsl_lost_error (if the stream source has been lost). 78 | */ 79 | extern LIBLSL_C_API void lsl_open_stream(lsl_inlet in, double timeout, int32_t *ec); 80 | 81 | /** 82 | * Drop the current data stream. 83 | * 84 | * All samples that are still buffered or in flight will be dropped and transmission 85 | * and buffering of data for this inlet will be stopped. If an application stops being 86 | * interested in data from a source (temporarily or not) but keeps the outlet alive, 87 | * it should call lsl_close_stream() to not waste unnecessary system and network 88 | * resources. 89 | */ 90 | extern LIBLSL_C_API void lsl_close_stream(lsl_inlet in); 91 | 92 | /** 93 | * @brief Retrieve an estimated time correction offset for the given stream. 94 | * 95 | * The first call to this function takes several milliseconds until a reliable first estimate is 96 | * obtained. Subsequent calls are instantaneous (and rely on periodic background updates). 97 | * 98 | * On a well-behaved network, the precision of these estimates should be below 1 ms (empirically it 99 | * is within +/-0.2 ms). 100 | * 101 | * To get a measure of whether the network is well-behaved, use #lsl_time_correction_ex and check 102 | * uncertainty (which maps to round-trip-time). 0.2 ms is typical of wired networks. 103 | * 104 | * 2 ms is typical of wireless networks. The number can be much higher on poor networks. 105 | * 106 | * @param in The lsl_inlet object to act on. 107 | * @param timeout Timeout to acquire the first time-correction estimate. 108 | * Use LSL_FOREVER to defuse the timeout. 109 | * @param[out] ec Error code: if nonzero, can be either #lsl_timeout_error (if the timeout has 110 | * expired) or lsl_lost_error (if the stream source has been lost). 111 | * @return The time correction estimate. 112 | * This is the number that needs to be added to a time stamp that was remotely generated via 113 | * lsl_local_clock() to map it into the local clock domain of this machine. 114 | */ 115 | extern LIBLSL_C_API double lsl_time_correction(lsl_inlet in, double timeout, int32_t *ec); 116 | /** @copydoc lsl_time_correction() 117 | * @param remote_time The current time of the remote computer that was used to generate this 118 | * time_correction. 119 | * If desired, the client can fit time_correction vs remote_time to improve the real-time 120 | * time_correction further. 121 | * @param uncertainty The maximum uncertainty of the given time correction. 122 | */ 123 | extern LIBLSL_C_API double lsl_time_correction_ex(lsl_inlet in, double *remote_time, double *uncertainty, double timeout, int32_t *ec); 124 | 125 | 126 | /** 127 | * Set post-processing flags to use. 128 | * 129 | * By default, the inlet performs NO post-processing and returns the ground-truth time stamps, which 130 | * can then be manually synchronized using time_correction(), and then smoothed/dejittered if 131 | * desired. 132 | * 133 | * This function allows automating these two and possibly more operations. 134 | * @warning When you enable this, you will no longer receive or be able to recover the original time 135 | * stamps. 136 | * @param in The lsl_inlet object to act on. 137 | * @param flags An integer that is the result of bitwise OR'ing one or more options from 138 | * #lsl_processing_options_t together (e.g., #proc_clocksync|#proc_dejitter); 139 | * a good setting is to use #proc_ALL. 140 | * @return The error code: if nonzero, can be #lsl_argument_error if an unknown flag was passed in. 141 | */ 142 | extern LIBLSL_C_API int32_t lsl_set_postprocessing(lsl_inlet in, uint32_t flags); 143 | 144 | 145 | /* === Pulling a sample from the inlet === */ 146 | 147 | /** 148 | * Pull a sample from the inlet and read it into a pointer to values. 149 | * Handles type checking & conversion. 150 | * @param in The #lsl_inlet object to act on. 151 | * @param[out] buffer A pointer to hold the resulting values. 152 | * @param buffer_elements The number of samples allocated in the buffer. 153 | * @attention It is the responsibility of the user to allocate enough memory. 154 | * @param timeout The timeout for this operation, if any. 155 | * Use #LSL_FOREVER to effectively disable it. It is also permitted to use 0.0 here; 156 | * in this case a sample is only returned if one is currently buffered. 157 | * @param[out] ec Error code: can be either no error or #lsl_lost_error 158 | * (if the stream source has been lost).
159 | * @note If the timeout expires before a new sample was received the function returns 0.0; 160 | * ec is *not* set to #lsl_timeout_error (because this case is not considered an error condition). 161 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 162 | * available. To remap this time stamp to the local clock, add the value returned by 163 | * lsl_time_correction() to it. 164 | * @{ 165 | */ 166 | extern LIBLSL_C_API double lsl_pull_sample_f(lsl_inlet in, float *buffer, int32_t buffer_elements, double timeout, int32_t *ec); 167 | extern LIBLSL_C_API double lsl_pull_sample_d(lsl_inlet in, double *buffer, int32_t buffer_elements, double timeout, int32_t *ec); 168 | extern LIBLSL_C_API double lsl_pull_sample_l(lsl_inlet in, int64_t *buffer, int32_t buffer_elements, double timeout, int32_t *ec); 169 | extern LIBLSL_C_API double lsl_pull_sample_i(lsl_inlet in, int32_t *buffer, int32_t buffer_elements, double timeout, int32_t *ec); 170 | extern LIBLSL_C_API double lsl_pull_sample_s(lsl_inlet in, int16_t *buffer, int32_t buffer_elements, double timeout, int32_t *ec); 171 | extern LIBLSL_C_API double lsl_pull_sample_c(lsl_inlet in, char *buffer, int32_t buffer_elements, double timeout, int32_t *ec); 172 | extern LIBLSL_C_API double lsl_pull_sample_str(lsl_inlet in, char **buffer, int32_t buffer_elements, double timeout, int32_t *ec); 173 | ///@} 174 | 175 | /** @copydoc lsl_pull_sample_f 176 | * These strings may contains 0's, therefore the lengths are read into the buffer_lengths array. 177 | * @param buffer_lengths 178 | * A pointer to an array that holds the resulting lengths for each returned binary string.*/ 179 | extern LIBLSL_C_API double lsl_pull_sample_buf(lsl_inlet in, char **buffer, uint32_t *buffer_lengths, int32_t buffer_elements, double timeout, int32_t *ec); 180 | 181 | /** 182 | * Pull a sample from the inlet and read it into a custom struct or buffer. 183 | * 184 | * Overall size checking but no type checking or conversion are done. 185 | * Do not use for variable-size/string-formatted streams. 186 | * @param in The #lsl_inlet object to act on. 187 | * @param[out] buffer A pointer to hold the resulting values. 188 | * @param buffer_bytes Length of the array held by buffer in bytes, not items 189 | * @param timeout The timeout for this operation, if any. 190 | * Use #LSL_FOREVER to effectively disable it. It is also permitted to use 0.0 here; 191 | * in this case a sample is only returned if one is currently buffered. 192 | * @param[out] ec Error code: can be either no error or #lsl_lost_error 193 | * (if the stream source has been lost).
194 | * @note If the timeout expires before a new sample was received the function returns 0.0; 195 | * ec is *not* set to #lsl_timeout_error (because this case is not considered an error condition). 196 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 197 | * available. To remap this time stamp to the local clock, add the value returned by 198 | * lsl_time_correction() to it. 199 | */ 200 | extern LIBLSL_C_API double lsl_pull_sample_v(lsl_inlet in, void *buffer, int32_t buffer_bytes, double timeout, int32_t *ec); 201 | 202 | /** 203 | * Pull a chunk of data from the inlet and read it into a buffer. 204 | * 205 | * Handles type checking & conversion. 206 | * 207 | * @attention Note that the provided data buffer size is measured in channel values (e.g. floats) 208 | * rather than in samples. 209 | * @param in The lsl_inlet object to act on. 210 | * @param[out] data_buffer A pointer to a buffer of data values where the results shall be stored. 211 | * @param[out] timestamp_buffer A pointer to a double buffer where time stamps shall be stored. 212 | * 213 | * If this is NULL, no time stamps will be returned. 214 | * @param data_buffer_elements The size of the data buffer, in channel data elements (of type T). 215 | * Must be a multiple of the stream's channel count. 216 | * @param timestamp_buffer_elements The size of the timestamp buffer. 217 | * 218 | * If a timestamp buffer is provided then this must correspond to the same number of samples as 219 | * data_buffer_elements. 220 | * @param timeout The timeout for this operation, if any. 221 | * 222 | * When the timeout expires, the function may return before the entire buffer is filled. 223 | * The default value of 0.0 will retrieve only data available for immediate pickup. 224 | * @param[out] ec Error code: can be either no error or #lsl_lost_error (if the stream source has 225 | * been lost). 226 | * @note if the timeout expires before a new sample was received the function returns 0.0; 227 | * ec is *not* set to #lsl_timeout_error (because this case is not considered an error condition). 228 | * @return data_elements_written Number of channel data elements written to the data buffer. 229 | * @{ 230 | */ 231 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_f(lsl_inlet in, float *data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 232 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_d(lsl_inlet in, double *data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 233 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_l(lsl_inlet in, int64_t *data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 234 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_i(lsl_inlet in, int32_t *data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 235 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_s(lsl_inlet in, int16_t *data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 236 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_c(lsl_inlet in, char *data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 237 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_str(lsl_inlet in, char **data_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 238 | 239 | ///@} 240 | 241 | /** 242 | * Pull a chunk of data from the inlet and read it into an array of binary strings. 243 | * 244 | * These strings may contains 0's, therefore the lengths are read into the lengths_buffer array. 245 | * Handles type checking & conversion. 246 | * IMPORTANT: Note that the provided data buffer size is measured in channel values (e.g., floats) 247 | * rather than in samples. 248 | * @param in The lsl_inlet object to act on. 249 | * @param[out] data_buffer A pointer to a buffer of data values where the results shall be stored. 250 | * @param[out] lengths_buffer A pointer to an array that holds the resulting lengths for each 251 | * returned binary string. 252 | * @param timestamp_buffer A pointer to a buffer of timestamp values where time stamps shall be 253 | * stored. If this is NULL, no time stamps will be returned. 254 | * @param data_buffer_elements The size of the data buffer, in channel data elements (of type T). 255 | * Must be a multiple of the stream's channel count. 256 | * @param timestamp_buffer_elements The size of the timestamp buffer. If a timestamp buffer is 257 | * provided then this must correspond to the same number of samples as data_buffer_elements. 258 | * @param timeout The timeout for this operation, if any. 259 | * 260 | * When the timeout expires, the function may return before the entire buffer is filled. 261 | * 262 | * The default value of 0.0 will retrieve only data available for immediate pickup. 263 | * @param[out] ec Error code: can be either no error or #lsl_lost_error (if the stream source has 264 | * been lost). 265 | * @note If the timeout expires before a new sample was received the function returns 0.0; ec is 266 | * *not* set to #lsl_timeout_error (because this case is not considered an error condition). 267 | * @return data_elements_written Number of channel data elements written to the data buffer. 268 | */ 269 | 270 | extern LIBLSL_C_API unsigned long lsl_pull_chunk_buf(lsl_inlet in, char **data_buffer, uint32_t *lengths_buffer, double *timestamp_buffer, unsigned long data_buffer_elements, unsigned long timestamp_buffer_elements, double timeout, int32_t *ec); 271 | 272 | /** 273 | * Query whether samples are currently available for immediate pickup. 274 | * 275 | * Note that it is not a good idea to use samples_available() to determine whether 276 | * a pull_*() call would block: to be sure, set the pull timeout to 0.0 or an acceptably 277 | * low value. If the underlying implementation supports it, the value will be the number of 278 | * samples available (otherwise it will be 1 or 0). 279 | */ 280 | extern LIBLSL_C_API uint32_t lsl_samples_available(lsl_inlet in); 281 | 282 | /// Drop all queued not-yet pulled samples, return the nr of dropped samples 283 | extern LIBLSL_C_API uint32_t lsl_inlet_flush(lsl_inlet in); 284 | 285 | /** 286 | * Query whether the clock was potentially reset since the last call to lsl_was_clock_reset(). 287 | * 288 | * This is rarely-used function is only needed for applications that combine multiple time_correction 289 | * values to estimate precise clock drift if they should tolerate cases where the source machine was 290 | * hot-swapped or restarted. 291 | */ 292 | extern LIBLSL_C_API uint32_t lsl_was_clock_reset(lsl_inlet in); 293 | 294 | /** 295 | * Override the half-time (forget factor) of the time-stamp smoothing. 296 | * 297 | * The default is 90 seconds unless a different value is set in the config file. 298 | * 299 | * Using a longer window will yield lower jitter in the time stamps, but longer windows will have 300 | * trouble tracking changes in the clock rate (usually due to temperature changes); the default is 301 | * able to track changes up to 10 degrees C per minute sufficiently well. 302 | * @param in The lsl_inlet object to act on. 303 | * @param value The new value, in seconds. This is the time after which a past sample 304 | * will be weighted by 1/2 in the exponential smoothing window. 305 | * @return The error code: if nonzero, can be #lsl_argument_error if an unknown flag was passed in. 306 | */ 307 | extern LIBLSL_C_API int32_t lsl_smoothing_halftime(lsl_inlet in, float value); 308 | 309 | /// @} 310 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/outlet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "./common.h" 3 | #include "types.h" 4 | 5 | /// @file outlet.h Stream outlet functions 6 | 7 | /** @defgroup outlet The lsl_outlet object 8 | * 9 | * This object represents an outlet sending data to all connected inlets. 10 | * 11 | * The data is pushed sample-by-sample or chunk-by-chunk into the outlet, and can consist of single- 12 | * or multichannel data, regular or irregular sampling rate, with uniform value types (integers, 13 | * floats, doubles, strings). 14 | * 15 | * Streams can have arbitrary XML meta-data (akin to a file header). 16 | * By creating an outlet the stream is made visible to a collection of computers (defined by the 17 | * network settings/layout) where one can subscribe to it by creating an inlet. 18 | * @{ 19 | */ 20 | 21 | /** 22 | * Establish a new stream outlet. This makes the stream discoverable. 23 | * @param info The stream information to use for creating this stream. 24 | * Stays constant over the lifetime of the outlet. 25 | * @note the outlet makes a copy of the streaminfo object upon construction (so the old info should 26 | * still be destroyed.) 27 | * @param chunk_size Optionally the desired chunk granularity (in samples) for transmission. 28 | * If specified as 0, each push operation yields one chunk. 29 | * Stream recipients can have this setting bypassed. 30 | * @param max_buffered Optionally the maximum amount of data to buffer (in seconds if there is a 31 | * nominal sampling rate, otherwise x100 in samples). A good default is 360, which corresponds to 6 32 | * minutes of data. Note that, for high-bandwidth data you will almost certainly want to use a lower 33 | * value here to avoid running out of RAM. 34 | * @return A newly created lsl_outlet handle or NULL in the event that an error occurred. 35 | */ 36 | extern LIBLSL_C_API lsl_outlet lsl_create_outlet(lsl_streaminfo info, int32_t chunk_size, int32_t max_buffered); 37 | /** @copydoc lsl_create_outlet() 38 | * @param flags An integer that is the result of bitwise OR'ing one or more options from 39 | * #lsl_transport_options_t together (e.g., #transp_bufsize_samples|#transp_bufsize_thousandths) 40 | */ 41 | extern LIBLSL_C_API lsl_outlet lsl_create_outlet_ex( 42 | lsl_streaminfo info, int32_t chunk_size, int32_t max_buffered, lsl_transport_options_t flags); 43 | 44 | /** 45 | * Destroy an outlet. 46 | * The outlet will no longer be discoverable after destruction and all connected inlets will stop 47 | * delivering data. 48 | */ 49 | extern LIBLSL_C_API void lsl_destroy_outlet(lsl_outlet out); 50 | 51 | /** Push a pointer to some values as a sample into the outlet. 52 | * Handles type checking & conversion. 53 | * @param out The lsl_outlet object through which to push the data. 54 | * @param data A pointer to values to push. The number of values pointed to must be no less than the 55 | * number of channels in the sample. 56 | * #lsl_local_clock(); if omitted, the current time is used. 57 | * @return Error code of the operation or lsl_no_error if successful (usually attributed to the 58 | * wrong data type). 59 | * @{ 60 | */ 61 | extern LIBLSL_C_API int32_t lsl_push_sample_f(lsl_outlet out, const float *data); 62 | extern LIBLSL_C_API int32_t lsl_push_sample_d(lsl_outlet out, const double *data); 63 | extern LIBLSL_C_API int32_t lsl_push_sample_l(lsl_outlet out, const int64_t *data); 64 | extern LIBLSL_C_API int32_t lsl_push_sample_i(lsl_outlet out, const int32_t *data); 65 | extern LIBLSL_C_API int32_t lsl_push_sample_s(lsl_outlet out, const int16_t *data); 66 | extern LIBLSL_C_API int32_t lsl_push_sample_c(lsl_outlet out, const char *data); 67 | extern LIBLSL_C_API int32_t lsl_push_sample_str(lsl_outlet out, const char **data); 68 | extern LIBLSL_C_API int32_t lsl_push_sample_v(lsl_outlet out, const void *data); 69 | /// @} 70 | /** @copydoc lsl_push_sample_f 71 | * @param timestamp Optionally the capture time of the sample, in agreement with 72 | * @{ 73 | */ 74 | extern LIBLSL_C_API int32_t lsl_push_sample_ft(lsl_outlet out, const float *data, double timestamp); 75 | extern LIBLSL_C_API int32_t lsl_push_sample_dt(lsl_outlet out, const double *data, double timestamp); 76 | extern LIBLSL_C_API int32_t lsl_push_sample_lt(lsl_outlet out, const int64_t *data, double timestamp); 77 | extern LIBLSL_C_API int32_t lsl_push_sample_it(lsl_outlet out, const int32_t *data, double timestamp); 78 | extern LIBLSL_C_API int32_t lsl_push_sample_st(lsl_outlet out, const int16_t *data, double timestamp); 79 | extern LIBLSL_C_API int32_t lsl_push_sample_ct(lsl_outlet out, const char *data, double timestamp); 80 | extern LIBLSL_C_API int32_t lsl_push_sample_strt(lsl_outlet out, const char **data, double timestamp); 81 | extern LIBLSL_C_API int32_t lsl_push_sample_vt(lsl_outlet out, const void *data, double timestamp); 82 | /// @} 83 | /** @copydoc lsl_push_sample_ft 84 | * @param pushthrough Whether to push the sample through to the receivers instead of buffering it 85 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 86 | * precedence over the pushthrough flag. 87 | * @{ 88 | */ 89 | extern LIBLSL_C_API int32_t lsl_push_sample_ftp(lsl_outlet out, const float *data, double timestamp, int32_t pushthrough); 90 | extern LIBLSL_C_API int32_t lsl_push_sample_dtp(lsl_outlet out, const double *data, double timestamp, int32_t pushthrough); 91 | extern LIBLSL_C_API int32_t lsl_push_sample_ltp(lsl_outlet out, const int64_t *data, double timestamp, int32_t pushthrough); 92 | extern LIBLSL_C_API int32_t lsl_push_sample_itp(lsl_outlet out, const int32_t *data, double timestamp, int32_t pushthrough); 93 | extern LIBLSL_C_API int32_t lsl_push_sample_stp(lsl_outlet out, const int16_t *data, double timestamp, int32_t pushthrough); 94 | extern LIBLSL_C_API int32_t lsl_push_sample_ctp(lsl_outlet out, const char *data, double timestamp, int32_t pushthrough); 95 | extern LIBLSL_C_API int32_t lsl_push_sample_strtp(lsl_outlet out, const char **data, double timestamp, int32_t pushthrough); 96 | extern LIBLSL_C_API int32_t lsl_push_sample_vtp(lsl_outlet out, const void *data, double timestamp, int32_t pushthrough); 97 | ///@} 98 | 99 | /** @copybrief lsl_push_sample_ftp 100 | * @see lsl_push_sample_ftp 101 | * @param out The lsl_outlet object through which to push the data. 102 | * @param data A pointer to values to push. The number of values pointed to must be no less than the 103 | * number of channels in the sample. 104 | * @param lengths A pointer the number of elements to push for each channel (string lengths). 105 | */ 106 | extern LIBLSL_C_API int32_t lsl_push_sample_buf(lsl_outlet out, const char **data, const uint32_t *lengths); 107 | /** @copydoc lsl_push_sample_buf 108 | * @param timestamp @see lsl_push_sample_ftp */ 109 | extern LIBLSL_C_API int32_t lsl_push_sample_buft(lsl_outlet out, const char **data, const uint32_t *lengths, double timestamp); 110 | /** @copydoc lsl_push_sample_buft 111 | * @param pushthrough @see lsl_push_sample_ftp */ 112 | extern LIBLSL_C_API int32_t lsl_push_sample_buftp(lsl_outlet out, const char **data, const uint32_t *lengths, double timestamp, int32_t pushthrough); 113 | 114 | /** Push a chunk of multiplexed samples into the outlet. One timestamp per sample is provided. 115 | * 116 | * @attention Note that the provided buffer size is measured in channel values (e.g. floats) rather 117 | * than in samples. 118 | * 119 | * Handles type checking & conversion. 120 | * @param out The lsl_outlet object through which to push the data. 121 | * @param data A buffer of channel values holding the data for zero or more successive samples to 122 | * send. 123 | * @param data_elements The number of data values (of type T) in the data buffer. Must be a multiple 124 | * of the channel count. 125 | * @return Error code of the operation (usually attributed to the wrong data type). 126 | * @{ 127 | */ 128 | extern LIBLSL_C_API int32_t lsl_push_chunk_f(lsl_outlet out, const float *data, unsigned long data_elements); 129 | extern LIBLSL_C_API int32_t lsl_push_chunk_d(lsl_outlet out, const double *data, unsigned long data_elements); 130 | extern LIBLSL_C_API int32_t lsl_push_chunk_l(lsl_outlet out, const int64_t *data, unsigned long data_elements); 131 | extern LIBLSL_C_API int32_t lsl_push_chunk_i(lsl_outlet out, const int32_t *data, unsigned long data_elements); 132 | extern LIBLSL_C_API int32_t lsl_push_chunk_s(lsl_outlet out, const int16_t *data, unsigned long data_elements); 133 | extern LIBLSL_C_API int32_t lsl_push_chunk_c(lsl_outlet out, const char *data, unsigned long data_elements); 134 | extern LIBLSL_C_API int32_t lsl_push_chunk_str(lsl_outlet out, const char **data, unsigned long data_elements); 135 | /// @} 136 | 137 | /** @copydoc lsl_push_chunk_f 138 | * @param timestamp Optionally the capture time of the most recent sample, in agreement with 139 | * lsl_local_clock(); if omitted, the current time is used. 140 | * The time stamps of other samples are automatically derived based on the sampling rate of the 141 | * stream. 142 | * @{ 143 | */ 144 | extern LIBLSL_C_API int32_t lsl_push_chunk_ft(lsl_outlet out, const float *data, unsigned long data_elements, double timestamp); 145 | extern LIBLSL_C_API int32_t lsl_push_chunk_dt(lsl_outlet out, const double *data, unsigned long data_elements, double timestamp); 146 | extern LIBLSL_C_API int32_t lsl_push_chunk_lt(lsl_outlet out, const int64_t *data, unsigned long data_elements, double timestamp); 147 | extern LIBLSL_C_API int32_t lsl_push_chunk_it(lsl_outlet out, const int32_t *data, unsigned long data_elements, double timestamp); 148 | extern LIBLSL_C_API int32_t lsl_push_chunk_st(lsl_outlet out, const int16_t *data, unsigned long data_elements, double timestamp); 149 | extern LIBLSL_C_API int32_t lsl_push_chunk_ct(lsl_outlet out, const char *data, unsigned long data_elements, double timestamp); 150 | extern LIBLSL_C_API int32_t lsl_push_chunk_strt(lsl_outlet out, const char **data, unsigned long data_elements, double timestamp); 151 | /// @} 152 | 153 | /** @copydoc lsl_push_chunk_ft 154 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 155 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 156 | * precedence over the pushthrough flag. 157 | * @{ 158 | */ 159 | extern LIBLSL_C_API int32_t lsl_push_chunk_ftp(lsl_outlet out, const float *data, unsigned long data_elements, double timestamp, int32_t pushthrough); 160 | extern LIBLSL_C_API int32_t lsl_push_chunk_dtp(lsl_outlet out, const double *data, unsigned long data_elements, double timestamp, int32_t pushthrough); 161 | extern LIBLSL_C_API int32_t lsl_push_chunk_ltp(lsl_outlet out, const int64_t *data, unsigned long data_elements, double timestamp, int32_t pushthrough); 162 | extern LIBLSL_C_API int32_t lsl_push_chunk_itp(lsl_outlet out, const int32_t *data, unsigned long data_elements, double timestamp, int32_t pushthrough); 163 | extern LIBLSL_C_API int32_t lsl_push_chunk_stp(lsl_outlet out, const int16_t *data, unsigned long data_elements, double timestamp, int32_t pushthrough); 164 | extern LIBLSL_C_API int32_t lsl_push_chunk_ctp(lsl_outlet out, const char *data, unsigned long data_elements, double timestamp, int32_t pushthrough); 165 | extern LIBLSL_C_API int32_t lsl_push_chunk_strtp(lsl_outlet out, const char **data, unsigned long data_elements, double timestamp, int32_t pushthrough); 166 | /// @} 167 | /** @copydoc lsl_push_chunk_f 168 | * @param timestamps Buffer holding one time stamp for each sample in the data buffer. 169 | * @{ 170 | */ 171 | extern LIBLSL_C_API int32_t lsl_push_chunk_ftn(lsl_outlet out, const float *data, unsigned long data_elements, const double *timestamps); 172 | extern LIBLSL_C_API int32_t lsl_push_chunk_dtn(lsl_outlet out, const double *data, unsigned long data_elements, const double *timestamps); 173 | extern LIBLSL_C_API int32_t lsl_push_chunk_ltn(lsl_outlet out, const int64_t *data, unsigned long data_elements, const double *timestamps); 174 | extern LIBLSL_C_API int32_t lsl_push_chunk_itn(lsl_outlet out, const int32_t *data, unsigned long data_elements, const double *timestamps); 175 | extern LIBLSL_C_API int32_t lsl_push_chunk_stn(lsl_outlet out, const int16_t *data, unsigned long data_elements, const double *timestamps); 176 | extern LIBLSL_C_API int32_t lsl_push_chunk_ctn(lsl_outlet out, const char *data, unsigned long data_elements, const double *timestamps); 177 | extern LIBLSL_C_API int32_t lsl_push_chunk_strtn(lsl_outlet out, const char **data, unsigned long data_elements, const double *timestamps); 178 | /// @} 179 | 180 | /** @copydoc lsl_push_chunk_ftn 181 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 182 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 183 | * precedence over the pushthrough flag. 184 | * @{ 185 | */ 186 | extern LIBLSL_C_API int32_t lsl_push_chunk_ftnp(lsl_outlet out, const float *data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 187 | extern LIBLSL_C_API int32_t lsl_push_chunk_dtnp(lsl_outlet out, const double *data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 188 | extern LIBLSL_C_API int32_t lsl_push_chunk_ltnp(lsl_outlet out, const int64_t *data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 189 | extern LIBLSL_C_API int32_t lsl_push_chunk_itnp(lsl_outlet out, const int32_t *data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 190 | extern LIBLSL_C_API int32_t lsl_push_chunk_stnp(lsl_outlet out, const int16_t *data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 191 | extern LIBLSL_C_API int32_t lsl_push_chunk_ctnp(lsl_outlet out, const char *data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 192 | extern LIBLSL_C_API int32_t lsl_push_chunk_strtnp(lsl_outlet out, const char **data, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 193 | ///@} 194 | 195 | /** @copybrief lsl_push_chunk_ftp 196 | * @sa lsl_push_chunk_ftp 197 | * @param out The lsl_outlet object through which to push the data. 198 | * @param data An array of channel values holding the data to push. 199 | * @param lengths Pointer the number of elements to push for each value (string lengths) so that 200 | * `size(data[i])==lengths[i]`. 201 | * @param data_elements The number of data values in the data buffer. 202 | * Must be a multiple of the channel count. 203 | */ 204 | extern LIBLSL_C_API int32_t lsl_push_chunk_buf(lsl_outlet out, const char **data, const uint32_t *lengths, unsigned long data_elements); 205 | 206 | /** @copydoc lsl_push_chunk_buf @sa lsl_push_chunk_ftp @sa lsl_push_chunk_buf 207 | * @param timestamp Optionally the capture time of the most recent sample, in agreement with 208 | * lsl_local_clock(); if omitted, the current time is used. 209 | * The time stamps of other samples are automatically derived based on the sampling rate of the 210 | * stream. */ 211 | extern LIBLSL_C_API int32_t lsl_push_chunk_buft(lsl_outlet out, const char **data, const uint32_t *lengths, unsigned long data_elements, double timestamp); 212 | 213 | /** @copydoc lsl_push_chunk_buft @sa lsl_push_chunk_ftp @sa lsl_push_chunk_buf 214 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 215 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 216 | * precedence over the pushthrough flag. */ 217 | extern LIBLSL_C_API int32_t lsl_push_chunk_buftp(lsl_outlet out, const char **data, const uint32_t *lengths, unsigned long data_elements, double timestamp, int32_t pushthrough); 218 | 219 | /** @copydoc lsl_push_chunk_buf @sa lsl_push_chunk_ftp @sa lsl_push_chunk_buf 220 | * @param timestamps Buffer holding one time stamp for each sample in the data buffer. */ 221 | extern LIBLSL_C_API int32_t lsl_push_chunk_buftn(lsl_outlet out, const char **data, const uint32_t *lengths, unsigned long data_elements, const double *timestamps); 222 | 223 | /** @copydoc lsl_push_chunk_buftn @sa lsl_push_chunk_ftp @sa lsl_push_chunk_buf 224 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 225 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 226 | * precedence over the pushthrough flag. */ 227 | extern LIBLSL_C_API int32_t lsl_push_chunk_buftnp(lsl_outlet out, const char **data, const uint32_t *lengths, unsigned long data_elements, const double *timestamps, int32_t pushthrough); 228 | 229 | /** 230 | * Check whether consumers are currently registered. 231 | * While it does not hurt, there is technically no reason to push samples if there is no consumer. 232 | */ 233 | extern LIBLSL_C_API int32_t lsl_have_consumers(lsl_outlet out); 234 | 235 | /** 236 | * Wait until some consumer shows up (without wasting resources). 237 | * @return True if the wait was successful, false if the timeout expired. 238 | */ 239 | extern LIBLSL_C_API int32_t lsl_wait_for_consumers(lsl_outlet out, double timeout); 240 | 241 | /** 242 | * Retrieve a handle to the stream info provided by this outlet. 243 | * This is what was used to create the stream (and also has the Additional Network Information 244 | * fields assigned). 245 | * @return A copy of the streaminfo of the outlet or NULL in the event that an error occurred. 246 | * @note It is the user's responsibility to destroy it when it is no longer needed. 247 | * @sa lsl_destroy_string() 248 | */ 249 | extern LIBLSL_C_API lsl_streaminfo lsl_get_info(lsl_outlet out); 250 | 251 | ///@} 252 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/resolver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common.h" 3 | #include "types.h" 4 | 5 | /// @file resolver.h Stream resolution functions 6 | 7 | /** @defgroup continuous_resolver The lsl_continuous_resolver 8 | * @ingroup resolve 9 | * 10 | * Streams can be resolved at a single timepoint once (@ref resolve) or continuously in the 11 | * background. 12 | * @{ 13 | */ 14 | 15 | /** 16 | * Construct a new #lsl_continuous_resolver that resolves all streams on the network. 17 | * 18 | * This is analogous to the functionality offered by the free function lsl_resolve_streams(). 19 | * @param forget_after When a stream is no longer visible on the network (e.g. because it was shut 20 | * down), this is the time in seconds after which it is no longer reported by the resolver. 21 | * 22 | * The recommended default value is 5.0. 23 | */ 24 | extern LIBLSL_C_API lsl_continuous_resolver lsl_create_continuous_resolver(double forget_after); 25 | 26 | /** 27 | * Construct a new lsl_continuous_resolver that resolves all streams with a specific value for a given 28 | * property. 29 | * 30 | * This is analogous to the functionality provided by the free function lsl_resolve_byprop() 31 | * @param prop The #lsl_streaminfo property that should have a specific value (e.g., "name", "type", 32 | * "source_id", or "desc/manufaturer"). 33 | * @param value The string value that the property should have (e.g., "EEG" as the type property). 34 | * @param forget_after When a stream is no longer visible on the network (e.g., because it was shut 35 | * down), this is the time in seconds after which it is no longer reported by the resolver. 36 | * The recommended default value is 5.0. 37 | */ 38 | extern LIBLSL_C_API lsl_continuous_resolver lsl_create_continuous_resolver_byprop(const char *prop, const char *value, double forget_after); 39 | 40 | /** 41 | * Construct a new lsl_continuous_resolver that resolves all streams that match a given XPath 1.0 42 | * predicate. 43 | * 44 | * This is analogous to the functionality provided by the free function lsl_resolve_bypred() 45 | * @param pred The predicate string, e.g. 46 | * `"name='BioSemi'" or "type='EEG' and starts-with(name,'BioSemi') and count(info/desc/channel)=32"` 47 | * @param forget_after When a stream is no longer visible on the network (e.g., because it was shut 48 | * down), this is the time in seconds after which it is no longer reported by the resolver. 49 | * The recommended default value is 5.0. 50 | */ 51 | extern LIBLSL_C_API lsl_continuous_resolver lsl_create_continuous_resolver_bypred(const char *pred, double forget_after); 52 | 53 | /** 54 | * Obtain the set of currently present streams on the network (i.e. resolve result). 55 | * 56 | * @param res A continuous resolver (previously created with one of the 57 | * lsl_create_continuous_resolver() functions). 58 | * @param buffer A user-allocated buffer to hold the current resolve results.
59 | * @attention It is the user's responsibility to either destroy the resulting streaminfo objects or 60 | * to pass them back to the LSL during during creation of an inlet. 61 | * @attention The stream_infos returned by the resolver are only short versions that do not include 62 | * the lsl_get_desc() field (which can be arbitrarily big). 63 | * 64 | * To obtain the full stream information you need to call lsl_get_info() on the inlet after you have 65 | * created one. 66 | * @param buffer_elements The user-provided buffer length. 67 | * @return The number of results written into the buffer (never more than the provided # of slots) 68 | * or a negative number if an error has occurred (values corresponding to #lsl_error_code_t). 69 | */ 70 | extern LIBLSL_C_API int32_t lsl_resolver_results(lsl_continuous_resolver res, lsl_streaminfo *buffer, uint32_t buffer_elements); 71 | 72 | /// Destructor for the continuous resolver. 73 | extern LIBLSL_C_API void lsl_destroy_continuous_resolver(lsl_continuous_resolver res); 74 | 75 | /// @} 76 | 77 | /** @defgroup resolve Resolving streams on the network 78 | * @{*/ 79 | 80 | /** 81 | * Resolve all streams on the network. 82 | * 83 | * This function returns all currently available streams from any outlet on the network. 84 | * The network is usually the subnet specified at the local router, but may also include a multicast 85 | * group of machines (given that the network supports it), or a list of hostnames.
86 | * These details may optionally be customized by the experimenter in a configuration file 87 | * (see page Network Connectivity in the LSL wiki). 88 | * This is the default mechanism used by the browsing programs and the recording program. 89 | * @param[out] buffer A user-allocated buffer to hold the resolve results. 90 | * @attention It is the user's responsibility to either destroy the resulting streaminfo objects or 91 | * to pass them back to the LSL during during creation of an inlet. 92 | * 93 | * @attention The stream_info's returned by the resolver are only short versions that do not include 94 | * the lsl_get_desc() field (which can be arbitrarily big). 95 | * To obtain the full stream information you need to call lsl_get_info() on the inlet after you have 96 | * created one. 97 | * @param buffer_elements The user-provided buffer length. 98 | * @param wait_time The waiting time for the operation, in seconds, to search for streams. 99 | * The recommended wait time is 1 second (or 2 for a busy and large recording operation). 100 | * @warning If this is too short (<0.5s) only a subset (or none) of the outlets that are present on 101 | * the network may be returned. 102 | * @return The number of results written into the buffer (never more than the provided # of slots) 103 | * or a negative number if an error has occurred (values corresponding to lsl_error_code_t). 104 | */ 105 | extern LIBLSL_C_API int32_t lsl_resolve_all(lsl_streaminfo *buffer, uint32_t buffer_elements, double wait_time); 106 | 107 | /** 108 | * Resolve all streams with a given value for a property. 109 | * 110 | * If the goal is to resolve a specific stream, this method is preferred over resolving all streams 111 | * and then selecting the desired one. 112 | * @param[out] buffer A user-allocated buffer to hold the resolve results. 113 | * @attention It is the user's responsibility to either destroy the resulting streaminfo objects or 114 | * to pass them back to the LSL during during creation of an inlet. 115 | * 116 | * @attention The stream_info's returned by the resolver are only short versions that do not include 117 | * the lsl_get_desc() field (which can be arbitrarily big). To obtain the full stream information 118 | * you need to call lsl_get_info() on the inlet after you have created one. 119 | * @param buffer_elements The user-provided buffer length. 120 | * @param prop The streaminfo property that should have a specific value (`"name"`, `"type"`, 121 | * `"source_id"`, or, e.g., `"desc/manufaturer"` if present). 122 | * @param value The string value that the property should have (e.g., "EEG" as the type). 123 | * @param minimum Return at least this number of streams. 124 | * @param timeout Optionally a timeout of the operation, in seconds (default: no timeout). 125 | * If the timeout expires, less than the desired number of streams (possibly none) will be returned. 126 | * @return The number of results written into the buffer (never more than the provided # of slots) 127 | * or a negative number if an error has occurred (values corresponding to #lsl_error_code_t). 128 | */ 129 | extern LIBLSL_C_API int32_t lsl_resolve_byprop(lsl_streaminfo *buffer, uint32_t buffer_elements, const char *prop, const char *value, int32_t minimum, double timeout); 130 | 131 | /** 132 | * Resolve all streams that match a given predicate. 133 | * 134 | * Advanced query that allows to impose more conditions on the retrieved streams; 135 | * the given string is an [XPath 1.0 predicate](http://en.wikipedia.org/w/index.php?title=XPath_1.0) 136 | * for the `` node (omitting the surrounding []'s) 137 | * @param[out] buffer A user-allocated buffer to hold the resolve results. 138 | * @attention It is the user's responsibility to either destroy the resulting streaminfo objects or 139 | * to pass them back to the LSL during during creation of an inlet. 140 | * 141 | * @attention The stream_info's returned by the resolver are only short versions that do not include 142 | * the lsl_get_desc() field (which can be arbitrarily big). To obtain the full stream information 143 | * you need to call lsl_get_info() on the inlet after you have created one. 144 | * @param buffer_elements The user-provided buffer length. 145 | * @param pred The predicate string, e.g. 146 | * `name='BioSemi'` or `type='EEG' and starts-with(name,'BioSemi') and count(info/desc/channel)=32` 147 | * @param minimum Return at least this number of streams. 148 | * @param timeout Optionally a timeout of the operation, in seconds (default: no timeout). 149 | * If the timeout expires, less than the desired number of streams (possibly none) 150 | * will be returned. 151 | * @return The number of results written into the buffer (never more than the provided # of slots) 152 | * or a negative number if an error has occurred (values corresponding to lsl_error_code_t). 153 | */ 154 | extern LIBLSL_C_API int32_t lsl_resolve_bypred(lsl_streaminfo *buffer, uint32_t buffer_elements, const char *pred, int32_t minimum, double timeout); 155 | 156 | /// @} 157 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/streaminfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common.h" 3 | #include "types.h" 4 | 5 | /// @file streaminfo.h Stream info functions 6 | 7 | /** @defgroup streaminfo The lsl_streaminfo object 8 | * 9 | * The #lsl_streaminfo object keeps a stream's meta data and connection settings. 10 | * @{ 11 | */ 12 | 13 | /** 14 | * Construct a new streaminfo object. 15 | * 16 | * Core stream information is specified here. Any remaining meta-data can be added later. 17 | * @param name Name of the stream.
18 | * Describes the device (or product series) that this stream makes available 19 | * (for use by programs, experimenters or data analysts). Cannot be empty. 20 | * @param type Content type of the stream. Please see https://github.com/sccn/xdf/wiki/Meta-Data (or 21 | * web search for: XDF meta-data) for pre-defined content-type names, but you can also make up your 22 | * own. The content type is the preferred way to find streams (as opposed to searching by name). 23 | * @param channel_count Number of channels per sample. 24 | * This stays constant for the lifetime of the stream. 25 | * @param nominal_srate The sampling rate (in Hz) as advertised by the 26 | * datasource, if regular (otherwise set to #LSL_IRREGULAR_RATE). 27 | * @param channel_format Format/type of each channel.
28 | * If your channels have different formats, consider supplying multiple streams 29 | * or use the largest type that can hold them all (such as #cft_double64). 30 | * 31 | * A good default is #cft_float32. 32 | * @param source_id Unique identifier of the source or device, if available (e.g. a serial number). 33 | * Allows recipients to recover from failure even after the serving app or device crashes. 34 | * May in some cases also be constructed from device settings. 35 | * @return A newly created streaminfo handle or NULL in the event that an error occurred. 36 | */ 37 | extern LIBLSL_C_API lsl_streaminfo lsl_create_streaminfo(const char *name, const char *type, int32_t channel_count, double nominal_srate, lsl_channel_format_t channel_format, const char *source_id); 38 | 39 | /// Destroy a previously created streaminfo object. 40 | extern LIBLSL_C_API void lsl_destroy_streaminfo(lsl_streaminfo info); 41 | 42 | /// Copy an existing streaminfo object (rarely used). 43 | extern LIBLSL_C_API lsl_streaminfo lsl_copy_streaminfo(lsl_streaminfo info); 44 | 45 | /** 46 | * Name of the stream. 47 | * 48 | * This is a human-readable name. 49 | * For streams offered by device modules, it refers to the type of device or product series that is 50 | * generating the data of the stream. If the source is an application, the name may be a more 51 | * generic or specific identifier. Multiple streams with the same name can coexist, though 52 | * potentially at the cost of ambiguity (for the recording app or experimenter). 53 | * @return An immutable library-owned pointer to the string value. @sa lsl_destroy_string() 54 | */ 55 | extern LIBLSL_C_API const char *lsl_get_name(lsl_streaminfo info); 56 | 57 | /** 58 | * Content type of the stream. 59 | * 60 | * The content type is a short string such as "EEG", "Gaze" which describes the content carried by 61 | * the channel (if known). If a stream contains mixed content this value need not be assigned but 62 | * may instead be stored in the description of channel types. To be useful to applications and 63 | * automated processing systems using the recommended content types is preferred. Content types 64 | * usually follow those pre-defined in the [wiki](https://github.com/sccn/xdf/wiki/Meta-Data) (or 65 | * web search for: XDF meta-data). 66 | * @return An immutable library-owned pointer to the string value. @sa lsl_destroy_string() 67 | */ 68 | extern LIBLSL_C_API const char *lsl_get_type(lsl_streaminfo info); 69 | 70 | /** 71 | * Number of channels of the stream. 72 | * A stream has at least one channels; the channel count stays constant for all samples. 73 | */ 74 | extern LIBLSL_C_API int32_t lsl_get_channel_count(lsl_streaminfo info); 75 | 76 | /** 77 | * Sampling rate of the stream, according to the source (in Hz). 78 | * 79 | * If a stream is irregularly sampled, this should be set to #LSL_IRREGULAR_RATE. 80 | * 81 | * Note that no data will be lost even if this sampling rate is incorrect or if a device has 82 | * temporary hiccups, since all samples will be recorded anyway (except for those dropped by the 83 | * device itself). However, when the recording is imported into an application, a good importer may 84 | * correct such errors more accurately if the advertised sampling rate was close to the specs of the 85 | * device. 86 | */ 87 | extern LIBLSL_C_API double lsl_get_nominal_srate(lsl_streaminfo info); 88 | 89 | /** 90 | * Channel format of the stream. 91 | * All channels in a stream have the same format. 92 | * However, a device might offer multiple time-synched streams each with its own format. 93 | */ 94 | extern LIBLSL_C_API lsl_channel_format_t lsl_get_channel_format(lsl_streaminfo info); 95 | 96 | /** 97 | * Unique identifier of the stream's source, if available. 98 | * 99 | * The unique source (or device) identifier is an optional piece of information that, if available, 100 | * allows that endpoints (such as the recording program) can re-acquire a stream automatically once 101 | * it is back online. 102 | * @return An immutable library-owned pointer to the string value. @sa lsl_destroy_string() 103 | */ 104 | extern LIBLSL_C_API const char *lsl_get_source_id(lsl_streaminfo info); 105 | 106 | /** 107 | * Protocol version used to deliver the stream. 108 | */ 109 | extern LIBLSL_C_API int32_t lsl_get_version(lsl_streaminfo info); 110 | 111 | /** 112 | * Creation time stamp of the stream. 113 | * 114 | * This is the time stamp when the stream was first created 115 | * (as determined via local_clock() on the providing machine). 116 | */ 117 | extern LIBLSL_C_API double lsl_get_created_at(lsl_streaminfo info); 118 | 119 | /** 120 | * Unique ID of the stream outlet (once assigned). 121 | * 122 | * This is a unique identifier of the stream outlet, and is guaranteed to be different 123 | * across multiple instantiations of the same outlet (e.g., after a re-start). 124 | * @return An immutable library-owned pointer to the string value. @sa lsl_destroy_string() 125 | */ 126 | extern LIBLSL_C_API const char *lsl_get_uid(lsl_streaminfo info); 127 | 128 | /** 129 | * Session ID for the given stream. 130 | * 131 | * The session id is an optional human-assigned identifier of the recording session. 132 | * While it is rarely used, it can be used to prevent concurrent recording activitites 133 | * on the same sub-network (e.g., in multiple experiment areas) from seeing each other's streams 134 | * (assigned via a configuration file by the experimenter, see Network Connectivity on the LSL 135 | * wiki). 136 | * @return An immutable library-owned pointer to the string value. @sa lsl_destroy_string() 137 | */ 138 | extern LIBLSL_C_API const char *lsl_get_session_id(lsl_streaminfo info); 139 | 140 | /// Hostname of the providing machine (once bound to an outlet). Modification is not permitted. 141 | extern LIBLSL_C_API const char *lsl_get_hostname(lsl_streaminfo info); 142 | 143 | /** 144 | * Extended description of the stream. 145 | * 146 | * It is highly recommended that at least the channel labels are described here. 147 | * See code examples on the LSL wiki. Other information, such as amplifier settings, 148 | * measurement units if deviating from defaults, setup information, subject information, etc., 149 | * can be specified here, as well. Meta-data recommendations follow the XDF file format project 150 | * (github.com/sccn/xdf/wiki/Meta-Data or web search for: XDF meta-data). 151 | * 152 | * @attention if you use a stream content type for which meta-data recommendations exist, please 153 | * try to lay out your meta-data in agreement with these recommendations for compatibility with other applications. 154 | */ 155 | extern LIBLSL_C_API lsl_xml_ptr lsl_get_desc(lsl_streaminfo info); 156 | 157 | /** 158 | * Retrieve the entire streaminfo in XML format. 159 | * 160 | * This yields an XML document (in string form) whose top-level element is ``. The info 161 | * element contains one element for each field of the streaminfo class, including: 162 | * 163 | * - the core elements ``, ``, ``, 164 | * ``, `` 165 | * - the misc elements ``, ``, ``, ``, 166 | * ``, ``, ``, ``, ``, 167 | * `` 168 | * - the extended description element `` with user-defined sub-elements. 169 | * @return A pointer to a copy of the XML text or NULL in the event that an error occurred. 170 | * @note It is the user's responsibility to deallocate this string when it is no longer needed. 171 | */ 172 | extern LIBLSL_C_API char *lsl_get_xml(lsl_streaminfo info); 173 | 174 | /// Number of bytes occupied by a channel (0 for string-typed channels). 175 | extern LIBLSL_C_API int32_t lsl_get_channel_bytes(lsl_streaminfo info); 176 | 177 | /// Number of bytes occupied by a sample (0 for string-typed channels). 178 | extern LIBLSL_C_API int32_t lsl_get_sample_bytes(lsl_streaminfo info); 179 | 180 | /** 181 | * Tries to match the stream info XML element @p info against an 182 | * XPath query. 183 | * 184 | * Example query strings: 185 | * @code 186 | * channel_count>5 and type='EEG' 187 | * type='TestStream' or contains(name,'Brain') 188 | * name='ExampleStream' 189 | * @endcode 190 | */ 191 | extern LIBLSL_C_API int32_t lsl_stream_info_matches_query(lsl_streaminfo info, const char *query); 192 | 193 | /// Create a streaminfo object from an XML representation 194 | extern LIBLSL_C_API lsl_streaminfo lsl_streaminfo_from_xml(const char *xml); 195 | 196 | /// @} 197 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/types.h: -------------------------------------------------------------------------------- 1 | #ifndef LSL_TYPES 2 | #define LSL_TYPES 3 | 4 | /** 5 | * @class lsl_streaminfo 6 | * Handle to a stream info object. 7 | * 8 | * Stores the declaration of a data stream. 9 | * Represents the following information: 10 | * 11 | * - stream data format (number of channels, channel format) 12 | * - core information (stream name, content type, sampling rate) 13 | * - optional meta-data about the stream content (channel labels, measurement units, etc.) 14 | * 15 | * Whenever a program wants to provide a new stream on the lab network it will typically first 16 | * create an lsl_streaminfo to describe its properties and then construct an #lsl_outlet with it to 17 | * create the stream on the network. Other parties who discover/resolve the outlet on the network 18 | * can query the stream info; it is also written to disk when recording the stream (playing a 19 | * similar role as a file header). 20 | */ 21 | typedef struct lsl_streaminfo_struct_ *lsl_streaminfo; 22 | 23 | /** 24 | * @class lsl_outlet 25 | * A stream outlet handle. 26 | * Outlets are used to make streaming data (and the meta-data) available on the lab network. 27 | */ 28 | typedef struct lsl_outlet_struct_ *lsl_outlet; 29 | 30 | /** 31 | * @class lsl_inlet 32 | * A stream inlet handle. 33 | * Inlets are used to receive streaming data (and meta-data) from the lab network. 34 | */ 35 | typedef struct lsl_inlet_struct_ *lsl_inlet; 36 | 37 | /** 38 | * @class lsl_xml_ptr 39 | * A lightweight XML element tree handle; models the description of a streaminfo object. 40 | * XML elements behave like advanced pointers into memory that is owned by some respective 41 | * streaminfo. 42 | * Has a name and can have multiple named children or have text content as value; 43 | * attributes are omitted. 44 | * @note The interface is modeled after a subset of pugixml's node type and is compatible with it. 45 | * Type-casts between pugi::xml_node_struct* and #lsl_xml_ptr are permitted (in both directions) 46 | * since the types are binary compatible. 47 | * @sa [pugixml documentation](https://pugixml.org/docs/manual.html#access). 48 | */ 49 | typedef struct lsl_xml_ptr_struct_ *lsl_xml_ptr; 50 | 51 | /** 52 | * @class lsl_continuous_resolver 53 | * 54 | * Handle to a convenience object that resolves streams continuously in the background throughout 55 | * its lifetime and which can be queried at any time for the set of streams that are currently 56 | * visible on the network. 57 | */ 58 | typedef struct lsl_continuous_resolver_ *lsl_continuous_resolver; 59 | 60 | #endif // LSL_TYPES 61 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl/xml.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "common.h" 3 | #include "types.h" 4 | 5 | /// @file inlet.h XML functions 6 | 7 | /** @defgroup xml_ptr The lsl_xml_ptr object 8 | * @{ 9 | */ 10 | 11 | // XML Tree Navigation 12 | 13 | /** Get the first child of the element. */ 14 | extern LIBLSL_C_API lsl_xml_ptr lsl_first_child(lsl_xml_ptr e); 15 | 16 | /** Get the last child of the element. */ 17 | extern LIBLSL_C_API lsl_xml_ptr lsl_last_child(lsl_xml_ptr e); 18 | 19 | /** Get the next sibling in the children list of the parent node. */ 20 | extern LIBLSL_C_API lsl_xml_ptr lsl_next_sibling(lsl_xml_ptr e); 21 | 22 | /** Get the previous sibling in the children list of the parent node. */ 23 | extern LIBLSL_C_API lsl_xml_ptr lsl_previous_sibling(lsl_xml_ptr e); 24 | 25 | /** Get the parent node. */ 26 | extern LIBLSL_C_API lsl_xml_ptr lsl_parent(lsl_xml_ptr e); 27 | 28 | 29 | // XML Tree Navigation by Name 30 | 31 | /** Get a child with a specified name. */ 32 | extern LIBLSL_C_API lsl_xml_ptr lsl_child(lsl_xml_ptr e, const char *name); 33 | 34 | /** Get the next sibling with the specified name. */ 35 | extern LIBLSL_C_API lsl_xml_ptr lsl_next_sibling_n(lsl_xml_ptr e, const char *name); 36 | 37 | /** Get the previous sibling with the specified name. */ 38 | extern LIBLSL_C_API lsl_xml_ptr lsl_previous_sibling_n(lsl_xml_ptr e, const char *name); 39 | 40 | 41 | // Content Queries 42 | 43 | /** Whether this node is empty. */ 44 | extern LIBLSL_C_API int32_t lsl_empty(lsl_xml_ptr e); 45 | 46 | /** Whether this is a text body (instead of an XML element). True both for plain char data and CData. */ 47 | extern LIBLSL_C_API int32_t lsl_is_text(lsl_xml_ptr e); 48 | 49 | /** Name of the element. */ 50 | extern LIBLSL_C_API const char *lsl_name(lsl_xml_ptr e); 51 | 52 | /** Value of the element. */ 53 | extern LIBLSL_C_API const char *lsl_value(lsl_xml_ptr e); 54 | 55 | /** Get child value (value of the first child that is text). */ 56 | extern LIBLSL_C_API const char *lsl_child_value(lsl_xml_ptr e); 57 | 58 | /** Get child value of a child with a specified name. */ 59 | extern LIBLSL_C_API const char *lsl_child_value_n(lsl_xml_ptr e, const char *name); 60 | 61 | 62 | // Data Modification 63 | 64 | /// Append a child node with a given name, which has a (nameless) plain-text child with the given text value. 65 | extern LIBLSL_C_API lsl_xml_ptr lsl_append_child_value(lsl_xml_ptr e, const char *name, const char *value); 66 | 67 | /// Prepend a child node with a given name, which has a (nameless) plain-text child with the given text value. 68 | extern LIBLSL_C_API lsl_xml_ptr lsl_prepend_child_value(lsl_xml_ptr e, const char *name, const char *value); 69 | 70 | /// Set the text value of the (nameless) plain-text child of a named child node. 71 | extern LIBLSL_C_API int32_t lsl_set_child_value(lsl_xml_ptr e, const char *name, const char *value); 72 | 73 | /** 74 | * Set the element's name. 75 | * @return 0 if the node is empty (or if out of memory). 76 | */ 77 | extern LIBLSL_C_API int32_t lsl_set_name(lsl_xml_ptr e, const char *rhs); 78 | 79 | /** 80 | * Set the element's value. 81 | * @return 0 if the node is empty (or if out of memory). 82 | */ 83 | extern LIBLSL_C_API int32_t lsl_set_value(lsl_xml_ptr e, const char *rhs); 84 | 85 | /** Append a child element with the specified name. */ 86 | extern LIBLSL_C_API lsl_xml_ptr lsl_append_child(lsl_xml_ptr e, const char *name); 87 | 88 | /** Prepend a child element with the specified name. */ 89 | extern LIBLSL_C_API lsl_xml_ptr lsl_prepend_child(lsl_xml_ptr e, const char *name); 90 | 91 | /** Append a copy of the specified element as a child. */ 92 | extern LIBLSL_C_API lsl_xml_ptr lsl_append_copy(lsl_xml_ptr e, lsl_xml_ptr e2); 93 | 94 | /** Prepend a child element with the specified name. */ 95 | extern LIBLSL_C_API lsl_xml_ptr lsl_prepend_copy(lsl_xml_ptr e, lsl_xml_ptr e2); 96 | 97 | /** Remove a child element with the specified name. */ 98 | extern LIBLSL_C_API void lsl_remove_child_n(lsl_xml_ptr e, const char *name); 99 | 100 | /** Remove a specified child element. */ 101 | extern LIBLSL_C_API void lsl_remove_child(lsl_xml_ptr e, lsl_xml_ptr e2); 102 | 103 | /// @} 104 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl_c.h: -------------------------------------------------------------------------------- 1 | #ifndef LSL_C_H 2 | #define LSL_C_H 3 | 4 | /** @file lsl_c.h LSL C API for the lab streaming layer 5 | * 6 | * The lab streaming layer provides a set of functions to make instrument data accessible 7 | * in real time within a lab network. From there, streams can be picked up by recording programs, 8 | * viewing programs or custom experiment applications that access data streams in real time. 9 | * 10 | * The API covers two areas: 11 | * - The "push API" allows to create stream outlets and to push data (regular or irregular 12 | * measurement time series, event data, coded audio/video frames, etc.) into them. 13 | * - The "pull API" allows to create stream inlets and read time-synched experiment data from them 14 | * (for recording, viewing or experiment control). 15 | * 16 | * To use this library you need to link to the liblsl library that comes with 17 | * this header. Under Visual Studio the library is linked in automatically. 18 | */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "lsl/common.h" 25 | #include "lsl/inlet.h" 26 | #include "lsl/outlet.h" 27 | #include "lsl/resolver.h" 28 | #include "lsl/streaminfo.h" 29 | #include "lsl/types.h" 30 | #include "lsl/xml.h" 31 | 32 | #ifdef __cplusplus 33 | } /* end extern "C" */ 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/include/lsl_cpp.h: -------------------------------------------------------------------------------- 1 | #ifndef LSL_CPP_H 2 | #define LSL_CPP_H 3 | 4 | /** 5 | * @file lsl_cpp.h 6 | * 7 | * C++ API for the lab streaming layer. 8 | * 9 | * The lab streaming layer provides a set of functions to make instrument data accessible 10 | * in real time within a lab network. From there, streams can be picked up by recording programs, 11 | * viewing programs or custom experiment applications that access data streams in real time. 12 | * 13 | * The API covers two areas: 14 | * - The "push API" allows to create stream outlets and to push data (regular or irregular 15 | * measurement time series, event data, coded audio/video frames, etc.) into them. 16 | * - The "pull API" allows to create stream inlets and read time-synched experiment data from them 17 | * (for recording, viewing or experiment control). 18 | * 19 | * To use this library you need to link to the shared library (lsl) that comes with 20 | * this header. Under Visual Studio the library is linked in automatically. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | extern "C" { 29 | #include "lsl_c.h" 30 | } 31 | 32 | namespace lsl { 33 | /// Assert that no error happened; throw appropriate exception otherwise 34 | int32_t check_error(int32_t ec); 35 | 36 | /// Constant to indicate that a stream has variable sampling rate. 37 | const double IRREGULAR_RATE = 0.0; 38 | 39 | /** 40 | * Constant to indicate that a sample has the next successive time stamp. 41 | * 42 | * This is an optional optimization to transmit less data per sample. 43 | * The stamp is then deduced from the preceding one according to the stream's sampling rate 44 | * (in the case of an irregular rate, the same time stamp as before will is assumed). 45 | */ 46 | const double DEDUCED_TIMESTAMP = -1.0; 47 | 48 | /** 49 | * A very large time duration (> 1 year) for timeout values. 50 | * 51 | * Note that significantly larger numbers can cause the timeout to be invalid on some operating 52 | * systems (e.g., 32-bit UNIX). 53 | */ 54 | const double FOREVER = 32000000.0; 55 | 56 | /// Data format of a channel (each transmitted sample holds an array of channels). 57 | enum channel_format_t { 58 | /** For up to 24-bit precision measurements in the appropriate physical unit (e.g., microvolts). 59 | Integers from -16777216 to 16777216 are represented accurately.*/ 60 | cf_float32 = 1, 61 | /// For universal numeric data as long as permitted by network & disk budget. 62 | /// The largest representable integer is 53-bit. 63 | cf_double64 = 2, 64 | /// For variable-length ASCII strings or data blobs, such as video frames, complex event 65 | /// descriptions, etc. 66 | cf_string = 3, 67 | /// For high-rate digitized formats that require 32-bit precision. 68 | /// Depends critically on meta-data to represent meaningful units. 69 | /// Useful for application event codes or other coded data. 70 | cf_int32 = 4, 71 | /// For very high rate signals (40Khz+) or consumer-grade audio (for professional audio float is 72 | /// recommended). 73 | cf_int16 = 5, 74 | /// For binary signals or other coded data. Not recommended for encoding string data. 75 | cf_int8 = 6, 76 | /// For now only for future compatibility. Support for this type is not yet exposed in all 77 | /// languages. Also, some builds of liblsl will not be able to send or receive data of this 78 | /// type. 79 | cf_int64 = 7, 80 | /// Can not be transmitted. 81 | cf_undefined = 0 82 | }; 83 | 84 | /// Post-processing options for stream inlets. 85 | enum processing_options_t { 86 | /// No automatic post-processing; return the ground-truth time stamps for manual post-processing 87 | /// (this is the default behavior of the inlet). 88 | post_none = 0, 89 | /// Perform automatic clock synchronization; equivalent to manually adding the time_correction() 90 | /// value to the received time stamps. 91 | post_clocksync = 1, 92 | /// Remove jitter from time stamps. This will apply a smoothing algorithm to the received time 93 | /// stamps; the smoothing needs to see a minimum number of samples (30-120 seconds worst-case) 94 | /// until the remaining jitter is consistently below 1ms. 95 | post_dejitter = 2, 96 | /// Force the time-stamps to be monotonically ascending (only makes sense if timestamps are 97 | /// dejittered). 98 | post_monotonize = 4, 99 | /// Post-processing is thread-safe (same inlet can be read from by multiple threads); uses 100 | /// somewhat more CPU. 101 | post_threadsafe = 8, 102 | /// The combination of all possible post-processing options. 103 | post_ALL = 1 | 2 | 4 | 8 104 | }; 105 | 106 | /** 107 | * Protocol version. 108 | * 109 | * The major version is `protocol_version() / 100`; 110 | * The minor version is `protocol_version() % 100`; 111 | * Clients with different minor versions are protocol-compatible with each other 112 | * while clients with different major versions will refuse to work together. 113 | */ 114 | inline int32_t protocol_version() { return lsl_protocol_version(); } 115 | 116 | /// @copydoc ::lsl_library_version() 117 | inline int32_t library_version() { return lsl_library_version(); } 118 | 119 | /** 120 | * Get a string containing library information. 121 | * 122 | * The format of the string shouldn't be used for anything important except giving a a debugging 123 | * person a good idea which exact library version is used. */ 124 | inline const char *library_info() { return lsl_library_info(); } 125 | 126 | /** 127 | * Obtain a local system time stamp in seconds. 128 | * 129 | * The resolution is better than a millisecond. 130 | * This reading can be used to assign time stamps to samples as they are being acquired. 131 | * If the "age" of a sample is known at a particular time (e.g., from USB transmission 132 | * delays), it can be used as an offset to local_clock() to obtain a better estimate of 133 | * when a sample was actually captured. See stream_outlet::push_sample() for a use case. 134 | */ 135 | inline double local_clock() { return lsl_local_clock(); } 136 | 137 | 138 | /// @section Stream Declaration 139 | 140 | class xml_element; 141 | 142 | /** 143 | * The stream_info object stores the declaration of a data stream. 144 | * 145 | * Represents the following information: 146 | * a) stream data format (number of channels, channel format) 147 | * b) core information (stream name, content type, sampling rate) 148 | * c) optional meta-data about the stream content (channel labels, measurement units, etc.) 149 | * 150 | * Whenever a program wants to provide a new stream on the lab network it will typically first 151 | * create a stream_info to describe its properties and then construct a stream_outlet with it to 152 | * create the stream on the network. Recipients who discover the outlet can query the stream_info; 153 | * it is also written to disk when recording the stream (playing a similar role as a file header). 154 | */ 155 | class stream_info { 156 | public: 157 | /** 158 | * Construct a new stream_info object. 159 | * 160 | * Core stream information is specified here. Any remaining meta-data can be added later. 161 | * @param name Name of the stream. Describes the device (or product series) that this stream 162 | * makes available (for use by programs, experimenters or data analysts). Cannot be empty. 163 | * @param type Content type of the stream. Please see https://github.com/sccn/xdf/wiki/Meta-Data 164 | * (or web search for: XDF meta-data) for pre-defined content-type names, but you can also make 165 | * up your own. The content type is the preferred way to find streams (as opposed to searching 166 | * by name). 167 | * @param channel_count Number of channels per sample. This stays constant for the lifetime of 168 | * the stream. 169 | * @param nominal_srate The sampling rate (in Hz) as advertised by the data source, if regular 170 | * (otherwise set to IRREGULAR_RATE). 171 | * @param channel_format Format/type of each channel. If your channels have different formats, 172 | * consider supplying multiple streams or use the largest type that can hold them all (such as 173 | * cf_double64). 174 | * @param source_id Unique identifier of the device or source of the data, if available (such as 175 | * the serial number). This is critical for system robustness since it allows recipients to 176 | * recover from failure even after the serving app, device or computer crashes (just by finding 177 | * a stream with the same source id on the network again). Therefore, it is highly recommended 178 | * to always try to provide whatever information can uniquely identify the data source itself. 179 | */ 180 | stream_info(const std::string &name, const std::string &type, int32_t channel_count = 1, 181 | double nominal_srate = IRREGULAR_RATE, channel_format_t channel_format = cf_float32, 182 | const std::string &source_id = std::string()) 183 | : obj(lsl_create_streaminfo((name.c_str()), (type.c_str()), channel_count, nominal_srate, 184 | (lsl_channel_format_t)channel_format, (source_id.c_str())), &lsl_destroy_streaminfo) { 185 | if (obj == nullptr) throw std::invalid_argument(lsl_last_error()); 186 | } 187 | 188 | /// Default contructor. 189 | stream_info(): stream_info("untitled", "", 0, 0, cf_undefined, ""){} 190 | 191 | /// Copy constructor. Only increments the reference count! @see clone() 192 | stream_info(const stream_info &) noexcept = default; 193 | stream_info(lsl_streaminfo handle) : obj(handle, &lsl_destroy_streaminfo) {} 194 | 195 | /// Clones a streaminfo object. 196 | stream_info clone() { return stream_info(lsl_copy_streaminfo(obj.get())); } 197 | 198 | 199 | // ======================== 200 | // === Core Information === 201 | // ======================== 202 | // (these fields are assigned at construction) 203 | 204 | /** 205 | * Name of the stream. 206 | * 207 | * This is a human-readable name. For streams offered by device modules, it refers to the type 208 | * of device or product series that is generating the data of the stream. If the source is an 209 | * application, the name may be a more generic or specific identifier. Multiple streams with the 210 | * same name can coexist, though potentially at the cost of ambiguity (for the recording app or 211 | * experimenter). 212 | */ 213 | std::string name() const { return lsl_get_name(obj.get()); } 214 | 215 | /** 216 | * Content type of the stream. 217 | * 218 | * The content type is a short string such as "EEG", "Gaze" which describes the content carried 219 | * by the channel (if known). If a stream contains mixed content this value need not be assigned 220 | * but may instead be stored in the description of channel types. To be useful to applications 221 | * and automated processing systems using the recommended content types is preferred. Content 222 | * types usually follow those pre-defined in https://github.com/sccn/xdf/wiki/Meta-Data (or web 223 | * search for: XDF meta-data). 224 | */ 225 | std::string type() const { return lsl_get_type(obj.get()); } 226 | 227 | /** 228 | * Number of channels of the stream. 229 | * 230 | * A stream has at least one channel; the channel count stays constant for all samples. 231 | */ 232 | int32_t channel_count() const { return lsl_get_channel_count(obj.get()); } 233 | 234 | /** 235 | * Sampling rate of the stream, according to the source (in Hz). 236 | * 237 | * If a stream is irregularly sampled, this should be set to IRREGULAR_RATE. 238 | * 239 | * Note that no data will be lost even if this sampling rate is incorrect or if a device has 240 | * temporary hiccups, since all samples will be recorded anyway (except for those dropped by the 241 | * device itself). However, when the recording is imported into an application, a good importer 242 | * may correct such errors more accurately if the advertised sampling rate was close to the 243 | * specs of the device. 244 | */ 245 | double nominal_srate() const { return lsl_get_nominal_srate(obj.get()); } 246 | 247 | /** 248 | * Channel format of the stream. 249 | * 250 | * All channels in a stream have the same format. However, a device might offer multiple 251 | * time-synched streams each with its own format. 252 | */ 253 | channel_format_t channel_format() const { 254 | return static_cast(lsl_get_channel_format(obj.get())); 255 | } 256 | 257 | /** 258 | * Unique identifier of the stream's source, if available. 259 | * 260 | * The unique source (or device) identifier is an optional piece of information that, if 261 | * available, allows that endpoints (such as the recording program) can re-acquire a stream 262 | * automatically once it is back online. 263 | */ 264 | std::string source_id() const { return lsl_get_source_id(obj.get()); } 265 | 266 | 267 | // ====================================== 268 | // === Additional Hosting Information === 269 | // ====================================== 270 | // (these fields are implicitly assigned once bound to an outlet/inlet) 271 | 272 | /// Protocol version used to deliver the stream. 273 | int32_t version() const { return lsl_get_version(obj.get()); } 274 | 275 | /** 276 | * Creation time stamp of the stream. 277 | * 278 | * This is the time stamp when the stream was first created 279 | * (as determined via #lsl::local_clock() on the providing machine). 280 | */ 281 | double created_at() const { return lsl_get_created_at(obj.get()); } 282 | 283 | /** 284 | * Unique ID of the stream outlet instance (once assigned). 285 | * 286 | * This is a unique identifier of the stream outlet, and is guaranteed to be different 287 | * across multiple instantiations of the same outlet (e.g., after a re-start). 288 | */ 289 | std::string uid() const { return lsl_get_uid(obj.get()); } 290 | 291 | /** 292 | * Session ID for the given stream. 293 | * 294 | * The session id is an optional human-assigned identifier of the recording session. 295 | * While it is rarely used, it can be used to prevent concurrent recording activitites 296 | * on the same sub-network (e.g., in multiple experiment areas) from seeing each other's streams 297 | * (assigned via a configuration file by the experimenter, see Network Connectivity in the LSL 298 | * wiki). 299 | */ 300 | std::string session_id() const { return lsl_get_session_id(obj.get()); } 301 | 302 | /// Hostname of the providing machine. 303 | std::string hostname() const { return lsl_get_hostname(obj.get()); } 304 | 305 | 306 | // ======================== 307 | // === Data Description === 308 | // ======================== 309 | 310 | /** 311 | * Extended description of the stream. 312 | * 313 | * It is highly recommended that at least the channel labels are described here. 314 | * See code examples on the LSL wiki. Other information, such as amplifier settings, 315 | * measurement units if deviating from defaults, setup information, subject information, etc., 316 | * can be specified here, as well. Meta-data recommendations follow the XDF file format project 317 | * (github.com/sccn/xdf/wiki/Meta-Data or web search for: XDF meta-data). 318 | * 319 | * Important: if you use a stream content type for which meta-data recommendations exist, please 320 | * try to lay out your meta-data in agreement with these recommendations for compatibility with 321 | * other applications. 322 | */ 323 | xml_element desc(); 324 | 325 | /// lsl_stream_info_matches_query 326 | bool matches_query(const char *query) const { 327 | return lsl_stream_info_matches_query(obj.get(), query); 328 | } 329 | 330 | 331 | // =============================== 332 | // === Miscellaneous Functions === 333 | // =============================== 334 | 335 | /** Retrieve the entire streaminfo in XML format. 336 | * This yields an XML document (in string form) whose top-level element is ``. The info 337 | * element contains one element for each field of the streaminfo class, including: 338 | * 339 | * - the core elements ``, ``, ``, 340 | * ``, `` 341 | * - the misc elements ``, ``, ``, ``, 342 | * ``, ``, ``, ``, ``, 343 | * `` 344 | * - the extended description element `` with user-defined sub-elements. 345 | */ 346 | std::string as_xml() const { 347 | char *tmp = lsl_get_xml(obj.get()); 348 | std::string result(tmp); 349 | lsl_destroy_string(tmp); 350 | return result; 351 | } 352 | 353 | /// Number of bytes occupied by a channel (0 for string-typed channels). 354 | int32_t channel_bytes() const { return lsl_get_channel_bytes(obj.get()); } 355 | 356 | /// Number of bytes occupied by a sample (0 for string-typed channels). 357 | int32_t sample_bytes() const { return lsl_get_sample_bytes(obj.get()); } 358 | 359 | /// Get the implementation handle. 360 | std::shared_ptr handle() const { return obj; } 361 | 362 | /// Assignment operator. 363 | stream_info &operator=(const stream_info &rhs) { 364 | if (this != &rhs) obj = stream_info(rhs).handle(); 365 | return *this; 366 | } 367 | 368 | stream_info(stream_info &&rhs) noexcept = default; 369 | 370 | stream_info &operator=(stream_info &&rhs) noexcept = default; 371 | 372 | /// Utility function to create a stream_info from an XML representation 373 | static stream_info from_xml(const std::string &xml) { 374 | return stream_info(lsl_streaminfo_from_xml(xml.c_str())); 375 | } 376 | 377 | private: 378 | std::shared_ptr obj; 379 | }; 380 | 381 | 382 | // ======================= 383 | // ==== Stream Outlet ==== 384 | // ======================= 385 | 386 | /** A stream outlet. 387 | * Outlets are used to make streaming data (and the meta-data) available on the lab network. 388 | */ 389 | class stream_outlet { 390 | public: 391 | /** Establish a new stream outlet. This makes the stream discoverable. 392 | * @param info The stream information to use for creating this stream. Stays constant over the 393 | * lifetime of the outlet. 394 | * @param chunk_size Optionally the desired chunk granularity (in samples) for transmission. If 395 | * unspecified, each push operation yields one chunk. Inlets can override this setting. 396 | * @param max_buffered Optionally the maximum amount of data to buffer (in seconds if there is a 397 | * nominal sampling rate, otherwise x100 in samples). The default is 6 minutes of data. 398 | */ 399 | stream_outlet(const stream_info &info, int32_t chunk_size = 0, int32_t max_buffered = 360, 400 | lsl_transport_options_t flags = transp_default) 401 | : channel_count(info.channel_count()), sample_rate(info.nominal_srate()), 402 | obj(lsl_create_outlet_ex(info.handle().get(), chunk_size, max_buffered, flags), 403 | &lsl_destroy_outlet) {} 404 | 405 | // ======================================== 406 | // === Pushing a sample into the outlet === 407 | // ======================================== 408 | 409 | /** Push a C array of values as a sample into the outlet. 410 | * Each entry in the array corresponds to one channel. 411 | * The function handles type checking & conversion. 412 | * @param data An array of values to push (one per channel). 413 | * @param timestamp Optionally the capture time of the sample, in agreement with 414 | * lsl::local_clock(); if omitted, the current time is used. 415 | * @param pushthrough Whether to push the sample through to the receivers instead of 416 | * buffering it with subsequent samples. 417 | * Note that the chunk_size, if specified at outlet construction, takes precedence over the 418 | * pushthrough flag. 419 | */ 420 | template 421 | void push_sample(const T data[N], double timestamp = 0.0, bool pushthrough = true) { 422 | check_numchan(N); 423 | push_sample(&data[0], timestamp, pushthrough); 424 | } 425 | 426 | /** Push a std vector of values as a sample into the outlet. 427 | * Each entry in the vector corresponds to one channel. The function handles type checking & 428 | * conversion. 429 | * @param data A vector of values to push (one for each channel). 430 | * @param timestamp Optionally the capture time of the sample, in agreement with local_clock(); 431 | * if omitted, the current time is used. 432 | * @param pushthrough Whether to push the sample through to the receivers instead of buffering 433 | * it with subsequent samples. Note that the chunk_size, if specified at outlet construction, 434 | * takes precedence over the pushthrough flag. 435 | */ 436 | template 437 | void push_sample( 438 | const std::vector &data, double timestamp = 0.0, bool pushthrough = true) { 439 | check_numchan(data.size()); 440 | push_sample(data.data(), timestamp, pushthrough); 441 | } 442 | 443 | /** Push a pointer to some values as a sample into the outlet. 444 | * This is a lower-level function for cases where data is available in some buffer. 445 | * Handles type checking & conversion. 446 | * @param data A pointer to values to push. The number of values pointed to must not be less 447 | * than the number of channels in the sample. 448 | * @param timestamp Optionally the capture time of the sample, in agreement with local_clock(); 449 | * if omitted, the current time is used. 450 | * @param pushthrough Whether to push the sample through to the receivers instead of buffering 451 | * it with subsequent samples. Note that the chunk_size, if specified at outlet construction, 452 | * takes precedence over the pushthrough flag. 453 | */ 454 | void push_sample(const float *data, double timestamp = 0.0, bool pushthrough = true) { 455 | lsl_push_sample_ftp(obj.get(), (data), timestamp, pushthrough); 456 | } 457 | void push_sample(const double *data, double timestamp = 0.0, bool pushthrough = true) { 458 | lsl_push_sample_dtp(obj.get(), (data), timestamp, pushthrough); 459 | } 460 | void push_sample(const int64_t *data, double timestamp = 0.0, bool pushthrough = true) { 461 | lsl_push_sample_ltp(obj.get(), (data), timestamp, pushthrough); 462 | } 463 | void push_sample(const int32_t *data, double timestamp = 0.0, bool pushthrough = true) { 464 | lsl_push_sample_itp(obj.get(), (data), timestamp, pushthrough); 465 | } 466 | void push_sample(const int16_t *data, double timestamp = 0.0, bool pushthrough = true) { 467 | lsl_push_sample_stp(obj.get(), (data), timestamp, pushthrough); 468 | } 469 | void push_sample(const char *data, double timestamp = 0.0, bool pushthrough = true) { 470 | lsl_push_sample_ctp(obj.get(), (data), timestamp, pushthrough); 471 | } 472 | void push_sample(const std::string *data, double timestamp = 0.0, bool pushthrough = true) { 473 | std::vector lengths(channel_count); 474 | std::vector pointers(channel_count); 475 | for (int32_t k = 0; k < channel_count; k++) { 476 | pointers[k] = data[k].c_str(); 477 | lengths[k] = (uint32_t)data[k].size(); 478 | } 479 | lsl_push_sample_buftp(obj.get(), pointers.data(), lengths.data(), timestamp, pushthrough); 480 | } 481 | 482 | /** Push a packed C struct (of numeric data) as one sample into the outlet (search for 483 | * [`#``pragma pack`](https://stackoverflow.com/a/3318475/73299) for information on packing 484 | * structs appropriately).
485 | * Overall size checking but no type checking or conversion are done.
486 | * Can not be used forvariable-size / string-formatted data. 487 | * @param sample The sample struct to push. 488 | * @param timestamp Optionally the capture time of the sample, in agreement with 489 | * local_clock(); if omitted, the current time is used. 490 | * @param pushthrough Whether to push the sample through to the receivers instead of 491 | * buffering it with subsequent samples. Note that the chunk_size, if specified at outlet 492 | * construction, takes precedence over the pushthrough flag. 493 | */ 494 | template 495 | void push_numeric_struct(const T &sample, double timestamp = 0.0, bool pushthrough = true) { 496 | if (info().sample_bytes() != sizeof(T)) 497 | throw std::runtime_error( 498 | "Provided object size does not match the stream's sample size."); 499 | push_numeric_raw((void *)&sample, timestamp, pushthrough); 500 | } 501 | 502 | /** Push a pointer to raw numeric data as one sample into the outlet. 503 | * This is the lowest-level function; performs no checking whatsoever. Cannot be used for 504 | * variable-size / string-formatted channels. 505 | * @param sample A pointer to the raw sample data to push. 506 | * @param timestamp Optionally the capture time of the sample, in agreement with local_clock(); 507 | * if omitted, the current time is used. 508 | * @param pushthrough Whether to push the sample through to the receivers instead of buffering 509 | * it with subsequent samples. Note that the chunk_size, if specified at outlet construction, 510 | * takes precedence over the pushthrough flag. 511 | */ 512 | void push_numeric_raw(const void *sample, double timestamp = 0.0, bool pushthrough = true) { 513 | lsl_push_sample_vtp(obj.get(), (sample), timestamp, pushthrough); 514 | } 515 | 516 | 517 | // =================================================== 518 | // === Pushing an chunk of samples into the outlet === 519 | // =================================================== 520 | 521 | /** Push a chunk of samples (batched into an STL vector) into the outlet. 522 | * @param samples A vector of samples in some supported format (each sample can be a data 523 | * pointer, data array, or std vector of data). 524 | * @param timestamp Optionally the capture time of the most recent sample, in agreement with 525 | * local_clock(); if omitted, the current time is used. The time stamps of other samples are 526 | * automatically derived according to the sampling rate of the stream. 527 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 528 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 529 | * precedence over the pushthrough flag. 530 | */ 531 | template 532 | void push_chunk( 533 | const std::vector &samples, double timestamp = 0.0, bool pushthrough = true) { 534 | if (!samples.empty()) { 535 | if (timestamp == 0.0) timestamp = local_clock(); 536 | if (sample_rate != IRREGULAR_RATE) 537 | timestamp = timestamp - (samples.size() - 1) / sample_rate; 538 | push_sample(samples[0], timestamp, pushthrough && samples.size() == 1); 539 | for (std::size_t k = 1; k < samples.size(); k++) 540 | push_sample(samples[k], DEDUCED_TIMESTAMP, pushthrough && k == samples.size() - 1); 541 | } 542 | } 543 | 544 | /** Push a chunk of samples (batched into an STL vector) into the outlet. 545 | * Allows to specify a separate time stamp for each sample (for irregular-rate streams). 546 | * @param samples A vector of samples in some supported format (each sample can be a data 547 | * pointer, data array, or std vector of data). 548 | * @param timestamps A vector of capture times for each sample, in agreement with local_clock(). 549 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 550 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 551 | * precedence over the pushthrough flag. 552 | */ 553 | template 554 | void push_chunk(const std::vector &samples, const std::vector ×tamps, 555 | bool pushthrough = true) { 556 | for (unsigned k = 0; k < samples.size() - 1; k++) 557 | push_sample(samples[k], timestamps[k], false); 558 | if (!samples.empty()) push_sample(samples.back(), timestamps.back(), pushthrough); 559 | } 560 | 561 | /** Push a chunk of numeric data as C-style structs (batched into an STL vector) into the 562 | * outlet. This performs some size checking but no type checking. Can not be used for 563 | * variable-size / string-formatted data. 564 | * @param samples A vector of samples, as C structs. 565 | * @param timestamp Optionally the capture time of the sample, in agreement with local_clock(); 566 | * if omitted, the current time is used. 567 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 568 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 569 | * precedence over the pushthrough flag. 570 | */ 571 | template 572 | void push_chunk_numeric_structs( 573 | const std::vector &samples, double timestamp = 0.0, bool pushthrough = true) { 574 | if (!samples.empty()) { 575 | if (timestamp == 0.0) timestamp = local_clock(); 576 | if (sample_rate != IRREGULAR_RATE) 577 | timestamp = timestamp - (samples.size() - 1) / sample_rate; 578 | push_numeric_struct(samples[0], timestamp, pushthrough && samples.size() == 1); 579 | for (std::size_t k = 1; k < samples.size(); k++) 580 | push_numeric_struct( 581 | samples[k], DEDUCED_TIMESTAMP, pushthrough && k == samples.size() - 1); 582 | } 583 | } 584 | 585 | /** Push a chunk of numeric data from C-style structs (batched into an STL vector), into the 586 | * outlet. This performs some size checking but no type checking. Can not be used for 587 | * variable-size / string-formatted data. 588 | * @param samples A vector of samples, as C structs. 589 | * @param timestamps A vector of capture times for each sample, in agreement with local_clock(). 590 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 591 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 592 | * precedence over the pushthrough flag. 593 | */ 594 | template 595 | void push_chunk_numeric_structs(const std::vector &samples, 596 | const std::vector ×tamps, bool pushthrough = true) { 597 | for (unsigned k = 0; k < samples.size() - 1; k++) 598 | push_numeric_struct(samples[k], timestamps[k], false); 599 | if (!samples.empty()) push_numeric_struct(samples.back(), timestamps.back(), pushthrough); 600 | } 601 | 602 | /** Push a chunk of multiplexed data into the outlet. 603 | * @name Push functions 604 | * @param buffer A buffer of channel values holding the data for zero or more successive samples 605 | * to send. 606 | * @param timestamp Optionally the capture time of the most recent sample, in agreement with 607 | * local_clock(); if omitted, the current time is used. The time stamps of other samples are 608 | * automatically derived according to the sampling rate of the stream. 609 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 610 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 611 | * precedence over the pushthrough flag. 612 | */ 613 | template 614 | void push_chunk_multiplexed( 615 | const std::vector &buffer, double timestamp = 0.0, bool pushthrough = true) { 616 | if (!buffer.empty()) 617 | push_chunk_multiplexed( 618 | buffer.data(), static_cast(buffer.size()), timestamp, pushthrough); 619 | } 620 | 621 | /** Push a chunk of multiplexed data into the outlet. One timestamp per sample is provided. 622 | * Allows to specify a separate time stamp for each sample (for irregular-rate streams). 623 | * @param buffer A buffer of channel values holding the data for zero or more successive samples 624 | * to send. 625 | * @param timestamps A buffer of timestamp values holding time stamps for each sample in the 626 | * data buffer. 627 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 628 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 629 | * precedence over the pushthrough flag. 630 | */ 631 | template 632 | void push_chunk_multiplexed(const std::vector &buffer, 633 | const std::vector ×tamps, bool pushthrough = true) { 634 | if (!buffer.empty() && !timestamps.empty()) 635 | push_chunk_multiplexed( 636 | buffer.data(), static_cast(buffer.size()), timestamps.data(), pushthrough); 637 | } 638 | 639 | /** Push a chunk of multiplexed samples into the outlet. Single timestamp provided. 640 | * @warning The provided buffer size is measured in channel values (e.g., floats), not samples. 641 | * @param buffer A buffer of channel values holding the data for zero or more successive samples 642 | * to send. 643 | * @param buffer_elements The number of channel values (of type T) in the buffer. Must be a 644 | * multiple of the channel count. 645 | * @param timestamp Optionally the capture time of the most recent sample, in agreement with 646 | * local_clock(); if omitted, the current time is used. The time stamps of other samples are 647 | * automatically derived based on the sampling rate of the stream. 648 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 649 | * with subsequent samples. Note that the stream_outlet() constructur parameter @p chunk_size, 650 | * if specified at outlet construction, takes precedence over the pushthrough flag. 651 | */ 652 | void push_chunk_multiplexed(const float *buffer, std::size_t buffer_elements, 653 | double timestamp = 0.0, bool pushthrough = true) { 654 | lsl_push_chunk_ftp(obj.get(), buffer, static_cast(buffer_elements), timestamp, pushthrough); 655 | } 656 | void push_chunk_multiplexed(const double *buffer, std::size_t buffer_elements, 657 | double timestamp = 0.0, bool pushthrough = true) { 658 | lsl_push_chunk_dtp(obj.get(), buffer, static_cast(buffer_elements), timestamp, pushthrough); 659 | } 660 | void push_chunk_multiplexed(const int64_t *buffer, std::size_t buffer_elements, 661 | double timestamp = 0.0, bool pushthrough = true) { 662 | lsl_push_chunk_ltp(obj.get(), buffer, static_cast(buffer_elements), timestamp, pushthrough); 663 | } 664 | void push_chunk_multiplexed(const int32_t *buffer, std::size_t buffer_elements, 665 | double timestamp = 0.0, bool pushthrough = true) { 666 | lsl_push_chunk_itp(obj.get(), buffer, static_cast(buffer_elements), timestamp, pushthrough); 667 | } 668 | void push_chunk_multiplexed(const int16_t *buffer, std::size_t buffer_elements, 669 | double timestamp = 0.0, bool pushthrough = true) { 670 | lsl_push_chunk_stp(obj.get(), buffer, static_cast(buffer_elements), timestamp, pushthrough); 671 | } 672 | void push_chunk_multiplexed(const char *buffer, std::size_t buffer_elements, 673 | double timestamp = 0.0, bool pushthrough = true) { 674 | lsl_push_chunk_ctp(obj.get(), buffer, static_cast(buffer_elements), timestamp, pushthrough); 675 | } 676 | void push_chunk_multiplexed(const std::string *buffer, std::size_t buffer_elements, 677 | double timestamp = 0.0, bool pushthrough = true) { 678 | if (buffer_elements) { 679 | std::vector lengths(buffer_elements); 680 | std::vector pointers(buffer_elements); 681 | for (std::size_t k = 0; k < buffer_elements; k++) { 682 | pointers[k] = buffer[k].c_str(); 683 | lengths[k] = (uint32_t)buffer[k].size(); 684 | } 685 | lsl_push_chunk_buftp(obj.get(), pointers.data(), lengths.data(), 686 | static_cast(buffer_elements), timestamp, pushthrough); 687 | } 688 | } 689 | 690 | /** Push a chunk of multiplexed samples into the outlet. One timestamp per sample is provided. 691 | * @warning Note that the provided buffer size is measured in channel values (e.g., floats) 692 | * rather than in samples. 693 | * @param data_buffer A buffer of channel values holding the data for zero or more successive 694 | * samples to send. 695 | * @param timestamp_buffer A buffer of timestamp values holding time stamps for each sample in 696 | * the data buffer. 697 | * @param data_buffer_elements The number of data values (of type T) in the data buffer. Must be 698 | * a multiple of the channel count. 699 | * @param pushthrough Whether to push the chunk through to the receivers instead of buffering it 700 | * with subsequent samples. Note that the chunk_size, if specified at outlet construction, takes 701 | * precedence over the pushthrough flag. 702 | */ 703 | void push_chunk_multiplexed(const float *data_buffer, const double *timestamp_buffer, 704 | std::size_t data_buffer_elements, bool pushthrough = true) { 705 | lsl_push_chunk_ftnp(obj.get(), data_buffer, static_cast(data_buffer_elements), 706 | (timestamp_buffer), pushthrough); 707 | } 708 | void push_chunk_multiplexed(const double *data_buffer, const double *timestamp_buffer, 709 | std::size_t data_buffer_elements, bool pushthrough = true) { 710 | lsl_push_chunk_dtnp(obj.get(), data_buffer, static_cast(data_buffer_elements), 711 | (timestamp_buffer), pushthrough); 712 | } 713 | void push_chunk_multiplexed(const int64_t *data_buffer, const double *timestamp_buffer, 714 | std::size_t data_buffer_elements, bool pushthrough = true) { 715 | lsl_push_chunk_ltnp(obj.get(), data_buffer, static_cast(data_buffer_elements), 716 | (timestamp_buffer), pushthrough); 717 | } 718 | void push_chunk_multiplexed(const int32_t *data_buffer, const double *timestamp_buffer, 719 | std::size_t data_buffer_elements, bool pushthrough = true) { 720 | lsl_push_chunk_itnp(obj.get(), data_buffer, static_cast(data_buffer_elements), 721 | (timestamp_buffer), pushthrough); 722 | } 723 | void push_chunk_multiplexed(const int16_t *data_buffer, const double *timestamp_buffer, 724 | std::size_t data_buffer_elements, bool pushthrough = true) { 725 | lsl_push_chunk_stnp(obj.get(), data_buffer, static_cast(data_buffer_elements), 726 | (timestamp_buffer), pushthrough); 727 | } 728 | void push_chunk_multiplexed(const char *data_buffer, const double *timestamp_buffer, 729 | std::size_t data_buffer_elements, bool pushthrough = true) { 730 | lsl_push_chunk_ctnp(obj.get(), data_buffer, static_cast(data_buffer_elements), 731 | (timestamp_buffer), pushthrough); 732 | } 733 | 734 | void push_chunk_multiplexed(const std::string *data_buffer, const double *timestamp_buffer, 735 | std::size_t data_buffer_elements, bool pushthrough = true) { 736 | if (data_buffer_elements) { 737 | std::vector lengths(data_buffer_elements); 738 | std::vector pointers(data_buffer_elements); 739 | for (std::size_t k = 0; k < data_buffer_elements; k++) { 740 | pointers[k] = data_buffer[k].c_str(); 741 | lengths[k] = (uint32_t)data_buffer[k].size(); 742 | } 743 | lsl_push_chunk_buftnp(obj.get(), pointers.data(), lengths.data(), 744 | static_cast(data_buffer_elements), timestamp_buffer, pushthrough); 745 | } 746 | } 747 | 748 | 749 | // =============================== 750 | // === Miscellaneous Functions === 751 | // =============================== 752 | 753 | /** Check whether consumers are currently registered. 754 | * While it does not hurt, there is technically no reason to push samples if there is no 755 | * consumer. 756 | */ 757 | bool have_consumers() { return lsl_have_consumers(obj.get()) != 0; } 758 | 759 | /** Wait until some consumer shows up (without wasting resources). 760 | * @return True if the wait was successful, false if the timeout expired. 761 | */ 762 | bool wait_for_consumers(double timeout) { return lsl_wait_for_consumers(obj.get(), timeout) != 0; } 763 | 764 | /** Retrieve the stream info provided by this outlet. 765 | * This is what was used to create the stream (and also has the Additional Network Information 766 | * fields assigned). 767 | */ 768 | stream_info info() const { return stream_info(lsl_get_info(obj.get())); } 769 | 770 | /// Return a shared pointer to pass to C-API functions that aren't wrapped yet 771 | /// 772 | /// Example: @code lsl_push_chunk_buft(outlet.handle().get(), data, …); @endcode 773 | std::shared_ptr handle() { return obj; } 774 | 775 | /** Destructor. 776 | * The stream will no longer be discoverable after destruction and all paired inlets will stop 777 | * delivering data. 778 | */ 779 | ~stream_outlet() = default; 780 | 781 | /// stream_outlet move constructor 782 | stream_outlet(stream_outlet &&res) noexcept = default; 783 | 784 | stream_outlet &operator=(stream_outlet &&rhs) noexcept = default; 785 | 786 | 787 | private: 788 | // The outlet is a non-copyable object. 789 | stream_outlet(const stream_outlet &rhs); 790 | stream_outlet &operator=(const stream_outlet &rhs); 791 | 792 | /// Check whether a given data length matches the number of channels; throw if not 793 | void check_numchan(std::size_t N) const { 794 | if (N != static_cast(channel_count)) 795 | throw std::runtime_error("Provided element count (" + std::to_string(N) + 796 | ") does not match the stream's channel count (" + 797 | std::to_string(channel_count) + '.'); 798 | } 799 | 800 | int32_t channel_count; 801 | double sample_rate; 802 | std::shared_ptr obj; 803 | }; 804 | 805 | 806 | // =========================== 807 | // ==== Resolve Functions ==== 808 | // =========================== 809 | 810 | /** Resolve all streams on the network. 811 | * This function returns all currently available streams from any outlet on the network. 812 | * The network is usually the subnet specified at the local router, but may also include 813 | * a multicast group of machines (given that the network supports it), or list of hostnames. 814 | * These details may optionally be customized by the experimenter in a configuration file 815 | * (see Network Connectivity in the LSL wiki). 816 | * This is the default mechanism used by the browsing programs and the recording program. 817 | * @param wait_time The waiting time for the operation, in seconds, to search for streams. 818 | * If this is too short (<0.5s) only a subset (or none) of the outlets that are present on the 819 | * network may be returned. 820 | * @return A vector of stream info objects (excluding their desc field), any of which can 821 | * subsequently be used to open an inlet. The full info can be retrieve from the inlet. 822 | */ 823 | inline std::vector resolve_streams(double wait_time = 1.0) { 824 | lsl_streaminfo buffer[1024]; 825 | int nres = check_error(lsl_resolve_all(buffer, sizeof(buffer), wait_time)); 826 | return std::vector(&buffer[0], &buffer[nres]); 827 | } 828 | 829 | /** Resolve all streams with a specific value for a given property. 830 | * If the goal is to resolve a specific stream, this method is preferred over resolving all streams 831 | * and then selecting the desired one. 832 | * @param prop The stream_info property that should have a specific value (e.g., "name", "type", 833 | * "source_id", or "desc/manufaturer"). 834 | * @param value The string value that the property should have (e.g., "EEG" as the type property). 835 | * @param minimum Return at least this number of streams. 836 | * @param timeout Optionally a timeout of the operation, in seconds (default: no timeout). 837 | * If the timeout expires, less than the desired number of streams (possibly none) 838 | * will be returned. 839 | * @return A vector of matching stream info objects (excluding their meta-data), any of 840 | * which can subsequently be used to open an inlet. 841 | */ 842 | inline std::vector resolve_stream(const std::string &prop, const std::string &value, 843 | int32_t minimum = 1, double timeout = FOREVER) { 844 | lsl_streaminfo buffer[1024]; 845 | int nres = check_error( 846 | lsl_resolve_byprop(buffer, sizeof(buffer), prop.c_str(), value.c_str(), minimum, timeout)); 847 | return std::vector(&buffer[0], &buffer[nres]); 848 | } 849 | 850 | /** Resolve all streams that match a given predicate. 851 | * 852 | * Advanced query that allows to impose more conditions on the retrieved streams; the given 853 | * string is an [XPath 1.0](http://en.wikipedia.org/w/index.php?title=XPath_1.0) predicate for 854 | * the `` node (omitting the surrounding []'s) 855 | * @param pred The predicate string, e.g. `name='BioSemi'` or 856 | * `type='EEG' and starts-with(name,'BioSemi') and count(info/desc/channel)=32` 857 | * @param minimum Return at least this number of streams. 858 | * @param timeout Optionally a timeout of the operation, in seconds (default: no timeout). 859 | * If the timeout expires, less than the desired number of streams (possibly 860 | * none) will be returned. 861 | * @return A vector of matching stream info objects (excluding their meta-data), any of 862 | * which can subsequently be used to open an inlet. 863 | */ 864 | inline std::vector resolve_stream( 865 | const std::string &pred, int32_t minimum = 1, double timeout = FOREVER) { 866 | lsl_streaminfo buffer[1024]; 867 | int nres = 868 | check_error(lsl_resolve_bypred(buffer, sizeof(buffer), pred.c_str(), minimum, timeout)); 869 | return std::vector(&buffer[0], &buffer[nres]); 870 | } 871 | 872 | 873 | // ====================== 874 | // ==== Stream Inlet ==== 875 | // ====================== 876 | 877 | /** A stream inlet. 878 | * Inlets are used to receive streaming data (and meta-data) from the lab network. 879 | */ 880 | class stream_inlet { 881 | public: 882 | /** 883 | * Construct a new stream inlet from a resolved stream info. 884 | * @param info A resolved stream info object (as coming from one of the resolver functions). 885 | * Note: The stream_inlet may also be constructed with a fully-specified stream_info, if the 886 | * desired channel format and count is already known up-front, but this is strongly discouraged 887 | * and should only ever be done if there is no time to resolve the stream up-front (e.g., due 888 | * to limitations in the client program). 889 | * @param max_buflen Optionally the maximum amount of data to buffer (in seconds if there is a 890 | * nominal sampling rate, otherwise x100 in samples). Recording applications want to use a 891 | * fairly large buffer size here, while real-time applications would only buffer as much as 892 | * they need to perform their next calculation. 893 | * @param max_chunklen Optionally the maximum size, in samples, at which chunks are transmitted 894 | * (the default corresponds to the chunk sizes used by the sender). 895 | * Recording applications can use a generous size here (leaving it to the network how to pack 896 | * things), while real-time applications may want a finer (perhaps 1-sample) granularity. 897 | * If left unspecified (=0), the sender determines the chunk granularity. 898 | * @param recover Try to silently recover lost streams that are recoverable (=those that that 899 | * have a source_id set). 900 | * In all other cases (recover is false or the stream is not recoverable) functions may throw a 901 | * lsl::lost_error if the stream's source is lost (e.g., due to an app or computer crash). 902 | */ 903 | stream_inlet(const stream_info &info, int32_t max_buflen = 360, int32_t max_chunklen = 0, 904 | bool recover = true, lsl_transport_options_t flags = transp_default) 905 | : channel_count(info.channel_count()), 906 | obj(lsl_create_inlet_ex(info.handle().get(), max_buflen, max_chunklen, recover, flags), 907 | &lsl_destroy_inlet) {} 908 | 909 | /// Return a shared pointer to pass to C-API functions that aren't wrapped yet 910 | /// 911 | /// Example: @code lsl_pull_sample_buf(inlet.handle().get(), buf, …); @endcode 912 | std::shared_ptr handle() { return obj; } 913 | 914 | /// Move constructor for stream_inlet 915 | stream_inlet(stream_inlet &&rhs) noexcept = default; 916 | stream_inlet &operator=(stream_inlet &&rhs) noexcept= default; 917 | 918 | 919 | /** Retrieve the complete information of the given stream, including the extended description. 920 | * Can be invoked at any time of the stream's lifetime. 921 | * @param timeout Timeout of the operation (default: no timeout). 922 | * @throws timeout_error (if the timeout expires), or lost_error (if the stream source has been 923 | * lost). 924 | */ 925 | stream_info info(double timeout = FOREVER) { 926 | int32_t ec = 0; 927 | lsl_streaminfo res = lsl_get_fullinfo(obj.get(), timeout, &ec); 928 | check_error(ec); 929 | return stream_info(res); 930 | } 931 | 932 | /** Subscribe to the data stream. 933 | * All samples pushed in at the other end from this moment onwards will be queued and 934 | * eventually be delivered in response to pull_sample() or pull_chunk() calls. 935 | * Pulling a sample without some preceding open_stream() is permitted (the stream will then be 936 | * opened implicitly). 937 | * @param timeout Optional timeout of the operation (default: no timeout). 938 | * @throws timeout_error (if the timeout expires), or lost_error (if the stream source has been 939 | * lost). 940 | */ 941 | void open_stream(double timeout = FOREVER) { 942 | int32_t ec = 0; 943 | lsl_open_stream(obj.get(), timeout, &ec); 944 | check_error(ec); 945 | } 946 | 947 | /** Drop the current data stream. 948 | * 949 | * All samples that are still buffered or in flight will be dropped and transmission 950 | * and buffering of data for this inlet will be stopped. If an application stops being 951 | * interested in data from a source (temporarily or not) but keeps the outlet alive, 952 | * it should call close_stream() to not waste unnecessary system and network 953 | * resources. 954 | */ 955 | void close_stream() { lsl_close_stream(obj.get()); } 956 | 957 | /** Retrieve an estimated time correction offset for the given stream. 958 | * 959 | * The first call to this function takes several milliseconds until a reliable first estimate 960 | * is obtained. Subsequent calls are instantaneous (and rely on periodic background updates). 961 | * On a well-behaved network, the precision of these estimates should be below 1 ms 962 | * (empirically it is within +/-0.2 ms). 963 | * 964 | * To get a measure of whether the network is well-behaved, use the extended version 965 | * time_correction(double*,double*,double) and check uncertainty (i.e. the round-trip-time). 966 | * 967 | * 0.2 ms is typical of wired networks. 2 ms is typical of wireless networks. 968 | * The number can be much higher on poor networks. 969 | * 970 | * @param timeout Timeout to acquire the first time-correction estimate (default: no timeout). 971 | * @return The time correction estimate. This is the number that needs to be added to a time 972 | * stamp that was remotely generated via lsl_local_clock() to map it into the local clock 973 | * domain of this machine. 974 | * @throws #lsl::timeout_error (if the timeout expires), or #lsl::lost_error (if the stream 975 | * source has been lost). 976 | */ 977 | 978 | double time_correction(double timeout = FOREVER) { 979 | int32_t ec = 0; 980 | double res = lsl_time_correction(obj.get(), timeout, &ec); 981 | check_error(ec); 982 | return res; 983 | } 984 | /** @copydoc time_correction(double) 985 | * @param remote_time The current time of the remote computer that was used to generate this 986 | * time_correction. If desired, the client can fit time_correction vs remote_time to improve 987 | * the real-time time_correction further. 988 | * @param uncertainty The maximum uncertainty of the given time correction. 989 | */ 990 | double time_correction(double *remote_time, double *uncertainty, double timeout = FOREVER) { 991 | int32_t ec = 0; 992 | double res = lsl_time_correction_ex(obj.get(), remote_time, uncertainty, timeout, &ec); 993 | check_error(ec); 994 | return res; 995 | } 996 | 997 | /** Set post-processing flags to use. 998 | * 999 | * By default, the inlet performs NO post-processing and returns the ground-truth time 1000 | * stamps, which can then be manually synchronized using .time_correction(), and then 1001 | * smoothed/dejittered if desired.
1002 | * This function allows automating these two and possibly more operations.
1003 | * @warning When you enable this, you will no longer receive or be able to recover the original 1004 | * time stamps. 1005 | * @param flags An integer that is the result of bitwise OR'ing one or more options from 1006 | * processing_options_t together (e.g., `post_clocksync|post_dejitter`); the default is to 1007 | * enable all options. 1008 | */ 1009 | void set_postprocessing(uint32_t flags = post_ALL) { 1010 | check_error(lsl_set_postprocessing(obj.get(), flags)); 1011 | } 1012 | 1013 | // ======================================= 1014 | // === Pulling a sample from the inlet === 1015 | // ======================================= 1016 | 1017 | /** Pull a sample from the inlet and read it into an array of values. 1018 | * Handles type checking & conversion. 1019 | * @param sample An array to hold the resulting values. 1020 | * @param timeout The timeout for this operation, if any. Use 0.0 to make the function 1021 | * non-blocking. 1022 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 1023 | * available. To remap this time stamp to the local clock, add the value returned by 1024 | * .time_correction() to it. 1025 | * @throws lost_error (if the stream source has been lost). 1026 | */ 1027 | template double pull_sample(T sample[N], double timeout = FOREVER) { 1028 | return pull_sample(&sample[0], N, timeout); 1029 | } 1030 | 1031 | /** Pull a sample from the inlet and read it into a std vector of values. 1032 | * Handles type checking & conversion and allocates the necessary memory in the vector if 1033 | * necessary. 1034 | * @param sample An STL vector to hold the resulting values. 1035 | * @param timeout The timeout for this operation, if any. Use 0.0 to make the function 1036 | * non-blocking. 1037 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 1038 | * available. To remap this time stamp to the local clock, add the value returned by 1039 | * .time_correction() to it. 1040 | * @throws lost_error (if the stream source has been lost). 1041 | */ 1042 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1043 | sample.resize(channel_count); 1044 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1045 | } 1046 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1047 | sample.resize(channel_count); 1048 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1049 | } 1050 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1051 | sample.resize(channel_count); 1052 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1053 | } 1054 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1055 | sample.resize(channel_count); 1056 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1057 | } 1058 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1059 | sample.resize(channel_count); 1060 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1061 | } 1062 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1063 | sample.resize(channel_count); 1064 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1065 | } 1066 | double pull_sample(std::vector &sample, double timeout = FOREVER) { 1067 | sample.resize(channel_count); 1068 | return pull_sample(&sample[0], (int32_t)sample.size(), timeout); 1069 | } 1070 | 1071 | /** Pull a sample from the inlet and read it into a pointer to values. 1072 | * Handles type checking & conversion. 1073 | * @param buffer A pointer to hold the resulting values. 1074 | * @param buffer_elements The number of samples allocated in the buffer. Note: it is the 1075 | * responsibility of the user to allocate enough memory. 1076 | * @param timeout The timeout for this operation, if any. Use 0.0 to make the function 1077 | * non-blocking. 1078 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 1079 | * available. To remap this time stamp to the local clock, add the value returned by 1080 | * .time_correction() to it. 1081 | * @throws lost_error (if the stream source has been lost). 1082 | */ 1083 | double pull_sample(float *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1084 | int32_t ec = 0; 1085 | double res = lsl_pull_sample_f(obj.get(), buffer, buffer_elements, timeout, &ec); 1086 | check_error(ec); 1087 | return res; 1088 | } 1089 | double pull_sample(double *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1090 | int32_t ec = 0; 1091 | double res = lsl_pull_sample_d(obj.get(), buffer, buffer_elements, timeout, &ec); 1092 | check_error(ec); 1093 | return res; 1094 | } 1095 | double pull_sample(int64_t *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1096 | int32_t ec = 0; 1097 | double res = lsl_pull_sample_l(obj.get(), buffer, buffer_elements, timeout, &ec); 1098 | check_error(ec); 1099 | return res; 1100 | } 1101 | double pull_sample(int32_t *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1102 | int32_t ec = 0; 1103 | double res = lsl_pull_sample_i(obj.get(), buffer, buffer_elements, timeout, &ec); 1104 | check_error(ec); 1105 | return res; 1106 | } 1107 | double pull_sample(int16_t *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1108 | int32_t ec = 0; 1109 | double res = lsl_pull_sample_s(obj.get(), buffer, buffer_elements, timeout, &ec); 1110 | check_error(ec); 1111 | return res; 1112 | } 1113 | double pull_sample(char *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1114 | int32_t ec = 0; 1115 | double res = lsl_pull_sample_c(obj.get(), buffer, buffer_elements, timeout, &ec); 1116 | check_error(ec); 1117 | return res; 1118 | } 1119 | double pull_sample(std::string *buffer, int32_t buffer_elements, double timeout = FOREVER) { 1120 | int32_t ec = 0; 1121 | if (buffer_elements) { 1122 | std::vector result_strings(buffer_elements); 1123 | std::vector result_lengths(buffer_elements); 1124 | double res = lsl_pull_sample_buf( 1125 | obj.get(), result_strings.data(), result_lengths.data(), buffer_elements, timeout, &ec); 1126 | check_error(ec); 1127 | for (int32_t k = 0; k < buffer_elements; k++) { 1128 | buffer[k].assign(result_strings[k], result_lengths[k]); 1129 | lsl_destroy_string(result_strings[k]); 1130 | } 1131 | return res; 1132 | } else 1133 | throw std::runtime_error( 1134 | "Provided element count does not match the stream's channel count."); 1135 | } 1136 | 1137 | /** 1138 | * Pull a sample from the inlet and read it into a custom C-style struct. 1139 | * 1140 | * Overall size checking but no type checking or conversion are done. 1141 | * Do not use for variable-size/string-formatted streams. 1142 | * @param sample The raw sample object to hold the data (packed C-style struct). 1143 | * Search for [`#``pragma pack`](https://stackoverflow.com/a/3318475/73299) for information 1144 | * on how to pack structs correctly. 1145 | * @param timeout The timeout for this operation, if any. Use 0.0 to make the function 1146 | * non-blocking. 1147 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 1148 | * available. To remap this time stamp to the local clock, add the value returned by 1149 | * .time_correction() to it. 1150 | * @throws lost_error (if the stream source has been lost). 1151 | */ 1152 | template double pull_numeric_struct(T &sample, double timeout = FOREVER) { 1153 | return pull_numeric_raw((void *)&sample, sizeof(T), timeout); 1154 | } 1155 | 1156 | /** 1157 | * Pull a sample from the inlet and read it into a pointer to raw data. 1158 | * 1159 | * No type checking or conversions are done (not recommended!).
1160 | * Do not use for variable-size/string-formatted streams. 1161 | * @param sample A pointer to hold the resulting raw sample data. 1162 | * @param buffer_bytes The number of bytes allocated in the buffer.
1163 | * Note: it is the responsibility of the user to allocate enough memory. 1164 | * @param timeout The timeout for this operation, if any. Use 0.0 to make the function 1165 | * non-blocking. 1166 | * @return The capture time of the sample on the remote machine, or 0.0 if no new sample was 1167 | * available. To remap this time stamp to the local clock, add the value returned by 1168 | * .time_correction() to it. 1169 | * @throws lost_error (if the stream source has been lost). 1170 | */ 1171 | double pull_numeric_raw(void *sample, int32_t buffer_bytes, double timeout = FOREVER) { 1172 | int32_t ec = 0; 1173 | double res = lsl_pull_sample_v(obj.get(), sample, buffer_bytes, timeout, &ec); 1174 | check_error(ec); 1175 | return res; 1176 | } 1177 | 1178 | 1179 | // ================================================= 1180 | // === Pulling a chunk of samples from the inlet === 1181 | // ================================================= 1182 | 1183 | /** 1184 | * Pull a chunk of samples from the inlet. 1185 | * 1186 | * This is the most complete version, returning both the data and a timestamp for each sample. 1187 | * @param chunk A vector of vectors to hold the samples. 1188 | * @param timestamps A vector to hold the time stamps. 1189 | * @return True if some data was obtained. 1190 | * @throws lost_error (if the stream source has been lost). 1191 | */ 1192 | template 1193 | bool pull_chunk(std::vector> &chunk, std::vector ×tamps) { 1194 | std::vector sample; 1195 | chunk.clear(); 1196 | timestamps.clear(); 1197 | while (double ts = pull_sample(sample, 0.0)) { 1198 | chunk.push_back(sample); 1199 | timestamps.push_back(ts); 1200 | } 1201 | return !chunk.empty(); 1202 | } 1203 | 1204 | /** 1205 | * Pull a chunk of samples from the inlet. 1206 | * 1207 | * This version returns only the most recent sample's time stamp. 1208 | * @param chunk A vector of vectors to hold the samples. 1209 | * @return The time when the most recent sample was captured 1210 | * on the remote machine, or 0.0 if no new sample was available. 1211 | * @throws lost_error (if the stream source has been lost) 1212 | */ 1213 | template double pull_chunk(std::vector> &chunk) { 1214 | double timestamp = 0.0; 1215 | std::vector sample; 1216 | chunk.clear(); 1217 | while (double ts = pull_sample(sample, 0.0)) { 1218 | chunk.push_back(sample); 1219 | timestamp = ts; 1220 | } 1221 | return timestamp; 1222 | } 1223 | 1224 | /** 1225 | * Pull a chunk of samples from the inlet. 1226 | * 1227 | * This function does not return time stamps for the samples. Invoked as: mychunk = 1228 | * pull_chunk(); 1229 | * @return A vector of vectors containing the obtained samples; may be empty. 1230 | * @throws lost_error (if the stream source has been lost) 1231 | */ 1232 | template std::vector> pull_chunk() { 1233 | std::vector> result; 1234 | std::vector sample; 1235 | while (pull_sample(sample, 0.0)) result.push_back(sample); 1236 | return result; 1237 | } 1238 | 1239 | /** 1240 | * Pull a chunk of data from the inlet into a pre-allocated buffer. 1241 | * 1242 | * This is a high-performance function that performs no memory allocations 1243 | * (useful for very high data rates or on low-powered devices). 1244 | * @warning The provided buffer size is measured in channel values (e.g., floats), not samples. 1245 | * @param data_buffer A pointer to a buffer of data values where the results shall be stored. 1246 | * @param timestamp_buffer A pointer to a buffer of timestamp values where time stamps shall be 1247 | * stored. If this is NULL, no time stamps will be returned. 1248 | * @param data_buffer_elements The size of the data buffer, in channel data elements (of type 1249 | * T). Must be a multiple of the stream's channel count. 1250 | * @param timestamp_buffer_elements The size of the timestamp buffer. If a timestamp buffer is 1251 | * provided then this must correspond to the same number of samples as data_buffer_elements. 1252 | * @param timeout The timeout for this operation, if any. When the timeout expires, the function 1253 | * may return before the entire buffer is filled. The default value of 0.0 will retrieve only 1254 | * data available for immediate pickup. 1255 | * @return data_elements_written Number of channel data elements written to the data buffer. 1256 | * @throws lost_error (if the stream source has been lost). 1257 | */ 1258 | std::size_t pull_chunk_multiplexed(float *data_buffer, double *timestamp_buffer, 1259 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1260 | double timeout = 0.0) { 1261 | int32_t ec = 0; 1262 | std::size_t res = lsl_pull_chunk_f(obj.get(), data_buffer, timestamp_buffer, 1263 | (unsigned long)data_buffer_elements, (unsigned long)timestamp_buffer_elements, timeout, 1264 | &ec); 1265 | check_error(ec); 1266 | return res; 1267 | } 1268 | std::size_t pull_chunk_multiplexed(double *data_buffer, double *timestamp_buffer, 1269 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1270 | double timeout = 0.0) { 1271 | int32_t ec = 0; 1272 | std::size_t res = lsl_pull_chunk_d(obj.get(), data_buffer, timestamp_buffer, 1273 | (unsigned long)data_buffer_elements, (unsigned long)timestamp_buffer_elements, timeout, 1274 | &ec); 1275 | check_error(ec); 1276 | return res; 1277 | } 1278 | std::size_t pull_chunk_multiplexed(int64_t *data_buffer, double *timestamp_buffer, 1279 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1280 | double timeout = 0.0) { 1281 | int32_t ec = 0; 1282 | std::size_t res = lsl_pull_chunk_l(obj.get(), data_buffer, timestamp_buffer, 1283 | (unsigned long)data_buffer_elements, (unsigned long)timestamp_buffer_elements, timeout, 1284 | &ec); 1285 | check_error(ec); 1286 | return res; 1287 | } 1288 | std::size_t pull_chunk_multiplexed(int32_t *data_buffer, double *timestamp_buffer, 1289 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1290 | double timeout = 0.0) { 1291 | int32_t ec = 0; 1292 | std::size_t res = lsl_pull_chunk_i(obj.get(), data_buffer, timestamp_buffer, 1293 | (unsigned long)data_buffer_elements, (unsigned long)timestamp_buffer_elements, timeout, 1294 | &ec); 1295 | check_error(ec); 1296 | return res; 1297 | } 1298 | std::size_t pull_chunk_multiplexed(int16_t *data_buffer, double *timestamp_buffer, 1299 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1300 | double timeout = 0.0) { 1301 | int32_t ec = 0; 1302 | std::size_t res = lsl_pull_chunk_s(obj.get(), data_buffer, timestamp_buffer, 1303 | (unsigned long)data_buffer_elements, (unsigned long)timestamp_buffer_elements, timeout, 1304 | &ec); 1305 | check_error(ec); 1306 | return res; 1307 | } 1308 | std::size_t pull_chunk_multiplexed(char *data_buffer, double *timestamp_buffer, 1309 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1310 | double timeout = 0.0) { 1311 | int32_t ec = 0; 1312 | std::size_t res = lsl_pull_chunk_c(obj.get(), data_buffer, timestamp_buffer, 1313 | static_cast(data_buffer_elements), static_cast(timestamp_buffer_elements), timeout, 1314 | &ec); 1315 | check_error(ec); 1316 | return res; 1317 | } 1318 | std::size_t pull_chunk_multiplexed(std::string *data_buffer, double *timestamp_buffer, 1319 | std::size_t data_buffer_elements, std::size_t timestamp_buffer_elements, 1320 | double timeout = 0.0) { 1321 | int32_t ec = 0; 1322 | if (data_buffer_elements) { 1323 | std::vector result_strings(data_buffer_elements); 1324 | std::vector result_lengths(data_buffer_elements); 1325 | std::size_t num = lsl_pull_chunk_buf(obj.get(), result_strings.data(), result_lengths.data(), 1326 | timestamp_buffer, static_cast(data_buffer_elements), 1327 | static_cast(timestamp_buffer_elements), timeout, &ec); 1328 | check_error(ec); 1329 | for (std::size_t k = 0; k < num; k++) { 1330 | data_buffer[k].assign(result_strings[k], result_lengths[k]); 1331 | lsl_destroy_string(result_strings[k]); 1332 | } 1333 | return num; 1334 | }; 1335 | return 0; 1336 | } 1337 | 1338 | /** 1339 | * Pull a multiplexed chunk of samples and optionally the sample timestamps from the inlet. 1340 | * 1341 | * @param chunk A vector to hold the multiplexed (Sample 1 Channel 1, 1342 | * S1C2, S2C1, S2C2, S3C1, S3C2, ...) samples 1343 | * @param timestamps A vector to hold the timestamps or nullptr 1344 | * @param timeout Time to wait for the first sample. The default value of 0.0 will not wait 1345 | * for data to arrive, pulling only samples already received. 1346 | * @param append (True:) Append data or (false:) clear them first 1347 | * @return True if some data was obtained. 1348 | * @throws lost_error (if the stream source has been lost). 1349 | */ 1350 | template 1351 | bool pull_chunk_multiplexed(std::vector &chunk, std::vector *timestamps = nullptr, 1352 | double timeout = 0.0, bool append = false) { 1353 | if (!append) { 1354 | chunk.clear(); 1355 | if (timestamps) timestamps->clear(); 1356 | } 1357 | std::vector sample; 1358 | double ts; 1359 | if ((ts = pull_sample(sample, timeout)) == 0.0) return false; 1360 | chunk.insert(chunk.end(), sample.begin(), sample.end()); 1361 | if (timestamps) timestamps->push_back(ts); 1362 | const auto target = samples_available(); 1363 | chunk.reserve(chunk.size() + target * this->channel_count); 1364 | if (timestamps) timestamps->reserve(timestamps->size() + target); 1365 | while ((ts = pull_sample(sample, 0.0)) != 0.0) { 1366 | #if LSL_CPP11 1367 | chunk.insert(chunk.end(), std::make_move_iterator(sample.begin()), 1368 | std::make_move_iterator(sample.end())); 1369 | #else 1370 | chunk.insert(chunk.end(), sample.begin(), sample.end()); 1371 | #endif 1372 | if (timestamps) timestamps->push_back(ts); 1373 | } 1374 | return true; 1375 | } 1376 | 1377 | /** 1378 | * Pull a chunk of samples from the inlet. 1379 | * 1380 | * This is the most complete version, returning both the data and a timestamp for each sample. 1381 | * @param chunk A vector of C-style structs to hold the samples. 1382 | * @param timestamps A vector to hold the time stamps. 1383 | * @return True if some data was obtained. 1384 | * @throws lost_error (if the stream source has been lost) 1385 | */ 1386 | template 1387 | bool pull_chunk_numeric_structs(std::vector &chunk, std::vector ×tamps) { 1388 | T sample; 1389 | chunk.clear(); 1390 | timestamps.clear(); 1391 | while (double ts = pull_numeric_struct(sample, 0.0)) { 1392 | chunk.push_back(sample); 1393 | timestamps.push_back(ts); 1394 | } 1395 | return !chunk.empty(); 1396 | } 1397 | 1398 | /** 1399 | * Pull a chunk of samples from the inlet. 1400 | * 1401 | * This version returns only the most recent sample's time stamp. 1402 | * @param chunk A vector of C-style structs to hold the samples. 1403 | * @return The time when the most recent sample was captured 1404 | * on the remote machine, or 0.0 if no new sample was available. 1405 | * @throws lost_error (if the stream source has been lost) 1406 | */ 1407 | template double pull_chunk_numeric_structs(std::vector &chunk) { 1408 | double timestamp = 0.0; 1409 | T sample; 1410 | chunk.clear(); 1411 | while (double ts = pull_numeric_struct(sample, 0.0)) { 1412 | chunk.push_back(sample); 1413 | timestamp = ts; 1414 | } 1415 | return timestamp; 1416 | } 1417 | 1418 | /** 1419 | * Pull a chunk of samples from the inlet. 1420 | * 1421 | * This function does not return time stamps. Invoked as: mychunk = pull_chunk(); 1422 | * @return A vector of C-style structs containing the obtained samples; may be empty. 1423 | * @throws lost_error (if the stream source has been lost) 1424 | */ 1425 | template std::vector pull_chunk_numeric_structs() { 1426 | std::vector result; 1427 | T sample; 1428 | while (pull_numeric_struct(sample, 0.0)) result.push_back(sample); 1429 | return result; 1430 | } 1431 | 1432 | /** 1433 | * Query whether samples are currently available for immediate pickup. 1434 | * 1435 | * Note that it is not a good idea to use samples_available() to determine whether 1436 | * a pull_*() call would block: to be sure, set the pull timeout to 0.0 or an acceptably 1437 | * low value. If the underlying implementation supports it, the value will be the number of 1438 | * samples available (otherwise it will be 1 or 0). 1439 | */ 1440 | std::size_t samples_available() { return lsl_samples_available(obj.get()); } 1441 | 1442 | /// Drop all queued not-yet pulled samples, return the nr of dropped samples 1443 | uint32_t flush() noexcept { return lsl_inlet_flush(obj.get()); } 1444 | 1445 | /** 1446 | * Query whether the clock was potentially reset since the last call to was_clock_reset(). 1447 | * 1448 | * This is a rarely-used function that is only useful to applications that combine multiple 1449 | * time_correction values to estimate precise clock drift; it allows to tolerate cases where the 1450 | * source machine was hot-swapped or restarted in between two measurements. 1451 | */ 1452 | bool was_clock_reset() { return lsl_was_clock_reset(obj.get()) != 0; } 1453 | 1454 | /** 1455 | * Override the half-time (forget factor) of the time-stamp smoothing. 1456 | * 1457 | * The default is 90 seconds unless a different value is set in the config file. 1458 | * Using a longer window will yield lower jitter in the time stamps, but longer 1459 | * windows will have trouble tracking changes in the clock rate (usually due to 1460 | * temperature changes); the default is able to track changes up to 10 1461 | * degrees C per minute sufficiently well. 1462 | */ 1463 | void smoothing_halftime(float value) { check_error(lsl_smoothing_halftime(obj.get(), value)); } 1464 | 1465 | int get_channel_count() const { return channel_count; } 1466 | 1467 | private: 1468 | // The inlet is a non-copyable object. 1469 | stream_inlet(const stream_inlet &rhs); 1470 | stream_inlet &operator=(const stream_inlet &rhs); 1471 | 1472 | int32_t channel_count; 1473 | std::shared_ptr obj; 1474 | }; 1475 | 1476 | 1477 | // ===================== 1478 | // ==== XML Element ==== 1479 | // ===================== 1480 | 1481 | /** 1482 | * A lightweight XML element tree; models the .desc() field of stream_info. 1483 | * 1484 | * Has a name and can have multiple named children or have text content as value; attributes are 1485 | * omitted. Insider note: The interface is modeled after a subset of pugixml's node type and is 1486 | * compatible with it. See also 1487 | * http://pugixml.googlecode.com/svn/tags/latest/docs/manual/access.html for additional 1488 | * documentation. 1489 | */ 1490 | class xml_element { 1491 | public: 1492 | /// Constructor. 1493 | xml_element(lsl_xml_ptr obj = 0) : obj(obj) {} 1494 | 1495 | 1496 | // === Tree Navigation === 1497 | 1498 | /// Get the first child of the element. 1499 | xml_element first_child() const { return lsl_first_child(obj); } 1500 | 1501 | /// Get the last child of the element. 1502 | xml_element last_child() const { return lsl_last_child(obj); } 1503 | 1504 | /// Get the next sibling in the children list of the parent node. 1505 | xml_element next_sibling() const { return lsl_next_sibling(obj); } 1506 | 1507 | /// Get the previous sibling in the children list of the parent node. 1508 | xml_element previous_sibling() const { return lsl_previous_sibling(obj); } 1509 | 1510 | /// Get the parent node. 1511 | xml_element parent() const { return lsl_parent(obj); } 1512 | 1513 | 1514 | // === Tree Navigation by Name === 1515 | 1516 | /// Get a child with a specified name. 1517 | xml_element child(const std::string &name) const { return lsl_child(obj, (name.c_str())); } 1518 | 1519 | /// Get the next sibling with the specified name. 1520 | xml_element next_sibling(const std::string &name) const { 1521 | return lsl_next_sibling_n(obj, (name.c_str())); 1522 | } 1523 | 1524 | /// Get the previous sibling with the specified name. 1525 | xml_element previous_sibling(const std::string &name) const { 1526 | return lsl_previous_sibling_n(obj, (name.c_str())); 1527 | } 1528 | 1529 | 1530 | // === Content Queries === 1531 | 1532 | /// Whether this node is empty. 1533 | bool empty() const { return lsl_empty(obj) != 0; } 1534 | 1535 | /// Is this a text body (instead of an XML element)? True both for plain char data and CData. 1536 | bool is_text() const { return lsl_is_text(obj) != 0; } 1537 | 1538 | /// Name of the element. 1539 | const char *name() const { return lsl_name(obj); } 1540 | 1541 | /// Value of the element. 1542 | const char *value() const { return lsl_value(obj); } 1543 | 1544 | /// Get child value (value of the first child that is text). 1545 | const char *child_value() const { return lsl_child_value(obj); } 1546 | 1547 | /// Get child value of a child with a specified name. 1548 | const char *child_value(const std::string &name) const { 1549 | return lsl_child_value_n(obj, (name.c_str())); 1550 | } 1551 | 1552 | 1553 | // === Modification === 1554 | 1555 | /// Append a child node with a given name, which has a (nameless) plain-text child with the 1556 | /// given text value. 1557 | xml_element append_child_value(const std::string &name, const std::string &value) { 1558 | return lsl_append_child_value(obj, (name.c_str()), (value.c_str())); 1559 | } 1560 | 1561 | /// Prepend a child node with a given name, which has a (nameless) plain-text child with the 1562 | /// given text value. 1563 | xml_element prepend_child_value(const std::string &name, const std::string &value) { 1564 | return lsl_prepend_child_value(obj, (name.c_str()), (value.c_str())); 1565 | } 1566 | 1567 | /// Set the text value of the (nameless) plain-text child of a named child node. 1568 | bool set_child_value(const std::string &name, const std::string &value) { 1569 | return lsl_set_child_value(obj, (name.c_str()), (value.c_str())) != 0; 1570 | } 1571 | 1572 | /** 1573 | * Set the element's name. 1574 | * @return False if the node is empty (or if out of memory). 1575 | */ 1576 | bool set_name(const std::string &rhs) { return lsl_set_name(obj, rhs.c_str()) != 0; } 1577 | 1578 | /** 1579 | * Set the element's value. 1580 | * @return False if the node is empty (or if out of memory). 1581 | */ 1582 | bool set_value(const std::string &rhs) { return lsl_set_value(obj, rhs.c_str()) != 0; } 1583 | 1584 | /// Append a child element with the specified name. 1585 | xml_element append_child(const std::string &name) { 1586 | return lsl_append_child(obj, name.c_str()); 1587 | } 1588 | 1589 | /// Prepend a child element with the specified name. 1590 | xml_element prepend_child(const std::string &name) { 1591 | return lsl_prepend_child(obj, (name.c_str())); 1592 | } 1593 | 1594 | /// Append a copy of the specified element as a child. 1595 | xml_element append_copy(const xml_element &e) { return lsl_append_copy(obj, e.obj); } 1596 | 1597 | /// Prepend a child element with the specified name. 1598 | xml_element prepend_copy(const xml_element &e) { return lsl_prepend_copy(obj, e.obj); } 1599 | 1600 | /// Remove a child element with the specified name. 1601 | void remove_child(const std::string &name) { lsl_remove_child_n(obj, (name.c_str())); } 1602 | 1603 | /// Remove a specified child element. 1604 | void remove_child(const xml_element &e) { lsl_remove_child(obj, e.obj); } 1605 | 1606 | private: 1607 | lsl_xml_ptr obj; 1608 | }; 1609 | 1610 | inline xml_element stream_info::desc() { return lsl_get_desc(obj.get()); } 1611 | 1612 | 1613 | // ============================= 1614 | // ==== Continuous Resolver ==== 1615 | // ============================= 1616 | 1617 | /** 1618 | * A convenience class that resolves streams continuously in the background throughout 1619 | * its lifetime and which can be queried at any time for the set of streams that are currently 1620 | * visible on the network. 1621 | */ 1622 | class continuous_resolver { 1623 | public: 1624 | /** 1625 | * Construct a new continuous_resolver that resolves all streams on the network. 1626 | * 1627 | * This is analogous to the functionality offered by the free function resolve_streams(). 1628 | * @param forget_after When a stream is no longer visible on the network (e.g., because it was 1629 | * shut down), this is the time in seconds after which it is no longer reported by the resolver. 1630 | */ 1631 | continuous_resolver(double forget_after = 5.0) 1632 | : obj(lsl_create_continuous_resolver(forget_after), &lsl_destroy_continuous_resolver) {} 1633 | 1634 | /** 1635 | * Construct a new continuous_resolver that resolves all streams with a specific value for a 1636 | * given property. 1637 | * 1638 | * This is analogous to the functionality provided by the free function resolve_stream(prop,value). 1639 | * @param prop The stream_info property that should have a specific value (e.g., "name", "type", 1640 | * "source_id", or "desc/manufaturer"). 1641 | * @param value The string value that the property should have (e.g., "EEG" as the type 1642 | * property). 1643 | * @param forget_after When a stream is no longer visible on the network (e.g., because it was 1644 | * shut down), this is the time in seconds after which it is no longer reported by the resolver. 1645 | */ 1646 | continuous_resolver( 1647 | const std::string &prop, const std::string &value, double forget_after = 5.0) 1648 | : obj(lsl_create_continuous_resolver_byprop((prop.c_str()), (value.c_str()), forget_after), 1649 | &lsl_destroy_continuous_resolver) {} 1650 | 1651 | /** 1652 | * Construct a new continuous_resolver that resolves all streams that match a given XPath 1.0 1653 | * predicate. 1654 | * 1655 | * This is analogous to the functionality provided by the free function resolve_stream(pred). 1656 | * @param pred The predicate string, e.g. 1657 | * `name='BioSemi'` or 1658 | * `type='EEG' and starts-with(name,'BioSemi') and count(info/desc/channel)=32` 1659 | * @param forget_after When a stream is no longer visible on the network (e.g., because it was 1660 | * shut down), this is the time in seconds after which it is no longer reported by the resolver. 1661 | */ 1662 | continuous_resolver(const std::string &pred, double forget_after = 5.0) 1663 | : obj(lsl_create_continuous_resolver_bypred((pred.c_str()), forget_after), &lsl_destroy_continuous_resolver) {} 1664 | 1665 | /** 1666 | * Obtain the set of currently present streams on the network (i.e. resolve result). 1667 | * @return A vector of matching stream info objects (excluding their meta-data), any of 1668 | * which can subsequently be used to open an inlet. 1669 | */ 1670 | std::vector results() { 1671 | lsl_streaminfo buffer[1024]; 1672 | return std::vector( 1673 | buffer, buffer + check_error(lsl_resolver_results(obj.get(), buffer, sizeof(buffer)))); 1674 | } 1675 | 1676 | /// Move constructor for stream_inlet 1677 | continuous_resolver(continuous_resolver &&rhs) noexcept = default; 1678 | continuous_resolver &operator=(continuous_resolver &&rhs) noexcept = default; 1679 | 1680 | private: 1681 | std::unique_ptr obj; 1682 | }; 1683 | 1684 | 1685 | // =============================== 1686 | // ==== Exception Definitions ==== 1687 | // =============================== 1688 | 1689 | /// Exception class that indicates that a stream inlet's source has been irrecoverably lost. 1690 | class lost_error : public std::runtime_error { 1691 | public: 1692 | explicit lost_error(const std::string &msg) : std::runtime_error(msg) {} 1693 | }; 1694 | 1695 | 1696 | /// Exception class that indicates that an operation failed due to a timeout. 1697 | class timeout_error : public std::runtime_error { 1698 | public: 1699 | explicit timeout_error(const std::string &msg) : std::runtime_error(msg) {} 1700 | }; 1701 | 1702 | /// Check error codes returned from the C interface and translate into appropriate exceptions. 1703 | inline int32_t check_error(int32_t ec) { 1704 | if (ec < 0) { 1705 | switch (ec) { 1706 | case lsl_timeout_error: throw timeout_error("The operation has timed out."); 1707 | case lsl_lost_error: 1708 | throw timeout_error( 1709 | "The stream has been lost; to continue reading, you need to re-resolve it."); 1710 | case lsl_argument_error: 1711 | throw std::invalid_argument("An argument was incorrectly specified."); 1712 | case lsl_internal_error: throw std::runtime_error("An internal error has occurred."); 1713 | default: throw std::runtime_error("An unknown error has occurred."); 1714 | } 1715 | } 1716 | return ec; 1717 | } 1718 | 1719 | } // namespace lsl 1720 | 1721 | #endif // LSL_CPP_H 1722 | -------------------------------------------------------------------------------- /Source/ThirdParty/liblsl/lib/lsl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labstreaminglayer/plugin-UE4/9a3efec9b0d1654911d321504144bf309d1d1919/Source/ThirdParty/liblsl/lib/lsl.lib -------------------------------------------------------------------------------- /Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | SET(LSL_BINDIR) 4 | SET(LSL_LIBRARY) 5 | IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 6 | IF(${CMAKE_C_SIZEOF_DATA_PTR} EQUAL 8) 7 | SET(LSL_BINDIR ${CMAKE_CURRENT_LIST_DIR}/../Binaries/Win64) 8 | SET(LSL_LIBRARY 9 | optimized "${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/liblsl/bin/liblsl64.lib" 10 | debug "${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/liblsl/bin/liblsl64-debug.lib") 11 | ELSE() 12 | SET(LSL_BINDIR ${CMAKE_CURRENT_LIST_DIR}/../Binaries/Win32) 13 | SET(LSL_LIBRARY 14 | optimized "${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/liblsl/bin/liblsl32.lib" 15 | debug "${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/liblsl/bin/liblsl32-debug.lib") 16 | ENDIF() 17 | ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 18 | SET(LSL_BINDIR ${CMAKE_CURRENT_LIST_DIR}/../Binaries/Mac) 19 | SET(LSL_LIBRARY 20 | optimized "${LSL_BINDIR}/liblsl64.dylib" 21 | debug "${LSL_BINDIR}/liblsl64-debug.dylib") 22 | ENDIF() 23 | SET(LSL_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/liblsl/include) 24 | 25 | # 26 | # TEST OUTLET 27 | # 28 | add_executable(test_outlet ${CMAKE_CURRENT_LIST_DIR}/test_outlet.cpp) 29 | target_include_directories(test_outlet PRIVATE ${LSL_INCLUDE_DIR}) 30 | target_link_libraries(test_outlet ${LSL_LIBRARY}) 31 | 32 | # 33 | # TEST INLET 34 | # 35 | add_executable(test_inlet ${CMAKE_CURRENT_LIST_DIR}/test_inlet.cpp) 36 | target_include_directories(test_inlet PRIVATE ${LSL_INCLUDE_DIR}) 37 | target_link_libraries(test_inlet ${LSL_LIBRARY}) 38 | -------------------------------------------------------------------------------- /Tests/SimpleControlSignalOutlet.py: -------------------------------------------------------------------------------- 1 | import __init__ 2 | import numpy as np 3 | import time 4 | from pylsl import StreamInfo, StreamOutlet, local_clock 5 | 6 | # ============================================== 7 | # ============ Constants ======================= 8 | # ============================================== 9 | Fs = 32 # Sampling rate. 32 control updates per second 10 | channels = ["Control1"] 11 | sine_freq = 0.5 # Frequency of control signal modulation 12 | outlet_name = "SineWaveControl" 13 | outlet_type = "Control" 14 | 15 | # ============================================== 16 | # =========== Create LSL Outlets =============== 17 | # ============================================== 18 | 19 | # Create a stream of fake 'raw' data with varying PAC values 20 | control_info = StreamInfo(name=outlet_name, type=outlet_type, 21 | channel_count=len(channels), nominal_srate=Fs, 22 | channel_format='float32', 23 | source_id='sinewavgen1234') 24 | control_xml = control_info.desc() 25 | chans = control_xml.append_child("channels") 26 | for channame in channels: 27 | chn = chans.append_child("channel") 28 | chn.append_child_value("label", channame) 29 | chn.append_child_value("unit", "SDU") 30 | chn.append_child_value("type", "generated") 31 | control_outlet = StreamOutlet(control_info) 32 | print("Created outlet with name {} and type {}".format(outlet_name, outlet_type)) 33 | 34 | start_time = local_clock() # Time of the 0th chunk 35 | print("now sending data...") 36 | try: 37 | last_time = start_time 38 | while True: 39 | if (local_clock() - last_time) < 1.0/Fs: 40 | time.sleep(0.001) 41 | last_time = local_clock() 42 | y = np.sin(2*np.pi*sine_freq*last_time) 43 | control_outlet.push_sample([y]) 44 | 45 | except KeyboardInterrupt: 46 | # No cleanup necessary? 47 | pass 48 | -------------------------------------------------------------------------------- /Tests/test_inlet.cpp: -------------------------------------------------------------------------------- 1 | #include "lsl_cpp.h" 2 | #include 3 | 4 | int main(int argc, char* argv[]) { 5 | 6 | // resolve the stream of interest & make an inlet to get data from the first result 7 | std::cout << "Searching for stream type Markers ..." << std::endl; 8 | std::vector results = lsl::resolve_stream("type","Markers"); 9 | std::cout << "Found:" << std::endl; 10 | std::cout << results[0].as_xml() << std::endl; 11 | 12 | lsl::stream_inlet inlet(results[0]); 13 | lsl::stream_info info = inlet.info(); 14 | std::cout << "Creating inlet for stream " << info.name() << " of type " << info.type() << std::endl; 15 | 16 | // receive data & time stamps forever (not displaying them here) 17 | double ts; 18 | while (true) 19 | { 20 | std::string sample; 21 | ts = inlet.pull_sample(&sample, 1); 22 | std::cout << ts << "\t" << sample << std::endl; 23 | } 24 | 25 | 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Tests/test_outlet.cpp: -------------------------------------------------------------------------------- 1 | #include "lsl_cpp.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define NCHANNELS 1 9 | const char *channels[] = { "CONTROL1" }; 10 | #define pi 3.14159 11 | 12 | double g_sine_freq = 0.5; 13 | double g_push_freq = 16; 14 | 15 | int main(int argc, char* argv[]) { 16 | std::string name = "SimpleOutlet"; 17 | std::string type = "Control"; 18 | auto start_time = std::chrono::high_resolution_clock::now(); 19 | 20 | try { 21 | lsl::stream_info outlet_info(name, type, NCHANNELS, g_push_freq, lsl::cf_double64, std::string(name) += type); 22 | // add some description fields 23 | lsl::xml_element info_xml = outlet_info.desc(); 24 | lsl::xml_element channels_xml = outlet_info.desc().append_child("channels"); 25 | for (int k = 0; k < NCHANNELS; k++) 26 | { 27 | lsl::xml_element chn = channels_xml.append_child("channel"); 28 | chn.append_child_value("label", channels[k]) 29 | .append_child_value("unit", "SDU") 30 | .append_child_value("type", "Generated"); 31 | } 32 | // make a new outlet 33 | lsl::stream_outlet outlet(outlet_info); 34 | 35 | // send data forever 36 | std::cout << "Now sending data... " << std::endl; 37 | double push_counter = 0.0; 38 | while(true) { 39 | std::chrono::duration elapsed = std::chrono::high_resolution_clock::now() - start_time; 40 | double elapsed_seconds = elapsed.count(); 41 | if (elapsed_seconds > (push_counter / g_push_freq)) 42 | { 43 | double sample[NCHANNELS]; 44 | for (int c = 0; c < NCHANNELS; c++) 45 | { 46 | sample[c] = sin(2 * pi * g_sine_freq * elapsed_seconds); 47 | } 48 | // send the sample 49 | outlet.push_sample(sample); 50 | push_counter += 1.0; 51 | std::cout << "Pushed sample (ch 1 = " << sample[0] << ")" << std::endl; 52 | } 53 | else 54 | { 55 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); 56 | } 57 | 58 | } 59 | 60 | } catch(std::exception &e) { 61 | std::cerr << "Got an exception: " << e.what() << std::endl; 62 | } 63 | std::cout << "Press any key to exit. " << std::endl; std::cin.get(); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /zip_marketplace.py: -------------------------------------------------------------------------------- 1 | # Zips the plugin, keeping only required and valid files for Marketplace distribution 2 | import os 3 | import zipfile 4 | 5 | def zip(dest): 6 | to_include = ( 7 | "Config", 8 | "Resources", 9 | "Source", 10 | "LICENSE", 11 | "LabStreamingLayer.uplugin" 12 | ) 13 | with zipfile.ZipFile(dest, 'w', zipfile.ZIP_DEFLATED) as zipf: 14 | for root, dirs, files in os.walk('.'): 15 | for file in files: 16 | relpath = os.path.relpath(os.path.join(root, file), '.') 17 | if not relpath.startswith(to_include): 18 | continue 19 | # Removing lslver.exe 20 | if relpath.endswith(".exe"): 21 | continue 22 | zipf.write(os.path.join(root, file), relpath) 23 | 24 | zip('UE5-LSL.zip') 25 | --------------------------------------------------------------------------------