[asterisk-commits] rmudgett: branch 13 r434617 - in /branches/13: bridges/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 10 11:37:23 CDT 2015


Author: rmudgett
Date: Fri Apr 10 11:37:20 2015
New Revision: 434617

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=434617
Log:
bridge_softmix.c,channel.c: Minor code simplification and cleanup.

* Made code easier to follow in bridge_softmix.c:analyse_softmix_stats()
and made some debug messages more helpful.

* Made some debug and warning messages more helpful in
channel.c:set_format().

Review: https://reviewboard.asterisk.org/r/4607/

Modified:
    branches/13/bridges/bridge_softmix.c
    branches/13/main/channel.c

Modified: branches/13/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/bridges/bridge_softmix.c?view=diff&rev=434617&r1=434616&r2=434617
==============================================================================
--- branches/13/bridges/bridge_softmix.c (original)
+++ branches/13/bridges/bridge_softmix.c Fri Apr 10 11:37:20 2015
@@ -144,11 +144,11 @@
 	unsigned int sample_rates[16];
 	/*! Each index represents the number of channels using the same index in the sample_rates array.  */
 	unsigned int num_channels[16];
-	/*! the number of channels above the internal sample rate */
+	/*! The number of channels above the internal sample rate */
 	unsigned int num_above_internal_rate;
-	/*! the number of channels at the internal sample rate */
+	/*! The number of channels at the internal sample rate */
 	unsigned int num_at_internal_rate;
-	/*! the absolute highest sample rate supported by any channel in the bridge */
+	/*! The absolute highest sample rate preferred by any channel in the bridge */
 	unsigned int highest_supported_rate;
 	/*! Is the sample rate locked by the bridge, if so what is that rate.*/
 	unsigned int locked_rate;
@@ -753,6 +753,7 @@
 		stats->num_at_internal_rate++;
 	}
 }
