From 6c87ed491597fb5e30935d8309aa7e0c3aa9e18f Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 17 Dec 2021 13:55:11 -0700 Subject: [PATCH] [Core] RFC 3264 says once we assign a payload number to a dynamic codec, we are stuck with it. 8.3.1 Modifying Address, Port or Transport The port number for a stream MAY be changed. To do this, the offerer creates a new media description, with the port number in the m line different from the corresponding stream in the previous SDP. If only the port number is to be changed, the rest of the media stream description SHOULD remain unchanged. The offerer MUST be prepared to receive media on both the old and new ports as soon as the offer is sent. The offerer SHOULD NOT cease listening for media on the old port until the answer is received and media arrives on the new port. Doing so could result in loss of media during the transition. Co-authored-by: Anthony Minessale --- src/switch_core_media.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 0b337082b8..1b7f392761 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -9907,7 +9907,8 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, for (i = 0; i < smh->mparams->num_codecs; i++) { const switch_codec_implementation_t *imp = smh->codecs[i]; int this_ptime = (imp->microseconds_per_packet / 1000); - + payload_map_t *pmap; + if (!strcasecmp(imp->iananame, "ilbc") || !strcasecmp(imp->iananame, "isac") ) { this_ptime = 20; } @@ -9932,7 +9933,18 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen, continue; } + + switch_mutex_lock(smh->sdp_mutex); + for (pmap = a_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) { + if (pmap->negotiated && !strcasecmp(imp->iananame, pmap->iananame)) { + smh->ianacodes[i] = pmap->pt; + break; + } + } + switch_mutex_unlock(smh->sdp_mutex); + already_did[smh->ianacodes[i]] = 1; + switch_snprintf(buf + strlen(buf), buflen - strlen(buf), " %d", smh->ianacodes[i]); } @@ -11114,13 +11126,21 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess continue; } - if (smh->ianacodes[i] < 128) { - if (already_did[smh->ianacodes[i]]) { - continue; - } - already_did[smh->ianacodes[i]] = 1; + if (smh->ianacodes[i] >= 128 || already_did[smh->ianacodes[i]]) { + continue; } + switch_mutex_lock(smh->sdp_mutex); + for (pmap = v_engine->cur_payload_map; pmap && pmap->allocated; pmap = pmap->next) { + if (pmap->negotiated && !strcasecmp(imp->iananame, pmap->iananame)) { + smh->ianacodes[i] = pmap->pt; + break; + } + } + switch_mutex_unlock(smh->sdp_mutex); + + already_did[smh->ianacodes[i]] = 1; + switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), " %d", smh->ianacodes[i]); if (!ptime) {