diff --git a/src/plugins/janus_videoroom.c b/src/plugins/janus_videoroom.c index f6f7b2aeb8..d97d1d0296 100644 --- a/src/plugins/janus_videoroom.c +++ b/src/plugins/janus_videoroom.c @@ -2419,6 +2419,7 @@ typedef struct janus_videoroom_publisher { GHashTable *remote_recipients; /* In case this is a remote publisher */ gboolean remote; /* Whether this is a remote publisher */ + uint32_t remote_ssrc_offset; /* SSRC offset to apply to the incoming RTP traffic */ int remote_fd, remote_rtcp_fd, pipefd[2]; /* Remote publisher sockets */ struct sockaddr_storage rtcp_addr; /* RTCP address of the remote publisher */ GThread *remote_thread; /* Remote publisher incoming packets thread */ @@ -7679,6 +7680,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi publisher->vcodec = JANUS_VIDEOCODEC_NONE; publisher->data_mindex = -1; publisher->remote = TRUE; + publisher->remote_ssrc_offset = janus_random_uint32(); publisher->remote_fd = fd; publisher->remote_rtcp_fd = rtcp_fd; pipe(publisher->pipefd); @@ -7776,9 +7778,9 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi ps->simulcast = json_is_true(json_object_get(s, "simulcast")); ps->svc = json_is_true(json_object_get(s, "svc")); if(ps->simulcast) { - ps->vssrc[0] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP); - ps->vssrc[1] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1; - ps->vssrc[2] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2; + ps->vssrc[0] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP); + ps->vssrc[1] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1; + ps->vssrc[2] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2; } } int video_orient_extmap_id = json_integer_value(json_object_get(s, "videoorient_ext_id")); @@ -8052,9 +8054,9 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi ps->simulcast = json_is_true(json_object_get(s, "simulcast")); ps->svc = json_is_true(json_object_get(s, "svc")); if(ps->simulcast) { - ps->vssrc[0] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP); - ps->vssrc[1] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1; - ps->vssrc[2] = REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2; + ps->vssrc[0] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP); + ps->vssrc[1] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 1; + ps->vssrc[2] = publisher->remote_ssrc_offset + REMOTE_PUBLISHER_BASE_SSRC + (mindex*REMOTE_PUBLISHER_SSRC_STEP) + 2; } } int video_orient_extmap_id = json_integer_value(json_object_get(s, "videoorient_ext_id")); @@ -13642,6 +13644,9 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) { pkt.extensions.max_delay = max; } } + /* Apply an SSRC offset to avoid issues when switching, + * see https://github.com/meetecho/janus-gateway/issues/3444 */ + rtp->ssrc = htonl(ntohl(rtp->ssrc) + publisher->remote_ssrc_offset); /* Now handle the packet as if coming from a regular publisher */ janus_videoroom_incoming_rtp_internal(publisher->session, publisher, &pkt); }