+
 /*!
  * \internal
  * \brief Analyse mixing statistics and change bridges internal rate
@@ -764,7 +765,9 @@
 static unsigned int analyse_softmix_stats(struct softmix_stats *stats, struct softmix_bridge_data *softmix_data)
 {
 	int i;
-	/* Re-adjust the internal bridge sample rate if
+
+	/*
+	 * Re-adjust the internal bridge sample rate if
 	 * 1. The bridge's internal sample rate is locked in at a sample
 	 *    rate other than the current sample rate being used.
 	 * 2. two or more channels support a higher sample rate
@@ -774,9 +777,9 @@
 		/* if the rate is locked by the bridge, only update it if it differs
 		 * from the current rate we are using. */
 		if (softmix_data->internal_rate != stats->locked_rate) {
+			ast_debug(1, "Locking at new rate.  Bridge changed from %u to %u.\n",
+				softmix_data->internal_rate, stats->locked_rate);
 			softmix_data->internal_rate = stats->locked_rate;
-			ast_debug(1, "Bridge is locked in at sample rate %u\n",
-				softmix_data->internal_rate);
 			return 1;
 		}
 	} else if (stats->num_above_internal_rate >= 2) {
@@ -788,42 +791,47 @@
 			if (stats->num_channels[i]) {
 				break;
 			}
-			/* best_rate starts out being the first sample rate
-			 * greater than the internal sample rate that 2 or
-			 * more channels support. */
-			if (stats->num_channels[i] >= 2 && (best_index == -1)) {
-				best_rate = stats->sample_rates[i];
-				best_index = i;
-			/* If it has been detected that multiple rates above
-			 * the internal rate are present, compare those rates
-			 * to each other and pick the highest one two or more
-			 * channels support. */
-			} else if (((best_index != -1) &&
-				(stats->num_channels[i] >= 2) &&
-				(stats->sample_rates[best_index] < stats->sample_rates[i]))) {
-				best_rate = stats->sample_rates[i];
-				best_index = i;
-			/* It is possible that multiple channels exist with native sample
-			 * rates above the internal sample rate, but none of those channels
-			 * have the same rate in common.  In this case, the lowest sample
-			 * rate among those channels is picked. Over time as additional
-			 * statistic runs are made the internal sample rate number will
-			 * adjust to the most optimal sample rate, but it may take multiple
-			 * iterations. */
+			if (2 <= stats->num_channels[i]) {
+				/* Two or more channels support this rate. */
+				if (best_index == -1
+					|| stats->sample_rates[best_index] < stats->sample_rates[i]) {
+					/*
+					 * best_rate starts out being the first sample rate
+					 * greater than the internal sample rate that two or
+					 * more channels support.
+					 *
+					 * or
+					 *
+					 * There are multiple rates above the internal rate
+					 * and this rate is higher than the previous rate two
+					 * or more channels support.
+					 */
+					best_rate = stats->sample_rates[i];
+					best_index = i;
+				}
 			} else if (best_index == -1) {
+				/*
+				 * It is possible that multiple channels exist with native sample
+				 * rates above the internal sample rate, but none of those channels
+				 * have the same rate in common.  In this case, the lowest sample
+				 * rate among those channels is picked. Over time as additional
+				 * statistic runs are made the internal sample rate number will
+				 * adjust to the most optimal sample rate, but it may take multiple
+				 * iterations.
+				 */
 				best_rate = MIN(best_rate, stats->sample_rates[i]);
 			}
 		}
 
-		ast_debug(1, "Bridge changed from %u To %u\n",
+		ast_debug(1, "Multiple above internal rate.  Bridge changed from %u to %u.\n",
 			softmix_data->internal_rate, best_rate);
 		softmix_data->internal_rate = best_rate;
 		return 1;
 	} else if (!stats->num_at_internal_rate && !stats->num_above_internal_rate) {
 		/* In this case, the highest supported rate is actually lower than the internal rate */
+		ast_debug(1, "All below internal rate.  Bridge changed from %u to %u.\n",
+			softmix_data->internal_rate, stats->highest_supported_rate);
 		softmix_data->internal_rate = stats->highest_supported_rate;
-		ast_debug(1, "Bridge changed from %u to %u\n",
-			softmix_data->internal_rate, stats->highest_supported_rate);
 		return 1;
 	}
 	return 0;

Modified: branches/13/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/channel.c?view=diff&rev=434617&r1=434616&r2=434617
==============================================================================
--- branches/13/main/channel.c (original)
+++ branches/13/main/channel.c Fri Apr 10 11:37:20 2015
@@ -5337,15 +5337,16 @@
 		res = ast_translator_best_choice(cap_native, cap_set, &best_native_fmt, &best_set_fmt);
 	}
 	if (res < 0) {
-		struct ast_str *codec_from = ast_str_alloca(64);
-		struct ast_str *codec_to = ast_str_alloca(64);
-
-		ast_format_cap_get_names(cap_native, &codec_from);
+		struct ast_str *codec_native = ast_str_alloca(256);
+		struct ast_str *codec_set = ast_str_alloca(256);
+
+		ast_format_cap_get_names(cap_native, &codec_native);
 		ast_channel_unlock(chan);
-		ast_format_cap_get_names(cap_set, &codec_to);
-
-		ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n",
-			ast_str_buffer(codec_from), ast_str_buffer(codec_to));
+		ast_format_cap_get_names(cap_set, &codec_set);
+
+		ast_log(LOG_WARNING, "Unable to find a codec translation path: %s -> %s\n",
+			ast_str_buffer(direction ? codec_set : codec_native),
+			ast_str_buffer(direction ? codec_native : codec_set));
 		return -1;
 	}
 
@@ -5389,10 +5390,11 @@
 		access->set_format(chan, best_set_fmt);
 		access->set_rawformat(chan, best_native_fmt);
 
-		ast_debug(1, "Set channel %s to %s format %s\n",
+		ast_debug(1, "Channel %s setting %s format path: %s -> %s\n",
 			ast_channel_name(chan),
 			access->direction,
-			ast_format_get_name(best_set_fmt));
+			ast_format_get_name(direction ? best_set_fmt : best_native_fmt),
+			ast_format_get_name(direction ? best_native_fmt : best_set_fmt));
 	}
 
 	ast_channel_unlock(chan);




More information about the asterisk-commits mailing list