Skip to content

Commit e91d815

Browse files
authored
Fix broken switch when using remote publishers (fixes #3444) (#3447)
1 parent d014cff commit e91d815

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/plugins/janus_videoroom.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ typedef struct janus_videoroom_publisher {
24192419
GHashTable *remote_recipients;
24202420
/* In case this is a remote publisher */
24212421
gboolean remote; /* Whether this is a remote publisher */
2422+
uint32_t remote_ssrc_offset; /* SSRC offset to apply to the incoming RTP traffic */
24222423
int remote_fd, remote_rtcp_fd, pipefd[2]; /* Remote publisher sockets */
24232424
struct sockaddr_storage rtcp_addr; /* RTCP address of the remote publisher */
24242425
GThread *remote_thread; /* Remote publisher incoming packets thread */
@@ -7697,6 +7698,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
76977698
publisher->vcodec = JANUS_VIDEOCODEC_NONE;
76987699
publisher->data_mindex = -1;
76997700
publisher->remote = TRUE;
7701+
publisher->remote_ssrc_offset = janus_random_uint32();
77007702
publisher->remote_fd = fd;
77017703
publisher->remote_rtcp_fd = rtcp_fd;
77027704
pipe(publisher->pipefd);
@@ -7794,9 +7796,9 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
77947796
ps->simulcast = json_is_true(json_object_get(s, "simulcast"));
77957797
ps->svc = json_is_true(json_object_get(s, "svc"));
77967798
if(ps->simulcast) {
7797-
ps->vssrc[0] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP);
7798-
ps->vssrc[1] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1;
7799-
ps->vssrc[2] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2;
7799+
ps->vssrc[0] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP);
7800+
ps->vssrc[1] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1;
7801+
ps->vssrc[2] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2;
78007802
}
78017803
}
78027804
int video_orient_extmap_id = json_integer_value(json_object_get(s, "videoorient_ext_id"));
@@ -8072,9 +8074,9 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
80728074
ps->simulcast = json_is_true(json_object_get(s, "simulcast"));
80738075
ps->svc = json_is_true(json_object_get(s, "svc"));
80748076
if(ps->simulcast) {
8075-
ps->vssrc[0] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP);
8076-
ps->vssrc[1] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1;
8077-
ps->vssrc[2] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2;
8077+
ps->vssrc[0] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP);
8078+
ps->vssrc[1] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1;
8079+
ps->vssrc[2] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2;
80788080
}
80798081
}
80808082
int video_orient_extmap_id = json_integer_value(json_object_get(s, "videoorient_ext_id"));
@@ -13682,6 +13684,9 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) {
1368213684
pkt.extensions.max_delay = max;
1368313685
}
1368413686
}
13687+
/* Apply an SSRC offset to avoid issues when switching,
13688+
* see https://github.com/meetecho/janus-gateway/issues/3444 */
13689+
rtp->ssrc = htonl(ntohl(rtp->ssrc) + publisher->remote_ssrc_offset);
1368513690
/* Now handle the packet as if coming from a regular publisher */
1368613691
janus_videoroom_incoming_rtp_internal(publisher->session, publisher, &pkt);
1368713692
}

0 commit comments

Comments
 (0)