[svn-commits] rmudgett: branch rmudgett/iax_fracks r419912 - in /team/rmudgett/iax_fracks/c...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 1 20:31:37 CDT 2014


Author: rmudgett
Date: Fri Aug  1 20:31:33 2014
New Revision: 419912

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419912
Log:
chan_iax2: Restore iax2_codec_pref_to_cap().  Found to users that were effectively inlining it.

Modified:
    team/rmudgett/iax_fracks/channels/chan_iax2.c
    team/rmudgett/iax_fracks/channels/iax2/codec_pref.c
    team/rmudgett/iax_fracks/channels/iax2/include/codec_pref.h

Modified: team/rmudgett/iax_fracks/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/chan_iax2.c?view=diff&rev=419912&r1=419911&r2=419912
==============================================================================
--- team/rmudgett/iax_fracks/channels/chan_iax2.c (original)
+++ team/rmudgett/iax_fracks/channels/chan_iax2.c Fri Aug  1 20:31:33 2014
@@ -1896,25 +1896,13 @@
 static int iax2_parse_allow_disallow(struct iax2_codec_pref *pref, iax2_format *formats, const char *list, int allowing)
 {
 	int res, i;
-	struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
-
-	if (!cap) {
+	struct ast_format_cap *cap;
+
+	/* We want to add the formats to the cap in the preferred order */
+	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!cap || iax2_codec_pref_to_cap(pref, cap)) {
+		ao2_cleanup(cap);
 		return 1;
-	}
-
-	/* We want to add the formats to the cap in the preferred order */
-	for (i = 0; i < ARRAY_LEN(pref->order); ++i) {
-		uint64_t pref_bitfield;
-
-		pref_bitfield = iax2_codec_pref_order_value_to_format_bitfield(pref->order[i]);
-		if (!pref_bitfield) {
-			break;
-		}
-
-		if (iax2_format_compatibility_bitfield2cap(pref_bitfield, cap)) {
-			ao2_ref(cap, -1);
-			return 1;
-		}
 	}
 
 	res = ast_format_cap_update_by_allow_disallow(cap, list, allowing);
@@ -3843,17 +3831,15 @@
 		ast_cli(a->fd, "  Addr->IP     : %s Port %s\n",  str_addr ? str_addr : "(Unspecified)", str_port);
 		ast_cli(a->fd, "  Defaddr->IP  : %s Port %s\n", str_defaddr, str_defport);
 		ast_cli(a->fd, "  Username     : %s\n", peer->username);
-		ast_cli(a->fd, "  Codecs       : ");
-		ast_cli(a->fd, "%s\n", iax2_getformatname_multiple(peer->capability, &codec_buf));
-
-		ast_cli(a->fd, "  Codec Order  : ");
-		if (iax2_codec_pref_string(&peer->prefs, cbuf, sizeof(cbuf)) != -1) {
-			ast_cli(a->fd, "%s\n", cbuf);
-		}
-
-		ast_cli(a->fd, "  Status       : ");
+		ast_cli(a->fd, "  Codecs       : %s\n", iax2_getformatname_multiple(peer->capability, &codec_buf));
+
+		if (iax2_codec_pref_string(&peer->prefs, cbuf, sizeof(cbuf)) < 0) {
+			strcpy(cbuf, "Error"); /* Safe */
+		}
+		ast_cli(a->fd, "  Codec Order  : %s\n", cbuf);
+
 		peer_status(peer, status, sizeof(status));
-		ast_cli(a->fd, "%s\n",status);
+		ast_cli(a->fd, "  Status       : %s\n", status);
 		ast_cli(a->fd, "  Qualify      : every %dms when OK, every %dms when UNREACHABLE (sample smoothing %s)\n", peer->pokefreqok, peer->pokefreqnotok, peer->smoothing ? "On" : "Off");
 		ast_cli(a->fd, "\n");
 		peer_unref(peer);

Modified: team/rmudgett/iax_fracks/channels/iax2/codec_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/iax2/codec_pref.c?view=diff&rev=419912&r1=419911&r2=419912
==============================================================================
--- team/rmudgett/iax_fracks/channels/iax2/codec_pref.c (original)
+++ team/rmudgett/iax_fracks/channels/iax2/codec_pref.c Fri Aug  1 20:31:33 2014
@@ -90,6 +90,29 @@
 	return *result;
 }
 
