From 0e6cfbf8c37b9ba35f8af27c5292178efda3a80f Mon Sep 17 00:00:00 2001
From: Lukasz Kotasa <lukasz.kotasa@genexis.eu>
Date: Wed, 16 Apr 2025 09:50:50 +0000
Subject: [PATCH] Intersect codec sets for local_merge strategy, REF 16784
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Here is our pjsip_endpoint.conf:
outgoing_call_offer_pref = local_merge
incoming_call_offer_pref = remote_first

For outgoing calls we use local_merge (UNION) which means "Merge the lists with the preferred
codecs first"
For incomming calls we use remote_first (INTERSECT) which means "Only common codecs with the
preferred codecs first"

When UPDATE was received for incoming call, device responded with
488 Not Acceptable Here with Reason:Q.850;cause=16
When UPDATE was received for outgoing call, device responded with
488 Not Acceptable Here with Reason:Q.850;cause=58
BYE

After this commit we have the same behaviour for UPDATE during both incoming and outgoing call.

Incoming calls were fixed in similar way before in fb50196410c2f72be595730dd15234e502de0c11.
---
 res/res_pjsip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index b022ecb3de..8c71b70bd6 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2491,7 +2491,7 @@ const char *ast_sip_call_codec_pref_to_str(struct ast_flags pref)
 
 	if (ast_sip_call_codec_pref_test(pref, LOCAL) &&  ast_sip_call_codec_pref_test(pref, INTERSECT) && ast_sip_call_codec_pref_test(pref, ALL)) {
 		value = "local";
-	} else if (ast_sip_call_codec_pref_test(pref, LOCAL) &&  ast_sip_call_codec_pref_test(pref, UNION) && ast_sip_call_codec_pref_test(pref, ALL)) {
+	} else if (ast_sip_call_codec_pref_test(pref, LOCAL) &&  ast_sip_call_codec_pref_test(pref, INTERSECT) && ast_sip_call_codec_pref_test(pref, ALL)) {
 		value = "local_merge";
 	} else if (ast_sip_call_codec_pref_test(pref, LOCAL) &&  ast_sip_call_codec_pref_test(pref, INTERSECT) && ast_sip_call_codec_pref_test(pref, FIRST)) {
 		value = "local_first";
@@ -2515,7 +2515,7 @@ int ast_sip_call_codec_str_to_pref(struct ast_flags *pref, const char *pref_str,
 	if (strcmp(pref_str, "local") == 0) {
 		ast_set_flag(pref, AST_SIP_CALL_CODEC_PREF_LOCAL | AST_SIP_CALL_CODEC_PREF_INTERSECT | AST_SIP_CALL_CODEC_PREF_ALL);
 	} else if (is_outgoing && strcmp(pref_str, "local_merge") == 0) {
-		ast_set_flag(pref, AST_SIP_CALL_CODEC_PREF_LOCAL | AST_SIP_CALL_CODEC_PREF_UNION | AST_SIP_CALL_CODEC_PREF_ALL);
+		ast_set_flag(pref, AST_SIP_CALL_CODEC_PREF_LOCAL | AST_SIP_CALL_CODEC_PREF_INTERSECT | AST_SIP_CALL_CODEC_PREF_ALL);
 	} else if (strcmp(pref_str, "local_first") == 0) {
 		ast_set_flag(pref, AST_SIP_CALL_CODEC_PREF_LOCAL | AST_SIP_CALL_CODEC_PREF_INTERSECT | AST_SIP_CALL_CODEC_PREF_FIRST);
 	} else if (strcmp(pref_str, "remote") == 0) {
-- 
GitLab