summaryrefslogtreecommitdiff
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-08-21 13:41:05 +0000
committerMatthew Jordan <mjordan@digium.com>2013-08-21 13:41:05 +0000
commite85dd769452ad7d27e22bd14405e93f9de27dd7a (patch)
tree98ba284b77034fb15e6b4a4fb43e21cdf115a2ed /channels/chan_sip.c
parentc7c8eb5ea49f60038d201b0d3123a32d69d5b2a2 (diff)
Allow the SIP_CODEC family of variables to specify more than one codec
The SIP_CODEC family of variables let you set the preferred codec to be offered on an outbound INVITE request. However, for video calls, you need to be able to set both the audio and video codecs to be offered. This patch lets the SIP_CODEC variables accept a comma delineated list of codecs. The first codec in the list is set as the preferred codec; additional codecs are still offered however. This lets a dialplan writer set both audio and video codecs, e.g., Set(SIP_CODEC=ulaw,h264) Note that this feature was written by both Dennis Guse and Frank Haase Review: https://reviewboard.asterisk.org/r/2728 (closes issue ASTERISK-21976) Reported by: Denis Guse Tested by: mjordan, sysreq patches: patch-channels-chan__sip.c-393919 uploaded by dennis.guse (license 6513) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397243 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 2e7615ae7..519f1dc88 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -7350,35 +7350,57 @@ static int sip_hangup(struct ast_channel *ast)
return 0;
}
-/*! \brief Try setting codec suggested by the SIP_CODEC channel variable */
+/*! \brief Try setting the codecs suggested by the SIP_CODEC channel variable */
static void try_suggested_sip_codec(struct sip_pvt *p)
{
struct ast_format fmt;
- const char *codec;
+ const char *codec_list;
+ char *codec_list_copy;
+ struct ast_format_cap *original_jointcaps;
+ char *codec;
+ int first_codec = 1;
- ast_format_clear(&fmt);
+ char *strtok_ptr;
if (p->outgoing_call) {
- codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND");
- } else if (!(codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) {
- codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC");
+ codec_list = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND");
+ } else if (!(codec_list = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) {
+ codec_list = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC");
}
- if (!codec)
+ if (ast_strlen_zero(codec_list)) {
return;
+ }
- ast_getformatbyname(codec, &fmt);
- if (fmt.id) {
- ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec);
- if (ast_format_cap_iscompatible(p->jointcaps, &fmt)) {
- ast_format_cap_set(p->jointcaps, &fmt);
- ast_format_cap_set(p->caps, &fmt);
- } else
- ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n");
- } else
- ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec);
+ codec_list_copy = ast_strdupa(codec_list);
+ original_jointcaps = ast_format_cap_dup(p->jointcaps);
+
+ for (codec = strtok_r(codec_list_copy, ",", &strtok_ptr); codec; codec = strtok_r(NULL, ",", &strtok_ptr)) {
+ codec = ast_strip(codec);
+
+ if (!ast_getformatbyname(codec, &fmt)) {
+ ast_log(AST_LOG_NOTICE, "Ignoring ${SIP_CODEC*} variable because of unrecognized/not configured codec %s (check allow/disallow in sip.conf)\n", codec);
+ continue;
+ }
+ if (ast_format_cap_iscompatible(original_jointcaps, &fmt)) {
+ if (first_codec) {
+ ast_verb(4, "Set codec to '%s' for this call because of ${SIP_CODEC*} variable\n", codec);
+ ast_format_cap_set(p->jointcaps, &fmt);
+ ast_format_cap_set(p->caps, &fmt);
+ first_codec = 0;
+ } else {
+ ast_verb(4, "Add codec to '%s' for this call because of ${SIP_CODEC*} variable\n", codec);
+ ast_format_cap_add(p->jointcaps, &fmt);
+ ast_format_cap_add(p->caps, &fmt);
+ }
+ } else {
+ ast_log(AST_LOG_NOTICE, "Ignoring ${SIP_CODEC*} variable because it is not shared by both ends: %s\n", codec);
+ }
+ }
+ ast_format_cap_destroy(original_jointcaps);
return;
-}
+ }
+
/*! \brief sip_answer: Answer SIP call , send 200 OK on Invite
* Part of PBX interface */