[svn-commits] rmudgett: branch rmudgett/iax_fracks r420025 - /team/rmudgett/iax_fracks/chan...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 4 16:58:59 CDT 2014


Author: rmudgett
Date: Mon Aug  4 16:58:54 2014
New Revision: 420025

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=420025
Log:
chan_iax2: Fix preference order values to be compatible with older versions.

Modified:
    team/rmudgett/iax_fracks/channels/iax2/codec_pref.c

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=420025&r1=420024&r2=420025
==============================================================================
--- team/rmudgett/iax_fracks/channels/iax2/codec_pref.c (original)
+++ team/rmudgett/iax_fracks/channels/iax2/codec_pref.c Mon Aug  4 16:58:54 2014
@@ -314,29 +314,65 @@
 	}
 }
 
+/*!
+ * \brief Formats supported by IAX2.
+ *
+ * \note The order is important because the array index+1 values
+ * go out over the wire.
+ */
+static const uint64_t iax2_supported_formats[] = {
+	AST_FORMAT_G723,
+	AST_FORMAT_GSM,
+	AST_FORMAT_ULAW,
+	AST_FORMAT_ALAW,
+	AST_FORMAT_G726,
+	AST_FORMAT_ADPCM,
+	AST_FORMAT_SLIN,
+	AST_FORMAT_LPC10,
+	AST_FORMAT_G729,
+	AST_FORMAT_SPEEX,
+	AST_FORMAT_SPEEX16,
+	AST_FORMAT_ILBC,
+	AST_FORMAT_G726_AAL2,
+	AST_FORMAT_G722,
+	AST_FORMAT_SLIN16,
+	AST_FORMAT_JPEG,
+	AST_FORMAT_PNG,
+	AST_FORMAT_H261,
+	AST_FORMAT_H263,
+	AST_FORMAT_H263P,
+	AST_FORMAT_H264,
+	AST_FORMAT_MP4,
+	AST_FORMAT_T140_RED,
+	AST_FORMAT_T140,
+	AST_FORMAT_SIREN7,
+	AST_FORMAT_SIREN14,
+	AST_FORMAT_TESTLAW,
+	AST_FORMAT_G719,
+	/* ONLY ADD TO THE END OF THIS LIST */
+};
+
 uint64_t iax2_codec_pref_order_value_to_format_bitfield(int order_value)
 {
-	if (!order_value) {
+	if (order_value < 1 || ARRAY_LEN(iax2_supported_formats) < order_value) {
 		return 0;
 	}
 
-	return 1ULL << (order_value - 1);
+	return iax2_supported_formats[order_value - 1];
 }
 
 int iax2_codec_pref_format_bitfield_to_order_value(uint64_t bitfield)
 {
-	int format_index = 1;
-
-	if (!bitfield) {
-		return 0;
-	}
-
-	while (bitfield > 1) {
-		bitfield = bitfield >> 1;
-		format_index++;
-	}
-
-	return format_index;
+	int idx;
+
+	if (bitfield) {
+		for (idx = 0; idx < ARRAY_LEN(iax2_supported_formats); ++idx) {
+			if (iax2_supported_formats[idx] == bitfield) {
+				return idx + 1;
+			}
+		}
+	}
+	return 0;
 }
 
 /*!
@@ -356,6 +392,10 @@
 	int x;
 
 	format_index = iax2_codec_pref_format_bitfield_to_order_value(bitfield);
+	if (!format_index) {
+		return;
+	}
+
 	codec_pref_remove(pref, format_index);
 
 	for (x = 0; x < ARRAY_LEN(pref->order); ++x) {
@@ -390,9 +430,12 @@
 	if (!bitfield) {
 		return;
 	}
+	format_index = iax2_codec_pref_format_bitfield_to_order_value(bitfield);
+	if (!format_index) {
+		return;
+	}
 
 	/* Now find any existing occurrence, or the end */
-	format_index = iax2_codec_pref_format_bitfield_to_order_value(bitfield);
 	for (x = 0; x < ARRAY_LEN(pref->order); ++x) {
 		if (!pref->order[x] || pref->order[x] == format_index)
 			break;




More information about the svn-commits mailing list