Skip to content

Commit

Permalink
Fix broken switch when using remote publishers (fixes meetecho#3444) (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero authored and Alexander Malaev committed Oct 24, 2024
1 parent fb9c2cc commit 5b94d3f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5b94d3f

Please sign in to comment.