[asterisk-commits] mjordan: trunk r397243 - in /trunk: CHANGES channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 21 08:41:13 CDT 2013


Author: mjordan
Date: Wed Aug 21 08:41:05 2013
New Revision: 397243

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397243
Log:
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)


Modified:
    trunk/CHANGES
    trunk/channels/chan_sip.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=397243&r1=397242&r2=397243
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Wed Aug 21 08:41:05 2013
@@ -553,6 +553,10 @@
    set of proxies by using a pre-loaded route-set defined by the Path headers in
    the REGISTER request. See Realtime updates for more configuration information.
 
+ * The SIP_CODEC family of variables may now specify more than one codec. Each
+   codec must be separated by a comma. The first codec specified is the
+   preferred codec for the offer. This allows a dialplan writer to specify both
+   audio and video codecs, e.g., Set(SIP_CODEC=ulaw,h264)
 
 Functions
 ------------------

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=397243&r1=397242&r2=397243
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Aug 21 08:41:05 2013
@@ -7350,35 +7350,57 @@
 	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;
-
-	ast_format_clear(&fmt);
+	const char *codec_list;
+	char *codec_list_copy;
+	struct ast_format_cap *original_jointcaps;
+	char *codec;
+	int first_codec = 1;
+
+	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");
-	}
-
-	if (!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 (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 */




More information about the asterisk-commits mailing list