From b74cbadd05d1ba42d66ba43a690c45f5d2c5f706 Mon Sep 17 00:00:00 2001
From: Kevin Harwell <kharwell@digium.com>
Date: Mon, 25 Sep 2017 12:30:56 -0500
Subject: [PATCH] res_pjsip_session: outgoing call did not offer all configured
 codecs

For some scenarios when an outgoing call was made only a subset of the
configured codecs were offered. If the codecs being offered happened to
not have a codec supported by the phone then the call would fail.

For instance Alice and Bob both are configured in Asterisk for g722 and ulaw(
allow=!all,g722,ulaw). Alice's endpoint however only supports g722 while Bob's
only supports ulaw. When Alice calls Bob, Alice negotiates g722 fine with
Asterisk. But when Asterisk sends the outgoing offer to Bob it only contains
g722 and not both g722 and ulaw, so the call ends.

This patch makes it so all the audio codecs configured on the endpoint always
get sent, and not just a subset. However priority is given to those codecs that
are compatible with the "other side".

ASTERISK-27259 #close

Change-Id: Iffabc373bd94cd1dc700925dcfe406e12918c696
---
 res/res_pjsip_session.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 76dafb378b..8b0ca2f73c 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -2459,6 +2459,16 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
 				continue;
 			}
 
+			if (ast_stream_get_type(req_stream) == AST_MEDIA_TYPE_AUDIO) {
+				/*
+				 * By appending codecs from the endpoint after compatible ones this
+				 * guarantees that priority is given to those while also allowing
+				 * translation to occur for non-compatible.
+				 */
+				ast_format_cap_append_from_cap(joint_cap,
+					endpoint->media.codecs, AST_MEDIA_TYPE_AUDIO);
+			}
+
 			ast_stream_set_formats(clone_stream, joint_cap);
 			ao2_ref(joint_cap, -1);
 
-- 
GitLab