+int iax2_codec_pref_to_cap(struct iax2_codec_pref *pref, struct ast_format_cap *cap)
+{
+	int idx;
+
+	for (idx = 0; idx < ARRAY_LEN(pref->order); ++idx) {
+		uint64_t pref_bitfield;
+		struct ast_format *pref_format;
+
+		pref_bitfield = iax2_codec_pref_order_value_to_format_bitfield(pref->order[idx]);
+		if (!pref_bitfield) {
+			break;
+		}
+
+		pref_format = ast_format_compatibility_bitfield2format(pref_bitfield);
+		if (pref_format) {
+			if (ast_format_cap_append(cap, pref_format, pref->framing[idx])) {
+				return -1;
+			}
+		}
+	}
+	return 0;
+}
+
 int iax2_codec_pref_best_bitfield2cap(uint64_t bitfield, struct iax2_codec_pref *prefs, struct ast_format_cap *cap)
 {
 	uint64_t best_bitfield;
@@ -159,13 +182,9 @@
 int iax2_codec_pref_string(struct iax2_codec_pref *pref, char *buf, size_t size)
 {
 	int x;
-	struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	struct ast_format_cap *cap;
 	size_t total_len;
 	char *cur;
-
-	if (!cap) {
-		return -1;
-	}
 
 	/* This function is useless if you have less than a 6 character buffer.
 	 * '(...)' is six characters. */
@@ -174,21 +193,15 @@
 	}
 
 	/* Convert the preferences into a format cap so that we can read the format names */
-	for (x = 0; x < ARRAY_LEN(pref->order); ++x) {
-		uint64_t pref_bitfield;
-
-		pref_bitfield = iax2_codec_pref_order_value_to_format_bitfield(pref->order[x]);
-		if (!pref_bitfield) {
-			break;
-		}
-
-		iax2_format_compatibility_bitfield2cap(pref_bitfield, cap);
+	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!cap || iax2_codec_pref_to_cap(pref, cap)) {
+		strcpy(buf, "(...)"); /* Safe */
+		ao2_cleanup(cap);
+		return -1;
 	}
 
 	/* We know that at a minimum, 3 characters are used - (, ), and \0 */
 	total_len = size - 3;
-
-	memset(buf, 0, size);
 
 	/* This character has already been accounted for total_len purposes */
 	buf[0] = '(';

Modified: team/rmudgett/iax_fracks/channels/iax2/include/codec_pref.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/iax2/include/codec_pref.h?view=diff&rev=419912&r1=419911&r2=419912
==============================================================================
--- team/rmudgett/iax_fracks/channels/iax2/include/codec_pref.h (original)
+++ team/rmudgett/iax_fracks/channels/iax2/include/codec_pref.h Fri Aug  1 20:31:33 2014
@@ -71,6 +71,19 @@
 struct ast_format *iax2_codec_pref_index(struct iax2_codec_pref *pref, int index, struct ast_format **result);
 
 /*!
+ * \brief Convert a preference structure to a capabilities structure.
+ *
+ * \param pref Formats in preference order to build the capabilities.
+ * \param cap Capabilities structure to place formats into
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ *
+ * \note If failure occurs the capabilities structure may contain a partial set of formats
+ */
+int iax2_codec_pref_to_cap(struct iax2_codec_pref *pref, struct ast_format_cap *cap);
+
+/*!
  * \brief Convert a bitfield to a format capabilities structure in the "best" order.
  *
  * \param bitfield The bitfield for the media formats




More information about the svn-commits mailing list