Skip to content

Commit ea67066

Browse files
servusrenedatagutt
andcommitted
feat(srt): add listen_publisher_srtla for SRTLA/bonded connections
Add separate publisher listener port for SRTLA (bonded) connections, allowing both SRTLA and direct SRT publishers on the same server with streams accessible from a single player port. New config option: - listen_publisher_srtla: Publisher port with SRTLA patches enabled Usage: server { listen_player 4000; # All streams playable here listen_publisher 4001; # Direct SRT publishers listen_publisher_srtla 4002; # SRTLA publishers (via srtla_rec) } SRTLA patches are automatically enabled on listen_publisher_srtla and disabled on listen_publisher. This prevents glitching that occurs when using the wrong SRT settings for each connection type. Co-authored-by: datagutt <datagutt@lekanger.no>
1 parent 6e3d307 commit ea67066

File tree

7 files changed

+57
-9
lines changed

7 files changed

+57
-9
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN apk update \
1111
&& rm -rf /tmp/cpp-httplib
1212

1313
# Clone, build and install belabox-patched SRT
14-
RUN git clone https://github.com/onsmith/srt.git srt \
14+
RUN git clone https://github.com/OpenIRL/srt.git srt \
1515
&& cd srt \
1616
&& ./configure \
1717
&& make -j$(nproc) \

sls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ srt {
1919
server {
2020
listen_player 4000;
2121
listen_publisher 4001;
22+
listen_publisher_srtla 4002;
2223

2324
latency_min 200; # Minimum allowed latency in ms (0 = no enforcement)
2425
latency_max 5000; # Maximum allowed latency in ms (0 = no enforcement)

slscore/SLSListener.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ CSLSListener::CSLSListener()
103103
memset(m_http_url_role, 0, URL_MAX_LEN);
104104
memset(m_record_hls_path_prefix, 0, URL_MAX_LEN);
105105
m_is_publisher_listener = false;
106+
m_is_srtla_listener = false;
106107
// Default path, will be overridden by configuration
107108
strcpy(m_stream_id_json_path, "/etc/sls/streamids.json");
108109

@@ -163,6 +164,14 @@ void CSLSListener::set_listener_type(bool is_publisher)
163164
}
164165
}
165166

167+
void CSLSListener::set_srtla_mode(bool is_srtla)
168+
{
169+
m_is_srtla_listener = is_srtla;
170+
if (is_srtla) {
171+
sprintf(m_role_name, "listener-publisher-srtla");
172+
}
173+
}
174+
166175
int CSLSListener::init_conf_app()
167176
{
168177
sls_conf_server_t * conf_server;
@@ -247,9 +256,11 @@ int CSLSListener::start()
247256
if (NULL == m_srt)
248257
m_srt = new CSLSSrt();
249258

250-
// Use different ports for publisher and player listeners
259+
// Use different ports for publisher, SRTLA publisher, and player listeners
251260
sls_conf_server_t* server_conf = (sls_conf_server_t*)m_conf;
252-
if (m_is_publisher_listener) {
261+
if (m_is_srtla_listener) {
262+
m_port = server_conf->listen_publisher_srtla;
263+
} else if (m_is_publisher_listener) {
253264
m_port = server_conf->listen_publisher;
254265
} else {
255266
m_port = server_conf->listen_player;
@@ -261,13 +272,14 @@ int CSLSListener::start()
261272
return SLS_ERROR;
262273
}
263274

264-
ret = m_srt->libsrt_setup(m_port);
275+
ret = m_srt->libsrt_setup(m_port, m_is_srtla_listener);
265276
if (SLS_OK != ret) {
266277
sls_log(SLS_LOG_ERROR, "[%p]CSLSListener::start, libsrt_setup failure.", this);
267278
return ret;
268279
}
269-
sls_log(SLS_LOG_INFO, "[%p]CSLSListener::start, libsrt_setup ok on port %d for %s.",
270-
this, m_port, m_is_publisher_listener ? "publisher" : "player");
280+
sls_log(SLS_LOG_INFO, "[%p]CSLSListener::start, libsrt_setup ok on port %d for %s%s.",
281+
this, m_port, m_is_publisher_listener ? "publisher" : "player",
282+
m_is_srtla_listener ? " (SRTLA)" : "");
271283

272284
// Only publisher listeners handle latency settings
273285
if (m_is_publisher_listener) {

slscore/SLSListener.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
SLS_CONF_DYNAMIC_DECLARE_BEGIN(server)
4343
int listen_player; // Port for players
4444
int listen_publisher; // Port for publishers
45+
int listen_publisher_srtla; // Port for SRTLA publishers (enables SRTLA patches)
4546
int backlog;
4647
int latency_min; // Minimum allowed latency (ms)
4748
int latency_max; // Maximum allowed latency (ms)
@@ -60,6 +61,7 @@ SLS_CONF_DYNAMIC_DECLARE_END
6061
SLS_CONF_CMD_DYNAMIC_DECLARE_BEGIN(server)
6162
SLS_SET_CONF(server, int, listen_player, "listen port for players", 1, 65535),
6263
SLS_SET_CONF(server, int, listen_publisher, "listen port for publishers", 1, 65535),
64+
SLS_SET_CONF(server, int, listen_publisher_srtla, "listen port for SRTLA publishers", 1, 65535),
6365
SLS_SET_CONF(server, int, backlog, "how many sockets may be allowed to wait until they are accepted", 1, 1024),
6466
SLS_SET_CONF(server, int, latency_min, "minimum allowed latency (ms)", 0, 5000),
6567
SLS_SET_CONF(server, int, latency_max, "maximum allowed latency (ms)", 0, 10000),
@@ -97,6 +99,7 @@ public :
9799
void set_map_pusher(CSLSMapRelay *map_puller);
98100
void set_record_hls_path_prefix(char *path);
99101
void set_listener_type(bool is_publisher);
102+
void set_srtla_mode(bool is_srtla);
100103

101104
virtual std::string get_stat_info();
102105

@@ -113,6 +116,7 @@ public :
113116
char m_http_url_role[URL_MAX_LEN];
114117
char m_record_hls_path_prefix[URL_MAX_LEN];
115118
bool m_is_publisher_listener;
119+
bool m_is_srtla_listener;
116120
char m_stream_id_json_path[URL_MAX_LEN];
117121

118122
int init_conf_app();

slscore/SLSManager.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,30 @@ int CSLSManager::start()
133133
return SLS_ERROR;
134134
}
135135
m_servers.push_back(p_pub);
136-
136+
137+
// Create SRTLA publisher listener if configured
138+
if (conf->listen_publisher_srtla > 0) {
139+
CSLSListener * p_srtla = new CSLSListener();
140+
p_srtla->set_role_list(m_list_role);
141+
p_srtla->set_conf(conf);
142+
p_srtla->set_record_hls_path_prefix(conf_srt->record_hls_path_prefix);
143+
p_srtla->set_map_data("", &m_map_data[i]);
144+
p_srtla->set_map_publisher(&m_map_publisher[i]);
145+
p_srtla->set_map_puller(&m_map_puller[i]);
146+
p_srtla->set_map_pusher(&m_map_pusher[i]);
147+
p_srtla->set_listener_type(true); // Publisher listener
148+
p_srtla->set_srtla_mode(true); // Enable SRTLA patches
149+
if (p_srtla->init() != SLS_OK) {
150+
sls_log(SLS_LOG_INFO, "[%p]CSLSManager::start, p_srtla->init failed.", this);
151+
return SLS_ERROR;
152+
}
153+
if (p_srtla->start() != SLS_OK) {
154+
sls_log(SLS_LOG_INFO, "[%p]CSLSManager::start, p_srtla->start failed.", this);
155+
return SLS_ERROR;
156+
}
157+
m_servers.push_back(p_srtla);
158+
}
159+
137160
// Create player listener
138161
CSLSListener * p_play = new CSLSListener();//deleted by groups
139162
p_play->set_role_list(m_list_role);

slscore/SLSSrt.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void CSLSSrt::libsrt_set_context(SRTContext *sc)
144144
m_sc = *sc;
145145
}
146146

147-
int CSLSSrt::libsrt_setup(int port)
147+
int CSLSSrt::libsrt_setup(int port, bool srtla_patches)
148148
{
149149
struct addrinfo hints = { 0 }, *ai;
150150
int fd = -1;
@@ -205,6 +205,14 @@ int CSLSSrt::libsrt_setup(int port)
205205
sls_log(SLS_LOG_WARNING, "[%p]CSLSSrt::libsrt_setup, setsockopt(SRTO_REUSEADDR) failed.", this);
206206
}
207207

208+
if (srtla_patches) {
209+
int srtla_enable = 1;
210+
if (srt_setsockopt(fd, SOL_SOCKET, SRTO_SRTLAPATCHES, &srtla_enable, sizeof(srtla_enable)))
211+
sls_log(SLS_LOG_WARNING, "[%p]CSLSSrt::libsrt_setup, setsockopt(SRTO_SRTLAPATCHES) failed.", this);
212+
else
213+
sls_log(SLS_LOG_INFO, "[%p]CSLSSrt::libsrt_setup, SRTLA patches enabled on port %d.", this, port);
214+
}
215+
208216
ret = srt_bind(fd, ai->ai_addr, ai->ai_addrlen);
209217
if (ret) {
210218
srt_close(fd);

slscore/SLSSrt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public :
9494

9595
void libsrt_set_context(SRTContext *sc);
9696

97-
int libsrt_setup(int port);
97+
int libsrt_setup(int port, bool srtla_patches = false);
9898
int libsrt_close();
9999

100100
int libsrt_listen(int backlog);

0 commit comments

Comments
 (0)