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