v2.0.0
Loading...
Searching...
No Matches
lsl_stream_info.cpp
Go to the documentation of this file.
1//=============================================================================================================
30
31//=============================================================================================================
32// INCLUDES
33//=============================================================================================================
34
35#include "lsl_stream_info.h"
36
37//=============================================================================================================
38// QT INCLUDES
39//=============================================================================================================
40
41#include <QHostInfo>
42#include <QUuid>
43
44//=============================================================================================================
45// STL INCLUDES
46//=============================================================================================================
47
48#include <sstream>
49
50//=============================================================================================================
51// USED NAMESPACES
52//=============================================================================================================
53
54using namespace LSLLIB;
55
56//=============================================================================================================
57// DEFINE MEMBER METHODS
58//=============================================================================================================
59
61: m_name()
62, m_type()
63, m_channel_count(0)
64, m_nominal_srate(0.0)
65, m_channel_format(ChannelFormat::Undefined)
66, m_source_id()
67, m_uid()
68, m_hostname()
69, m_data_port(0)
70, m_data_host()
71{
72}
73
74//=============================================================================================================
75
76stream_info::stream_info(const std::string& name,
77 const std::string& type,
78 int channel_count,
79 double nominal_srate,
81 const std::string& source_id)
82: m_name(name)
83, m_type(type)
84, m_channel_count(channel_count)
85, m_nominal_srate(nominal_srate)
86, m_channel_format(channel_format)
87, m_source_id(source_id)
88, m_uid(QUuid::createUuid().toString(QUuid::WithoutBraces).toStdString())
89, m_hostname(QHostInfo::localHostName().toStdString())
90, m_data_port(0)
91, m_data_host()
92{
93}
94
95//=============================================================================================================
96
97std::string stream_info::name() const noexcept
98{
99 return m_name;
100}
101
102//=============================================================================================================
103
104std::string stream_info::type() const noexcept
105{
106 return m_type;
107}
108
109//=============================================================================================================
110
111int stream_info::channel_count() const noexcept
112{
113 return m_channel_count;
114}
115
116//=============================================================================================================
117
118double stream_info::nominal_srate() const noexcept
119{
120 return m_nominal_srate;
121}
122
123//=============================================================================================================
124
126{
127 return m_channel_format;
128}
129
130//=============================================================================================================
131
132std::string stream_info::source_id() const noexcept
133{
134 return m_source_id;
135}
136
137//=============================================================================================================
138
139std::string stream_info::uid() const noexcept
140{
141 return m_uid;
142}
143
144//=============================================================================================================
145
146std::string stream_info::hostname() const noexcept
147{
148 return m_hostname;
149}
150
151//=============================================================================================================
152
153int stream_info::data_port() const noexcept
154{
155 return m_data_port;
156}
157
158//=============================================================================================================
159
160std::string stream_info::data_host() const noexcept
161{
162 return m_data_host;
163}
164
165//=============================================================================================================
166
168{
169 m_data_port = port;
170}
171
172//=============================================================================================================
173
174void stream_info::set_data_host(const std::string& host)
175{
176 m_data_host = host;
177}
178
179//=============================================================================================================
180
181std::string stream_info::to_string() const
182{
183 // Pipe-delimited format:
184 // MNELSL1|name|type|channel_count|nominal_srate|uid|hostname|source_id|data_port|channel_format
185 std::ostringstream oss;
186 oss << "MNELSL1"
187 << "|" << m_name
188 << "|" << m_type
189 << "|" << m_channel_count
190 << "|" << m_nominal_srate
191 << "|" << m_uid
192 << "|" << m_hostname
193 << "|" << m_source_id
194 << "|" << m_data_port
195 << "|" << static_cast<int>(m_channel_format);
196 return oss.str();
197}
198
199//=============================================================================================================
200
201stream_info stream_info::from_string(const std::string& data)
202{
203 // Parse pipe-delimited format
204 std::istringstream iss(data);
205 std::string token;
206 std::vector<std::string> tokens;
207
208 while (std::getline(iss, token, '|')) {
209 tokens.push_back(token);
210 }
211
212 // Validate: need at least 10 fields (header + 9 data fields)
213 if (tokens.size() < 10 || tokens[0] != "MNELSL1") {
214 return stream_info(); // return invalid/empty
215 }
216
217 stream_info info;
218 info.m_name = tokens[1];
219 info.m_type = tokens[2];
220 info.m_channel_count = std::stoi(tokens[3]);
221 info.m_nominal_srate = std::stod(tokens[4]);
222 info.m_uid = tokens[5];
223 info.m_hostname = tokens[6];
224 info.m_source_id = tokens[7];
225 info.m_data_port = std::stoi(tokens[8]);
226 info.m_channel_format = static_cast<ChannelFormat>(std::stoi(tokens[9]));
227
228 return info;
229}
Declares stream_info, the LSL metadata descriptor that identifies and routes a stream on the network.
Lab Streaming Layer (LSL) integration for real-time data exchange.
int channel_count() const noexcept
Number of channels.
int data_port() const noexcept
TCP data port of the outlet.
double nominal_srate() const noexcept
Nominal sampling rate in Hz. 0.0 means irregular.
std::string to_string() const
Serialize stream_info into a string for network transport.
std::string hostname() const noexcept
Hostname of the machine from which the stream originates.
void set_data_host(const std::string &host)
Set the data host (used internally during discovery).
std::string source_id() const noexcept
Unique source identifier.
void set_data_port(int port)
Set the TCP data port (used internally during discovery / outlet creation).
ChannelFormat channel_format() const noexcept
Data format of a channel.
std::string uid() const noexcept
A unique identifier for this particular stream instance (auto-generated).
std::string name() const noexcept
Name of the stream.
std::string type() const noexcept
Content type of the stream.
static stream_info from_string(const std::string &data)
Deserialize a stream_info from a network transport string.
std::string data_host() const noexcept
Host address of the outlet (IP, set from UDP sender address during discovery).