Skip to content

Commit

Permalink
Fix SDP negotiation when client uses max-bundles (fixes meetecho#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero authored and PauKerr committed Nov 11, 2020
1 parent 229eb97 commit 2cf0f4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
19 changes: 9 additions & 10 deletions sdp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,15 @@ janus_sdp *janus_sdp_parse(const char *sdp, char *error, size_t errlen) {
m->proto = g_strdup(proto);
m->direction = JANUS_SDP_SENDRECV;
m->c_ipv4 = TRUE;
if(m->port > 0 || m->type == JANUS_SDP_APPLICATION) {
/* Now let's check the payload types/formats */
gchar **mline_parts = g_strsplit(line+2, " ", -1);
if(!mline_parts) {
janus_sdp_mline_destroy(m);
if(error)
g_snprintf(error, errlen, "Invalid m= line (no payload types/formats): %s", line);
success = FALSE;
break;
}
/* Now let's check the payload types/formats */
gchar **mline_parts = g_strsplit(line+2, " ", -1);
if(!mline_parts && (m->port > 0 || m->type == JANUS_SDP_APPLICATION)) {
janus_sdp_mline_destroy(m);
if(error)
g_snprintf(error, errlen, "Invalid m= line (no payload types/formats): %s", line);
success = FALSE;
break;
} else {
int mindex = 0;
while(mline_parts[mindex]) {
if(mindex < 3) {
Expand Down
25 changes: 18 additions & 7 deletions sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ janus_sdp *janus_sdp_preparse(void *ice_handle, const char *jsep_sdp, char *erro
GList *temp = parsed_sdp->m_lines;
while(temp) {
janus_sdp_mline *m = (janus_sdp_mline *)temp->data;
if(m->type == JANUS_SDP_AUDIO && m->port > 0) {
if(m->type == JANUS_SDP_AUDIO) {
*audio = *audio + 1;
} else if(m->type == JANUS_SDP_VIDEO && m->port > 0) {
} else if(m->type == JANUS_SDP_VIDEO) {
*video = *video + 1;
}
/* Preparse the mid as well */
/* Preparse the mid as well, and check if bundle-only is used */
GList *tempA = m->attributes;
while(tempA) {
janus_sdp_attribute *a = (janus_sdp_attribute *)tempA->data;
if(a->name) {
if(!strcasecmp(a->name, "mid")) {
if(!strcasecmp(a->name, "bundle-only") && m->port == 0) {
/* Port 0 but bundle-only is used, don't disable this m-line */
m->port = 9;
} else if(!strcasecmp(a->name, "mid")) {
/* Found mid attribute */
if(a->value == NULL) {
JANUS_LOG(LOG_ERR, "[%"SCNu64"] Invalid mid attribute (no value)\n", handle->handle_id);
Expand Down Expand Up @@ -89,6 +92,14 @@ janus_sdp *janus_sdp_preparse(void *ice_handle, const char *jsep_sdp, char *erro
}
}
}
/* If the m-line is disabled don't actually increase the count */
if(m->port == 0) {
if(m->type == JANUS_SDP_AUDIO) {
*audio = *audio - 1;
} else if(m->type == JANUS_SDP_VIDEO) {
*video = *video - 1;
}
}
tempA = tempA->next;
}
temp = temp->next;
Expand Down Expand Up @@ -1234,14 +1245,14 @@ char *janus_sdp_merge(void *ice_handle, janus_sdp *anon, gboolean offer) {
janus_sdp_mline *m = (janus_sdp_mline *)temp->data;
if(m->type == JANUS_SDP_AUDIO) {
audio++;
if(audio == 1) {
if(audio == 1 && m->port > 0) {
g_snprintf(buffer_part, sizeof(buffer_part),
" %s", handle->audio_mid ? handle->audio_mid : "audio");
g_strlcat(buffer, buffer_part, sizeof(buffer));
}
} else if(m->type == JANUS_SDP_VIDEO) {
video++;
if(video == 1) {
if(video == 1 && m->port > 0) {
g_snprintf(buffer_part, sizeof(buffer_part),
" %s", handle->video_mid ? handle->video_mid : "video");
g_strlcat(buffer, buffer_part, sizeof(buffer));
Expand All @@ -1250,7 +1261,7 @@ char *janus_sdp_merge(void *ice_handle, janus_sdp *anon, gboolean offer) {
} else if(m->type == JANUS_SDP_APPLICATION) {
if(m->proto && (!strcasecmp(m->proto, "DTLS/SCTP") || !strcasecmp(m->proto, "UDP/DTLS/SCTP")))
data++;
if(data == 1) {
if(data == 1 && m->port > 0) {
g_snprintf(buffer_part, sizeof(buffer_part),
" %s", handle->data_mid ? handle->data_mid : "data");
g_strlcat(buffer, buffer_part, sizeof(buffer));
Expand Down

0 comments on commit 2cf0f4e

Please sign in to comment.