<p>Kevin Harwell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13842">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">codec negotiation: add incoming_call_offer_prefs option<br><br>Add a new option, incoming_call_offer_pref, to res_pjsip endpoints that<br>specifies the preferred order of codecs after receiving an offer.<br><br>This patch does the following:<br><br> Adds a new enumeration, ast_sip_call_codec_pref, used by the the new<br>configuration option that's added to the endpoint media structure.<br><br> Adds a new ast_sip_session_caps structure that's set for each session media<br>object.<br><br> Creates a new file, res_pjsip_session_caps that "implements" the new<br>structure and option, and is compiled into the res_pjsip_session library.<br><br>ASTERISK-28756 #close<br><br>Change-Id: I35e7a2a0c236cfb6bd9cdf89539f57a1ffefc76f<br>---<br>M configs/samples/pjsip.conf.sample<br>A doc/CHANGES-staging/res_pjsip_incoming_call_offer_pref.txt<br>M include/asterisk/res_pjsip.h<br>M include/asterisk/res_pjsip_session.h<br>A include/asterisk/res_pjsip_session_caps.h<br>M res/Makefile<br>M res/res_pjsip.c<br>M res/res_pjsip/pjsip_configuration.c<br>M res/res_pjsip_sdp_rtp.c<br>M res/res_pjsip_session.c<br>A res/res_pjsip_session/pjsip_session_caps.c<br>11 files changed, 423 insertions(+), 20 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/13842/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample</span><br><span>index 92d9aaa..4330345 100644</span><br><span>--- a/configs/samples/pjsip.conf.sample</span><br><span>+++ b/configs/samples/pjsip.conf.sample</span><br><span>@@ -798,6 +798,16 @@</span><br><span> ; "0" or not enabled)</span><br><span> ;contact_user= ; On outgoing requests, force the user portion of the Contact</span><br><span> ; header to this value (default: "")</span><br><span style="color: hsl(120, 100%, 40%);">+;incoming_call_offer_pref= ; Sets the preferred codecs, and order to use between</span><br><span style="color: hsl(120, 100%, 40%);">+ ; those received in the offer, and those set in this</span><br><span style="color: hsl(120, 100%, 40%);">+ ; configuration's allow line. Valid values include:</span><br><span style="color: hsl(120, 100%, 40%);">+ ;</span><br><span style="color: hsl(120, 100%, 40%);">+ ; local - prefer and order by configuration (default).</span><br><span style="color: hsl(120, 100%, 40%);">+ ; local_single - prefer and order by configuration,</span><br><span style="color: hsl(120, 100%, 40%);">+ ; but only choose 'top' most codec</span><br><span style="color: hsl(120, 100%, 40%);">+ ; remote - prefer and order by incoming sdp.</span><br><span style="color: hsl(120, 100%, 40%);">+ ; remote_single - prefer and order by incoming sdp,</span><br><span style="color: hsl(120, 100%, 40%);">+ ; but only choose 'top' most codec</span><br><span> ;preferred_codec_only=yes ; Respond to a SIP invite with the single most preferred codec</span><br><span> ; rather than advertising all joint codec capabilities. This</span><br><span> ; limits the other side's codec choice to exactly what we prefer.</span><br><span>diff --git a/doc/CHANGES-staging/res_pjsip_incoming_call_offer_pref.txt b/doc/CHANGES-staging/res_pjsip_incoming_call_offer_pref.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..ecd71d0</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_pjsip_incoming_call_offer_pref.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip_session</span><br><span style="color: hsl(120, 100%, 40%);">+Master-Only: True</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+A new option, incoming_call_offer_pref, was added to res_pjsip endpoints that</span><br><span style="color: hsl(120, 100%, 40%);">+specifies the preferred order of codecs to use between those received in the</span><br><span style="color: hsl(120, 100%, 40%);">+offer, and those set in the configuration.</span><br><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index b26aba9..40192ec 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -510,6 +510,18 @@</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Incoming/Outgoing call offer/answer joint codec preference.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_sip_call_codec_pref {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_CALL_CODEC_PREF_LOCAL,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_CALL_CODEC_PREF_LOCAL_LIMIT,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_CALL_CODEC_PREF_LOCAL_SINGLE,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_CALL_CODEC_PREF_REMOTE,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_CALL_CODEC_PREF_REMOTE_LIMIT,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_SIP_CALL_CODEC_PREF_REMOTE_SINGLE,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Session timers options</span><br><span> */</span><br><span> struct ast_sip_timer_options {</span><br><span>@@ -750,6 +762,8 @@</span><br><span> unsigned int bundle;</span><br><span> /*! Enable webrtc settings and defaults */</span><br><span> unsigned int webrtc;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Codec preference for an incoming offer */</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_sip_call_codec_pref incoming_call_offer_pref;</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h</span><br><span>index 485cbd3..4ff53f1 100644</span><br><span>--- a/include/asterisk/res_pjsip_session.h</span><br><span>+++ b/include/asterisk/res_pjsip_session.h</span><br><span>@@ -31,6 +31,8 @@</span><br><span> /* Needed for ast_media_type */</span><br><span> #include "asterisk/codec.h"</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/res_pjsip_session_caps.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Forward declarations */</span><br><span> struct ast_sip_endpoint;</span><br><span> struct ast_sip_transport;</span><br><span>@@ -79,6 +81,8 @@</span><br><span> struct ast_sip_session_sdp_handler *handler;</span><br><span> /*! \brief Holds SRTP information */</span><br><span> struct ast_sdp_srtp *srtp;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Media format capabilities */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session_caps *caps;</span><br><span> /*! \brief What type of encryption is in use on this stream */</span><br><span> enum ast_sip_session_media_encryption encryption;</span><br><span> /*! \brief The media transport in use for this stream */</span><br><span>diff --git a/include/asterisk/res_pjsip_session_caps.h b/include/asterisk/res_pjsip_session_caps.h</span><br><span>new file mode 100644</span><br><span>index 0000000..8328377</span><br><span>--- /dev/null</span><br><span>+++ b/include/asterisk/res_pjsip_session_caps.h</span><br><span>@@ -0,0 +1,76 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Asterisk -- An open source telephony toolkit.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2020, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Kevin Harwell <kharwell@sangoma.com></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * See http://www.asterisk.org for more information about</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Asterisk project. Please do not directly contact</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the maintainers of this project for assistance;</span><br><span style="color: hsl(120, 100%, 40%);">+ * the project provides a web site, mailing lists and IRC</span><br><span style="color: hsl(120, 100%, 40%);">+ * channels for your use.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+ * the GNU General Public License Version 2. See the LICENSE file</span><br><span style="color: hsl(120, 100%, 40%);">+ * at the top of the source tree.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef _PJSIP_SESSION_CAPS_H</span><br><span style="color: hsl(120, 100%, 40%);">+#define _PJSIP_SESSION_CAPS_H</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_format_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_session;</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_session_media;</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_session_caps;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Allocate a sip session capabilities object.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval An ao2 allocated sip session capabilities object, or NULL on error</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_session_caps *ast_sip_session_caps_alloc(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Set the incoming call offer capabilities for a session.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param caps A session's capabilities object</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param cap The capabilities to set it to</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_sip_session_set_incoming_call_offer_cap(struct ast_sip_session_caps *caps,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format_cap *cap);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get the incoming call offer capabilities.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note Returned objects reference is not incremented.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param caps A session's capabilities object</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval An incoming call offer capabilities object</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+const struct ast_format_cap *ast_sip_session_get_incoming_call_offer_cap(</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_sip_session_caps *caps);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Build the incoming call offer capabilities for a session.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18.0.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Creates a set of joint capabilities between the given remote capabilities,</span><br><span style="color: hsl(120, 100%, 40%);">+ * and pre-configured ones.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note Returned objects reference is not incremented.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param session The session</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param session_media An associated media session</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param remote Capabilities of a device</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval A pointer to the incoming call offer capabilities</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+const struct ast_format_cap *ast_sip_session_build_incoming_call_offer_cap(</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_sip_session *session, const struct ast_sip_session_media *session_media,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_format_cap *remote);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* _PJSIP_SESSION_CAPS_H */</span><br><span>diff --git a/res/Makefile b/res/Makefile</span><br><span>index 78410ad..b4f50b7 100644</span><br><span>--- a/res/Makefile</span><br><span>+++ b/res/Makefile</span><br><span>@@ -66,6 +66,7 @@</span><br><span> $(call MOD_ADD_C,res_snmp,snmp/agent.c)</span><br><span> $(call MOD_ADD_C,res_parking,$(wildcard parking/*.c))</span><br><span> $(call MOD_ADD_C,res_pjsip,$(wildcard res_pjsip/*.c))</span><br><span style="color: hsl(120, 100%, 40%);">+$(call MOD_ADD_C,res_pjsip_session,$(wildcard res_pjsip_session/*.c))</span><br><span> $(call MOD_ADD_C,res_prometheus,$(wildcard prometheus/*.c))</span><br><span> $(call MOD_ADD_C,res_ari,ari/cli.c ari/config.c ari/ari_websockets.c)</span><br><span> $(call MOD_ADD_C,res_ari_model,ari/ari_model_validators.c)</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 0dcbcea..3751551 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -925,6 +925,35 @@</span><br><span> <configOption name="preferred_codec_only" default="no"></span><br><span> <synopsis>Respond to a SIP invite with the single most preferred codec rather than advertising all joint codec capabilities. This limits the other side's codec choice to exactly what we prefer.</synopsis></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="incoming_call_offer_pref" default="local"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>After receiving an incoming offer create a list of preferred codecs between</span><br><span style="color: hsl(120, 100%, 40%);">+ those received in the SDP offer, and those specified in endpoint configuration.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <note><para>This list will consist of only those codecs found in both.</para></note></span><br><span style="color: hsl(120, 100%, 40%);">+ <enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="local"><para></span><br><span style="color: hsl(120, 100%, 40%);">+ Order by the endpoint configuration allow line (default)</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></enum></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="local_single"><para></span><br><span style="color: hsl(120, 100%, 40%);">+ Order by the endpoint configuration allow line, but the list will only contain the first, or 'top' item</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></enum></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="remote"><para></span><br><span style="color: hsl(120, 100%, 40%);">+ Order by what is received in the SDP offer</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></enum></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="remote_single"><para></span><br><span style="color: hsl(120, 100%, 40%);">+ Order by what is received in the SDP offer, but the list will only contain the first, or 'top' item</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></enum></span><br><span style="color: hsl(120, 100%, 40%);">+ </enumlist></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="rtp_keepalive"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Number of seconds between RTP comfort noise keepalive packets.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <description><para></span><br><span style="color: hsl(120, 100%, 40%);">+ At the specified interval, Asterisk will send an RTP comfort noise frame. This may</span><br><span style="color: hsl(120, 100%, 40%);">+ be useful for situations where Asterisk is behind a NAT or firewall and must keep</span><br><span style="color: hsl(120, 100%, 40%);">+ a hole open in order to allow for media to arrive at Asterisk.</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></description></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> <configOption name="rtp_keepalive"></span><br><span> <synopsis>Number of seconds between RTP comfort noise keepalive packets.</synopsis></span><br><span> <description><para></span><br><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index 355b595..abcdaf0 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -1117,6 +1117,47 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static const char *sip_call_codec_pref_strings[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_SIP_CALL_CODEC_PREF_LOCAL] = "local",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_SIP_CALL_CODEC_PREF_LOCAL_LIMIT] = "local_limit",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_SIP_CALL_CODEC_PREF_LOCAL_SINGLE] = "local_single",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_SIP_CALL_CODEC_PREF_REMOTE] = "remote",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_SIP_CALL_CODEC_PREF_REMOTE_LIMIT] = "remote_limit",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_SIP_CALL_CODEC_PREF_REMOTE_SINGLE] = "remote_single",</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int incoming_call_offer_pref_handler(const struct aco_option *opt,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *var, void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_endpoint *endpoint = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < ARRAY_LEN(sip_call_codec_pref_strings); ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcmp(var->value, sip_call_codec_pref_strings[i])) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (i == AST_SIP_CALL_CODEC_PREF_LOCAL_LIMIT ||</span><br><span style="color: hsl(120, 100%, 40%);">+ i == AST_SIP_CALL_CODEC_PREF_REMOTE_LIMIT) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ endpoint->media.incoming_call_offer_pref = i;</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int incoming_call_offer_pref_to_str(const void *obj, const intptr_t *args, char **buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_sip_endpoint *endpoint = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ARRAY_IN_BOUNDS(endpoint->media.incoming_call_offer_pref, sip_call_codec_pref_strings)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *buf = ast_strdup(sip_call_codec_pref_strings[endpoint->media.incoming_call_offer_pref]);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void *sip_nat_hook_alloc(const char *name)</span><br><span> {</span><br><span> return ast_sorcery_generic_alloc(sizeof(struct ast_sip_nat_hook), NULL);</span><br><span>@@ -1952,6 +1993,8 @@</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "accept_multiple_sdp_answers", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.accept_multiple_sdp_answers));</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "suppress_q850_reason_headers", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, suppress_q850_reason_headers));</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "ignore_183_without_sdp", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, ignore_183_without_sdp));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "incoming_call_offer_pref", "local",</span><br><span style="color: hsl(120, 100%, 40%);">+ incoming_call_offer_pref_handler, incoming_call_offer_pref_to_str, NULL, 0, 0);</span><br><span> </span><br><span> if (ast_sip_initialize_sorcery_transport()) {</span><br><span> ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");</span><br><span>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c</span><br><span>index d652fc4..04dcb76 100644</span><br><span>--- a/res/res_pjsip_sdp_rtp.c</span><br><span>+++ b/res/res_pjsip_sdp_rtp.c</span><br><span>@@ -373,6 +373,80 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int apply_cap_to_bundled(struct ast_sip_session_media *session_media,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session_media *session_media_transport,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream *asterisk_stream, const struct ast_format_cap *joint)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!joint) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stream_set_formats(asterisk_stream, (struct ast_format_cap *)joint);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If this is a bundled stream then apply the payloads to RTP instance acting as transport to prevent conflicts */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (session_media_transport != session_media && session_media->bundled) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int index;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (index = 0; index < ast_format_cap_count(joint); ++index) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format *format = ast_format_cap_get_format(joint, index);</span><br><span style="color: hsl(120, 100%, 40%);">+ int rtp_code;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Ensure this payload is in the bundle group transport codecs, this purposely doesn't check the return value for</span><br><span style="color: hsl(120, 100%, 40%);">+ * things as the format is guaranteed to have a payload already.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session_media->rtp), 1, format, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_codecs_payload_set_rx(ast_rtp_instance_get_codecs(session_media_transport->rtp), rtp_code, format);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(format, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct ast_format_cap *set_incoming_call_offer_cap(</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session *session, struct ast_sip_session_media *session_media,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct pjmedia_sdp_media *stream)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_format_cap *incoming_call_offer_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format_cap *remote;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_rtp_codecs codecs = AST_RTP_CODECS_NULL_INIT;</span><br><span style="color: hsl(120, 100%, 40%);">+ int fmts = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ remote = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!remote) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to allocate %s incoming remote capabilities\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_codec_media_type2str(session_media->type));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Get the peer's capabilities*/</span><br><span style="color: hsl(120, 100%, 40%);">+ get_codecs(session, stream, &codecs, session_media);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_codecs_payload_formats(&codecs, remote, &fmts);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ incoming_call_offer_cap = ast_sip_session_build_incoming_call_offer_cap(</span><br><span style="color: hsl(120, 100%, 40%);">+ session, session_media, remote);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(remote, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!incoming_call_offer_cap) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_codecs_payloads_destroy(&codecs);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Setup rx payload type mapping to prefer the mapping</span><br><span style="color: hsl(120, 100%, 40%);">+ * from the peer that the RFC says we SHOULD use.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_codecs_payloads_xover(&codecs, &codecs, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_codecs_payloads_copy(&codecs,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_instance_get_codecs(session_media->rtp), session_media->rtp);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_codecs_payloads_destroy(&codecs);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return incoming_call_offer_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int set_caps(struct ast_sip_session *session,</span><br><span> struct ast_sip_session_media *session_media,</span><br><span> struct ast_sip_session_media *session_media_transport,</span><br><span>@@ -432,25 +506,7 @@</span><br><span> ast_rtp_codecs_payloads_copy(&codecs, ast_rtp_instance_get_codecs(session_media->rtp),</span><br><span> session_media->rtp);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_stream_set_formats(asterisk_stream, joint);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* If this is a bundled stream then apply the payloads to RTP instance acting as transport to prevent conflicts */</span><br><span style="color: hsl(0, 100%, 40%);">- if (session_media_transport != session_media && session_media->bundled) {</span><br><span style="color: hsl(0, 100%, 40%);">- int index;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (index = 0; index < ast_format_cap_count(joint); ++index) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_format *format = ast_format_cap_get_format(joint, index);</span><br><span style="color: hsl(0, 100%, 40%);">- int rtp_code;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Ensure this payload is in the bundle group transport codecs, this purposely doesn't check the return value for</span><br><span style="color: hsl(0, 100%, 40%);">- * things as the format is guaranteed to have a payload already.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">- rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session_media->rtp), 1, format, 0);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_rtp_codecs_payload_set_rx(ast_rtp_instance_get_codecs(session_media_transport->rtp), rtp_code, format);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(format, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ apply_cap_to_bundled(session_media, session_media_transport, asterisk_stream, joint);</span><br><span> </span><br><span> if (session->channel && ast_sip_session_is_pending_stream_default(session, asterisk_stream)) {</span><br><span> ast_channel_lock(session->channel);</span><br><span>@@ -1406,7 +1462,8 @@</span><br><span> /* If ICE support is enabled find all the needed attributes */</span><br><span> check_ice_support(session, session_media, stream);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (set_caps(session, session_media, session_media_transport, stream, 1, asterisk_stream)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (apply_cap_to_bundled(session_media, session_media_transport, asterisk_stream,</span><br><span style="color: hsl(120, 100%, 40%);">+ set_incoming_call_offer_cap(session, session_media, stream))) {</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index c1e89c5..5c5595d 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -466,6 +466,8 @@</span><br><span> </span><br><span> ast_free(session_media->mid);</span><br><span> ast_free(session_media->remote_mslabel);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(session_media->caps);</span><br><span> }</span><br><span> </span><br><span> struct ast_sip_session_media *ast_sip_session_media_state_add(struct ast_sip_session *session,</span><br><span>@@ -524,6 +526,12 @@</span><br><span> } else {</span><br><span> session_media->bundle_group = -1;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ session_media->caps = ast_sip_session_caps_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!session_media->caps) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(session_media, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> if (AST_VECTOR_REPLACE(&media_state->sessions, position, session_media)) {</span><br><span>diff --git a/res/res_pjsip_session/pjsip_session_caps.c b/res/res_pjsip_session/pjsip_session_caps.c</span><br><span>new file mode 100644</span><br><span>index 0000000..3f16d3e</span><br><span>--- /dev/null</span><br><span>+++ b/res/res_pjsip_session/pjsip_session_caps.c</span><br><span>@@ -0,0 +1,154 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Asterisk -- An open source telephony toolkit.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2020, Sangoma Technologies Corporation</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Kevin Harwell <kharwell@digium.com></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * See http://www.asterisk.org for more information about</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Asterisk project. Please do not directly contact</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the maintainers of this project for assistance;</span><br><span style="color: hsl(120, 100%, 40%);">+ * the project provides a web site, mailing lists and IRC</span><br><span style="color: hsl(120, 100%, 40%);">+ * channels for your use.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+ * the GNU General Public License Version 2. See the LICENSE file</span><br><span style="color: hsl(120, 100%, 40%);">+ * at the top of the source tree.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/astobj2.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/format.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/format_cap.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/logger.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <pjsip_ua.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/res_pjsip.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/res_pjsip_session.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/res_pjsip_session_caps.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_session_caps {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format_cap *incoming_call_offer_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void log_caps(int level, const char *file, int line, const char *function,</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *msg, enum ast_media_type type,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_format_cap *local, const struct ast_format_cap *remote,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_format_cap *joint)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *s1;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *s2;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *s3;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (level == __LOG_DEBUG && !DEBUG_ATLEAST(3)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ s1 = local ? ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ s2 = remote ? ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ s3 = joint ? ast_str_alloca(AST_FORMAT_CAP_NAMES_LEN) : NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(level, file, line, function, "%s '%s' capabilities -%s%s%s%s%s%s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ msg ? msg : "", ast_codec_media_type2str(type),</span><br><span style="color: hsl(120, 100%, 40%);">+ s1 ? " local: " : "", s1 ? ast_format_cap_get_names(local, &s1) : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ s2 ? " remote: " : "", s2 ? ast_format_cap_get_names(remote, &s2) : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ s3 ? " joint: " : "", s3 ? ast_format_cap_get_names(joint, &s3) : "");</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void sip_session_caps_destroy(void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session_caps *caps = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(caps->incoming_call_offer_cap);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_sip_session_caps *ast_sip_session_caps_alloc(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return ao2_alloc_options(sizeof(struct ast_sip_session_caps),</span><br><span style="color: hsl(120, 100%, 40%);">+ sip_session_caps_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_sip_session_set_incoming_call_offer_cap(struct ast_sip_session_caps *caps,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format_cap *cap)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(caps->incoming_call_offer_cap);</span><br><span style="color: hsl(120, 100%, 40%);">+ caps->incoming_call_offer_cap = ao2_bump(cap);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+const struct ast_format_cap *ast_sip_session_get_incoming_call_offer_cap(</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_sip_session_caps *caps)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return caps->incoming_call_offer_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+const struct ast_format_cap *ast_sip_session_build_incoming_call_offer_cap(</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_sip_session *session, const struct ast_sip_session_media *session_media,</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_format_cap *remote)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ enum ast_sip_call_codec_pref pref;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format_cap *joint;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format_cap *local;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ joint = session_media->caps->incoming_call_offer_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (joint) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * If the incoming call offer capabilities have been set elsewhere, e.g. dialplan</span><br><span style="color: hsl(120, 100%, 40%);">+ * then those take precedence.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ return joint;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ joint = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);</span><br><span style="color: hsl(120, 100%, 40%);">+ local = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!joint || !local) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to allocate %s incoming call offer capabilities\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_codec_media_type2str(session_media->type));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(joint);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(local);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pref = session->endpoint->media.incoming_call_offer_pref;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_append_from_cap(local, session->endpoint->media.codecs,</span><br><span style="color: hsl(120, 100%, 40%);">+ session_media->type);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pref < AST_SIP_CALL_CODEC_PREF_REMOTE) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_get_compatible(local, remote, joint); /* Prefer local */</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_get_compatible(remote, local, joint); /* Prefer remote */</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_format_cap_empty(joint)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ log_caps(LOG_NOTICE, "No joint incoming", session_media->type, local, remote, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(joint, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(local, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pref == AST_SIP_CALL_CODEC_PREF_LOCAL_SINGLE ||</span><br><span style="color: hsl(120, 100%, 40%);">+ pref == AST_SIP_CALL_CODEC_PREF_REMOTE_SINGLE ||</span><br><span style="color: hsl(120, 100%, 40%);">+ session->endpoint->preferred_codec_only) {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Save the most preferred one */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format *single = ast_format_cap_get_format(joint, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Remove all formats */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_remove_by_type(joint, AST_MEDIA_TYPE_UNKNOWN);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Put the most preferred one back */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_append(joint, single, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(single, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ log_caps(LOG_DEBUG, "Joint incoming", session_media->type, local, remote, joint);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(local, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_set_incoming_call_offer_cap(session_media->caps, joint);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return joint;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13842">change 13842</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13842"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I35e7a2a0c236cfb6bd9cdf89539f57a1ffefc76f </div>
<div style="display:none"> Gerrit-Change-Number: 13842 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>