From 2a10e4efa1c0e04b319dffb1c7381079fb83dc24 Mon Sep 17 00:00:00 2001 From: bmoradiy Date: Wed, 20 Dec 2023 12:27:56 +0530 Subject: [PATCH] Stop generating SWITCH_RTP_CRYPTO_SEND upon late offer i.e ack with sdp --- src/include/switch_types.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 4 ++++ src/switch_core_media.c | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 94a4c62cca..3d1a76ebe4 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1630,6 +1630,7 @@ typedef enum { CF_VIDEO_READ_TAPPED, CF_VIDEO_WRITE_TAPPED, CF_DEVICES_CHANGED, + CF_LATE_OFFER, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ /* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */ CF_FLAG_MAX diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c5b5bcc190..ea2fac4df0 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -7496,6 +7496,10 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (r_sdp) { switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, r_sdp); + if (ss_state == nua_callstate_ready && status == 200) { + switch_channel_set_flag(tech_pvt->channel, CF_LATE_OFFER); + } + if (!(profile->mndlb & SM_NDLB_ALLOW_NONDUP_SDP) || (!zstr(tech_pvt->mparams.remote_sdp_str) && !strcmp(tech_pvt->mparams.remote_sdp_str, r_sdp))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Duplicate SDP\n%s\n", r_sdp); is_dup_sdp = 1; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 4b6d8aff8b..fb11b3aa91 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -1731,8 +1731,12 @@ SWITCH_DECLARE(int) switch_core_session_check_incoming_crypto(switch_core_sessio } switch_channel_set_variable(session->channel, varname, vval); - switch_core_media_build_crypto(session->media_handle, type, crypto_tag, ctype, SWITCH_RTP_CRYPTO_SEND, 1, use_alias); - switch_rtp_add_crypto_key(engine->rtp_session, SWITCH_RTP_CRYPTO_SEND, atoi(crypto), &engine->ssec[engine->crypto_type]); + if (!switch_channel_test_flag(session->channel, CF_LATE_OFFER) || !switch_true(switch_channel_get_variable(session->channel, "disable_crypto_rekeying_on_late_offer"))) { + switch_core_media_build_crypto(session->media_handle, type, crypto_tag, ctype, SWITCH_RTP_CRYPTO_SEND, 1, use_alias); + switch_rtp_add_crypto_key(engine->rtp_session, SWITCH_RTP_CRYPTO_SEND, atoi(crypto), &engine->ssec[engine->crypto_type]); + } + switch_channel_clear_flag(session->channel, CF_LATE_OFFER); + } if (a && b && !strncasecmp(a, b, 23)) {