[asterisk-commits] branch 1.2 r11089 - /branches/1.2/translate.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Feb 24 22:08:57 MST 2006


Author: kpfleming
Date: Fri Feb 24 23:08:46 2006
New Revision: 11089

URL: http://svn.digium.com/view/asterisk?rev=11089&view=rev
Log:
factor the number of translation steps required into translation path decisions, so that equal cost paths that require fewer translations are preferred

Modified:
    branches/1.2/translate.c

Modified: branches/1.2/translate.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/translate.c?rev=11089&r1=11088&r2=11089&view=diff
==============================================================================
--- branches/1.2/translate.c (original)
+++ branches/1.2/translate.c Fri Feb 24 23:08:46 2006
@@ -454,14 +454,14 @@
 	int bestdst = 0;
 	int cur = 1;
 	int besttime = INT_MAX;
+	int beststeps = INT_MAX;
 	int common;
 
 	if ((common = (*dst) & (*srcs))) {
 		/* We have a format in common */
-		for (y=0; y < MAX_FORMAT; y++) {
+		for (y = 0; y < MAX_FORMAT; y++) {
 			if (cur & common) {
 				/* This is a common format to both.  Pick it if we don't have one already */
-				besttime = 0;
 				bestdst = cur;
 				best = cur;
 			}
@@ -470,25 +470,38 @@
 	} else {
 		/* We will need to translate */
 		ast_mutex_lock(&list_lock);
-		for (y=0; y < MAX_FORMAT; y++) {
-			if (cur & *dst)
-				for (x=0; x < MAX_FORMAT; x++) {
-					if ((*srcs & (1 << x)) &&			/* x is a valid source format */
-					    tr_matrix[x][y].step &&			/* There's a step */
-					    (tr_matrix[x][y].cost < besttime)) {	/* It's better than what we have so far */
-						best = 1 << x;
-						bestdst = cur;
-						besttime = tr_matrix[x][y].cost;
-					}
+		for (y = 0; y < MAX_FORMAT; y++) {
+			if (!(cur & *dst))
+				continue;
+
+			for (x = 0; x < MAX_FORMAT; x++) {
+				if ((*srcs & (1 << x)) &&			/* x is a valid source format */
+				    tr_matrix[x][y].step) {			/* There's a step */
+					if (tr_matrix[x][y].cost > besttime)
+						continue;			/* It's more expensive, skip it */
+					
+					if (tr_matrix[x][y].cost == besttime &&
+					    tr_matrix[x][y].multistep >= beststeps)
+						continue; 			/* It requires the same (or more) steps,
+										   skip it */
+
+					/* It's better than what we have so far */
+					best = 1 << x;
+					bestdst = cur;
+					besttime = tr_matrix[x][y].cost;
+					beststeps = tr_matrix[x][y].multistep;
 				}
+			}
 			cur = cur << 1;
 		}
 		ast_mutex_unlock(&list_lock);
 	}
+
 	if (best > -1) {
 		*srcs = best;
 		*dst = bestdst;
 		best = 0;
 	}
+
 	return best;
 }



More information about the asterisk-commits mailing list