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