From 0da35585a4b5a5638b88b316fd3f62c85aa456fb Mon Sep 17 00:00:00 2001 From: Sean Oxley <13091705+OxleyS@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:55:50 +0900 Subject: [PATCH 1/3] Transport-wide CC feedback reports no longer use an SSRC of zero if the first simulcast layer never gets data. --- src/ice.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ice.c b/src/ice.c index d9fc749b08..c3e8af066a 100644 --- a/src/ice.c +++ b/src/ice.c @@ -3997,6 +3997,20 @@ static gboolean janus_ice_outgoing_transport_wide_cc_feedback(gpointer user_data } if(pc && pc->do_transport_wide_cc && medium) { + /* Simulcast layers that have not received data will not have a recorded peer SSRC. */ + /* Pick the first layer that has a peer SSRC */ + guint32 ssrc_peer = 0; + for(int i = 0; i < 3; i++) { + if(medium->ssrc_peer[i] != 0) { + ssrc_peer = medium->ssrc_peer[i]; + break; + } + } + if (ssrc_peer == 0) { + JANUS_LOG(LOG_WARN, "No peer SSRC, cannot send transport-wide CC feedback\n"); + return G_SOURCE_CONTINUE; + } + /* Create a transport wide feedback message */ size_t size = 1300; char rtcpbuf[1300]; @@ -4065,7 +4079,7 @@ static gboolean janus_ice_outgoing_transport_wide_cc_feedback(gpointer user_data guint8 feedback_packet_count = pc->transport_wide_cc_feedback_count++; /* Create RTCP packet */ int len = janus_rtcp_transport_wide_cc_feedback(rtcpbuf, size, - medium->ssrc, medium->ssrc_peer[0], feedback_packet_count, packets_to_process); + medium->ssrc, ssrc_peer, feedback_packet_count, packets_to_process); /* Enqueue it, we'll send it later */ if(len > 0) { janus_plugin_rtcp rtcp = { .mindex = medium->mindex, .video = TRUE, .buffer = rtcpbuf, .length = len }; From d94d2834a634070f045dbf9777d0c9a2198db3d7 Mon Sep 17 00:00:00 2001 From: Sean Oxley <13091705+OxleyS@users.noreply.github.com> Date: Wed, 2 Mar 2022 19:52:19 +0900 Subject: [PATCH 2/3] Expanded the SSRC candidate list for TWCC feedback to all video mediums, not just the first one. Changed the log level to LOG_HUGE for when no valid SSRC is found. --- src/ice.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/ice.c b/src/ice.c index c3e8af066a..3b579b97e1 100644 --- a/src/ice.c +++ b/src/ice.c @@ -3979,6 +3979,7 @@ static gboolean janus_ice_outgoing_transport_wide_cc_feedback(gpointer user_data janus_ice_handle *handle = (janus_ice_handle *)user_data; janus_ice_peerconnection *pc = handle->pc; + guint32 ssrc_peer = 0; janus_ice_peerconnection_medium *medium = NULL; if(pc) { /* Find inbound video medium */ @@ -3989,28 +3990,31 @@ static gboolean janus_ice_outgoing_transport_wide_cc_feedback(gpointer user_data while (g_hash_table_iter_next(&iter, NULL, &value)) { janus_ice_peerconnection_medium *m = value; if(m && m->type == JANUS_MEDIA_VIDEO && m->recv) { - medium = m; - break; + /* If a medium (or simulcast layer, if applicable) has not received data, its SSRC may be unknown. */ + /* Pick the first valid SSRC we find across all considered mediums */ + int i = 0; + for(i = 0; i < 3; i++) { + if(m->ssrc_peer[i] != 0) + break; + } + + /* Stop if we found a valid SSRC/medium to use */ + if(i < 3) { + ssrc_peer = m->ssrc_peer[i]; + medium = m; + break; + } } } janus_mutex_unlock(&handle->mutex); } - if(pc && pc->do_transport_wide_cc && medium) { - /* Simulcast layers that have not received data will not have a recorded peer SSRC. */ - /* Pick the first layer that has a peer SSRC */ - guint32 ssrc_peer = 0; - for(int i = 0; i < 3; i++) { - if(medium->ssrc_peer[i] != 0) { - ssrc_peer = medium->ssrc_peer[i]; - break; - } - } - if (ssrc_peer == 0) { - JANUS_LOG(LOG_WARN, "No peer SSRC, cannot send transport-wide CC feedback\n"); - return G_SOURCE_CONTINUE; - } + if(!medium) { + JANUS_LOG(LOG_HUGE, "No medium with a valid peer SSRC found for transport-wide CC feedback\n"); + return G_SOURCE_CONTINUE; + } + if(pc && pc->do_transport_wide_cc) { /* Create a transport wide feedback message */ size_t size = 1300; char rtcpbuf[1300]; From 198cb2b6c0e5446a6f9fba74162931c25b81cb25 Mon Sep 17 00:00:00 2001 From: Sean Oxley <13091705+OxleyS@users.noreply.github.com> Date: Wed, 2 Mar 2022 20:11:24 +0900 Subject: [PATCH 3/3] Styling cleanup for peer SSRC selection for TWCC. --- src/ice.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ice.c b/src/ice.c index 3b579b97e1..a74c860c5c 100644 --- a/src/ice.c +++ b/src/ice.c @@ -3994,22 +3994,22 @@ static gboolean janus_ice_outgoing_transport_wide_cc_feedback(gpointer user_data /* Pick the first valid SSRC we find across all considered mediums */ int i = 0; for(i = 0; i < 3; i++) { - if(m->ssrc_peer[i] != 0) + if(m->ssrc_peer[i] != 0) { + ssrc_peer = m->ssrc_peer[i]; + medium = m; break; + } } /* Stop if we found a valid SSRC/medium to use */ - if(i < 3) { - ssrc_peer = m->ssrc_peer[i]; - medium = m; + if(medium && ssrc_peer) break; - } } } janus_mutex_unlock(&handle->mutex); } - if(!medium) { + if(medium == NULL) { JANUS_LOG(LOG_HUGE, "No medium with a valid peer SSRC found for transport-wide CC feedback\n"); return G_SOURCE_CONTINUE; }