[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step2 r299395 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 21 17:44:31 UTC 2010


Author: dvossel
Date: Tue Dec 21 11:44:27 2010
New Revision: 299395

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299395
Log:
Build translators based on table cost and computational cost

Modified:
    team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c
    team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c
    team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c
    team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h
    team/dvossel/fixtheworld_phase1_step2/main/translate.c

Modified: team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c?view=diff&rev=299395&r1=299394&r2=299395
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c Tue Dec 21 11:44:27 2010
@@ -288,7 +288,7 @@
 	.name = "adpcmtolin",
 	.srcfmt = AST_FORMAT_ADPCM,
 	.dstfmt = AST_FORMAT_SLINEAR,
-	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.framein = adpcmtolin_framein,
 	.sample = adpcm_sample,
 	.desc_size = sizeof(struct adpcm_decoder_pvt),
@@ -300,7 +300,7 @@
 	.name = "lintoadpcm",
 	.srcfmt = AST_FORMAT_SLINEAR,
 	.dstfmt = AST_FORMAT_ADPCM,
-	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.framein = lintoadpcm_framein,
 	.frameout = lintoadpcm_frameout,
 	.sample = slin8_sample,

Modified: team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c?view=diff&rev=299395&r1=299394&r2=299395
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c Tue Dec 21 11:44:27 2010
@@ -75,7 +75,7 @@
 	.name = "alawtolin",
 	.srcfmt = AST_FORMAT_ALAW,
 	.dstfmt = AST_FORMAT_SLINEAR,
-	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.framein = alawtolin_framein,
 	.sample = alaw_sample,
 	.buffer_samples = BUFFER_SAMPLES,
@@ -86,7 +86,7 @@
 	"lintoalaw",
 	.srcfmt = AST_FORMAT_SLINEAR,
 	.dstfmt = AST_FORMAT_ALAW,
-	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.framein = lintoalaw_framein,
 	.sample = slin8_sample,
 	.buffer_samples = BUFFER_SAMPLES,

Modified: team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c?view=diff&rev=299395&r1=299394&r2=299395
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c Tue Dec 21 11:44:27 2010
@@ -332,7 +332,7 @@
 	.name = "speextolin", 
 	.srcfmt = AST_FORMAT_SPEEX,
 	.dstfmt =  AST_FORMAT_SLINEAR,
-	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.newpvt = speextolin_new,
 	.framein = speextolin_framein,
 	.destroy = speextolin_destroy,
@@ -347,7 +347,7 @@
 	.name = "lintospeex", 
 	.srcfmt = AST_FORMAT_SLINEAR,
 	.dstfmt = AST_FORMAT_SPEEX,
-	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.newpvt = lintospeex_new,
 	.framein = lintospeex_framein,
 	.frameout = lintospeex_frameout,
@@ -362,7 +362,7 @@
 	.name = "speexwbtolin16", 
 	.srcfmt = AST_FORMAT_SPEEX16,
 	.dstfmt =  AST_FORMAT_SLINEAR16,
-	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.newpvt = speexwbtolin16_new,
 	.framein = speextolin_framein,
 	.destroy = speextolin_destroy,
@@ -377,7 +377,7 @@
 	.name = "lin16tospeexwb", 
 	.srcfmt = AST_FORMAT_SLINEAR16,
 	.dstfmt = AST_FORMAT_SPEEX16,
-	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
+	.table_cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.newpvt = lin16tospeexwb_new,
 	.framein = lintospeex_framein,
 	.frameout = lintospeex_frameout,

Modified: team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h?view=diff&rev=299395&r1=299394&r2=299395
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h Tue Dec 21 11:44:27 2010
@@ -114,8 +114,11 @@
 	                                        *   converted to index during registration) */
 	format_t dstfmt;                       /*!< Destination format (note: bit position,
 	                                        *   converted to index during registration) */
-	int cost;                               /*!< Cost value associated with this translator based
-	                                        *   on translation cost table*/
+	int table_cost;                        /*!< Cost value associated with this translator based
+	                                        *   on translation cost table. */
+	int comp_cost;                         /*!< Cost value associated with this translator based
+	                                        *   on computation time. This cost value is computed based
+											*   on the time required to translate sample data. */
 
 	int (*newpvt)(struct ast_trans_pvt *); /*!< initialize private data 
                                             *   associated with the translator */

Modified: team/dvossel/fixtheworld_phase1_step2/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/main/translate.c?view=diff&rev=299395&r1=299394&r2=299395
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/translate.c Tue Dec 21 11:44:27 2010
@@ -45,23 +45,10 @@
 /*! \brief the list of translators */
 static AST_RWLIST_HEAD_STATIC(translators, ast_translator);
 
-
-/*! \brief these values indicate how a translation path will affect the sample rate
- *
- *  \note These must stay in this order.  They are ordered by most optimal selection first.
- */
-enum path_samp_change {
-	RATE_CHANGE_NONE = 0, /*!< path uses the same sample rate consistently */
-	RATE_CHANGE_UPSAMP = 1, /*!< path will up the sample rate during a translation */
-	RATE_CHANGE_DOWNSAMP = 2, /*!< path will have to down the sample rate during a translation. */
-	RATE_CHANGE_UPSAMP_DOWNSAMP = 3, /*!< path will both up and down the sample rate during translation */
-};
-
 struct translator_path {
-	struct ast_translator *step;	/*!< Next step translator */
-	unsigned int cost;		/*!< Complete cost to destination */
-	unsigned int multistep;		/*!< Multiple conversions required for this translation */
-	enum path_samp_change rate_change; /*!< does this path require a sample rate change, if so what kind. */
+	struct ast_translator *step;       /*!< Next step translator */
+	unsigned int table_cost;           /*!< Complete table cost to destination */
+	unsigned int multistep;            /*!< Multiple conversions required for this translation */
 };
 
 /*! \brief a matrix that, for any pair of supported formats,
@@ -75,9 +62,6 @@
  * this structure.
  */
 static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT];
-
-
-static int generate_cost_val(format_t src, format_t dst);
 
 /*! \todo
  * TODO: sample frames for each supported input format.
@@ -359,8 +343,15 @@
 	return out;
 }
 
-/*! \brief compute the cost of a single translation step */
-static void calc_cost(struct ast_translator *t, int seconds)
+/*!
+ * \internal
+ *
+* \brief Compute the computational cost of a single translation step.
+ *
+ * \note This function is only used to decide which translation path to
+ * use between two translators with identical src and dst formats.
+ */
+static void generate_computational_cost(struct ast_translator *t, int seconds)
 {
 	int num_samples = 0;
 	struct ast_trans_pvt *pvt;
@@ -371,18 +362,18 @@
 
 	if (!seconds)
 		seconds = 1;
-	
+
 	/* If they don't make samples, give them a terrible score */
 	if (!t->sample) {
 		ast_log(LOG_WARNING, "Translator '%s' does not produce sample frames.\n", t->name);
-		t->cost = 999999;
+		t->comp_cost = 999999;
 		return;
 	}
 
 	pvt = newpvt(t);
 	if (!pvt) {
 		ast_log(LOG_WARNING, "Translator '%s' appears to be broken and will probably fail.\n", t->name);
-		t->cost = 999999;
+		t->comp_cost = 999999;
 		return;
 	}
 
@@ -394,7 +385,7 @@
 		if (!f) {
 			ast_log(LOG_WARNING, "Translator '%s' failed to produce a sample frame.\n", t->name);
 			destroy(pvt);
-			t->cost = 999999;
+			t->comp_cost = 999999;
 			return;
 		}
 		framein(pvt, f);
@@ -412,28 +403,76 @@
 
 	destroy(pvt);
 
-	t->cost = cost / seconds;
-
-	if (!t->cost)
-		t->cost = 1;
-}
-
-static enum path_samp_change get_rate_change_result(format_t src, format_t dst)
+	t->comp_cost = cost / seconds;
+
+	if (!t->comp_cost)
+		t->comp_cost = 1;
+}
+
+/*!
+ * \internal
+ *
+ * \brief If no table cost value was pre set by the translator.  An attempt is made to
+ * automatically generate that cost value from the cost table based on our src and
+ * dst formats.
+ *
+ * \note This function allows older translators built before the translation cost
+ * changed away from using onely computational time to continue to be registered
+ * correctly.
+ *
+ * \note This function is safe to use on any formats that used to be defined in the
+ * first 32 bits of the old bit field codec representation.
+ *
+ * \retval Table Cost value greater than 0.
+ * \retval 0 on error.
+ */
+static int generate_table_cost(format_t src, format_t dst)
 {
 	int src_rate = ast_format_rate(src);
+	int src_ll = 0;
 	int dst_rate = ast_format_rate(dst);
-
-	/* if src rate is less than dst rate, a sample upgrade is required */
-	if (src_rate < dst_rate) {
-		return RATE_CHANGE_UPSAMP;
-	}
-
-	/* if src rate is larger than dst rate, a downgrade is required */
-	if (src_rate > dst_rate) {
-		return RATE_CHANGE_DOWNSAMP;
-	}
-
-	return RATE_CHANGE_NONE;
+	int dst_ll = 0;
+
+	if (!(src & AST_FORMAT_AUDIO_MASK) || !(src & AST_FORMAT_AUDIO_MASK)) {
+		/* this old method of generating table cost is limited to audio. */
+		return 0;
+	}
+	if ((src == AST_FORMAT_SLINEAR) || (src == AST_FORMAT_SLINEAR16)) {
+		src_ll = 1;
+	}
+	if ((dst == AST_FORMAT_SLINEAR) || (dst == AST_FORMAT_SLINEAR16)) {
+		dst_ll = 1;
+	}
+
+	if (src_ll) {
+		if (dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LL_LL_ORIGSAMP;
+		} else if (!dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LL_LY_ORIGSAMP;
+		} else if (dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LL_LL_UPSAMP;
+		} else if (!dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LL_LY_UPSAMP;
+		} else if (dst_ll && (src_rate > dst_rate)) {
+			return AST_TRANS_COST_LL_LL_DOWNSAMP;
+		} else {
+			return AST_TRANS_COST_LL_LY_DOWNSAMP;
+		}
+	} else {
+		if (dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LY_LL_ORIGSAMP;
+		} else if (!dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LY_LY_ORIGSAMP;
+		} else if (dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LY_LL_UPSAMP;
+		} else if (!dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LY_LY_UPSAMP;
+		} else if (dst_ll && (src_rate > dst_rate)) {
+			return AST_TRANS_COST_LY_LL_DOWNSAMP;
+		} else {
+			return AST_TRANS_COST_LY_LY_DOWNSAMP;
+		}
+	}
 }
 
 /*!
@@ -443,8 +482,7 @@
 static void rebuild_matrix(int samples)
 {
 	struct ast_translator *t;
-	int new_rate_change;
-	int newcost;
+	int newtablecost;
 	int x;      /* source format index */
 	int y;      /* intermediate format index */
 	int z;      /* destination format index */
@@ -461,23 +499,22 @@
 		x = t->srcfmt;
 		z = t->dstfmt;
 
-		if (samples)
-			calc_cost(t, samples);
-
-		new_rate_change = get_rate_change_result(1LL << t->srcfmt, 1LL << t->dstfmt);
-
-		/* this translator is the best choice if any of the below are true.
+		if (samples) {
+			generate_computational_cost(t, samples);
+		}
+
+		/* This new translator is the best choice if any of the below are true.
 		 * 1. no translation path is set between x and z yet.
-		 * 2. the new translation costs less and sample rate is no worse than old one. 
-		 * 3. the new translation has a better sample rate conversion than the old one.
+		 * 2. the new table cost is less.
+		 * 3. the new computational cost is less.  Computational cost is only used
+		 *    to break a tie between two identical translation paths.
 		 */
 		if (!tr_matrix[x][z].step ||
-			((t->cost < tr_matrix[x][z].cost) && (new_rate_change <= tr_matrix[x][z].rate_change)) ||
-			(new_rate_change < tr_matrix[x][z].rate_change)) {
+			(t->table_cost < tr_matrix[x][z].step->table_cost) ||
+			(t->comp_cost < tr_matrix[x][z].step->comp_cost)) {
 
 			tr_matrix[x][z].step = t;
-			tr_matrix[x][z].cost = t->cost;
-			tr_matrix[x][z].rate_change = new_rate_change;
+			tr_matrix[x][z].table_cost = t->table_cost;
 		}
 	}
 
@@ -489,7 +526,6 @@
 	 */
 	for (;;) {
 		int changed = 0;
-		int better_choice = 0;
 		for (x = 0; x < MAX_FORMAT; x++) {      /* source format */
 			for (y = 0; y < MAX_FORMAT; y++) {    /* intermediate format */
 				if (x == y)                     /* skip ourselves */
@@ -502,68 +538,24 @@
 					if (!tr_matrix[y][z].step)  /* no path from y to z */
 						continue;
 
-					/* Does x->y->z result in a less optimal sample rate change?
-					 * Never downgrade the sample rate conversion quality regardless
-					 * of any cost improvements */
-					if (tr_matrix[x][z].step &&
-						((tr_matrix[x][z].rate_change < tr_matrix[x][y].rate_change) ||
-						(tr_matrix[x][z].rate_change < tr_matrix[y][z].rate_change))) {
-						continue;
+					/* calculate table cost from x->y->z */
+					newtablecost = tr_matrix[x][y].table_cost + tr_matrix[y][z].table_cost;
+
+					if (!tr_matrix[x][z].step || (newtablecost < tr_matrix[x][z].table_cost)) {
+						tr_matrix[x][z].step = tr_matrix[x][y].step;
+						tr_matrix[x][z].table_cost = newtablecost;
+						tr_matrix[x][z].multistep = 1;
+						changed++;
+						ast_debug(3, "Discovered %d cost path from %s to %s, via %s\n", tr_matrix[x][z].table_cost,
+						  ast_getformatname(1LL << x), ast_getformatname(1LL << z), ast_getformatname(1LL << y));
 					}
 
-					/* is x->y->z a better sample rate confersion that the current x->z? */
-					new_rate_change = tr_matrix[x][y].rate_change + tr_matrix[y][z].rate_change;
-
-					/* calculate cost from x->y->z */
-					newcost = tr_matrix[x][y].cost + tr_matrix[y][z].cost;
-
-					/* Is x->y->z a better choice than x->z?
-					 * There are three conditions for x->y->z to be a better choice than x->z
-					 * 1. if there is no step directly between x->z then x->y->z is the best and only current option.
-					 * 2. if x->y->z costs less and the sample rate conversion is no less optimal.
-					 * 3. if x->y->z results in a more optimal sample rate conversion. */
-					if (!tr_matrix[x][z].step) {
-						better_choice = 1;
-					} else if ((newcost < tr_matrix[x][z].cost) && (new_rate_change <= tr_matrix[x][z].rate_change)) {
-						better_choice = 1;
-					} else if (new_rate_change < tr_matrix[x][z].rate_change) {
-						better_choice = 1;
-					} else {
-						better_choice = 0;
-					}
-
-					if (!better_choice) {
-						continue;
-					}
-					/* ok, we can get from x to z via y with a cost that
-					   is the sum of the transition from x to y and from y to z */
-					tr_matrix[x][z].step = tr_matrix[x][y].step;
-					tr_matrix[x][z].cost = newcost;
-					tr_matrix[x][z].multistep = 1;
-
-					/* now calculate what kind of sample rate change is required for this multi-step path
-					 * 
-					 * if both paths require a change in rate, and they are not in the same direction
-					 * then this is a up sample down sample conversion scenario. */
-					if ((tr_matrix[x][y].rate_change > RATE_CHANGE_NONE) &&
-						(tr_matrix[y][z].rate_change > RATE_CHANGE_NONE) &&
-						(tr_matrix[x][y].rate_change != tr_matrix[y][z].rate_change)) {
-
-						tr_matrix[x][z].rate_change = RATE_CHANGE_UPSAMP_DOWNSAMP;
-					} else {
-						/* else just set the rate change to whichever is worse */
-						tr_matrix[x][z].rate_change = tr_matrix[x][y].rate_change > tr_matrix[y][z].rate_change
-							? tr_matrix[x][y].rate_change : tr_matrix[y][z].rate_change;
-					}
-
-					ast_debug(3, "Discovered %d cost path from %s to %s, via %s\n", tr_matrix[x][z].cost,
-						  ast_getformatname(1LL << x), ast_getformatname(1LL << z), ast_getformatname(1LL << y));
-					changed++;
 				}
 			}
 		}
-		if (!changed)
+		if (!changed) {
 			break;
+		}
 	}
 }
 
@@ -611,7 +603,7 @@
 #define SHOW_TRANS 64
 	static const char * const option1[] = { "recalc", "paths", NULL };
 	int x, y, z;
-	int curlen = 0, longest = 0, magnitude[SHOW_TRANS] = { 0, };
+	int curlen = 0, longest = 0;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -723,14 +715,8 @@
 		if (!(AST_FORMAT_AUDIO_MASK & (1LL << (x))))
 			continue;
 		curlen = strlen(ast_getformatname(1LL << (x)));
-		if (curlen > longest)
+		if (curlen > longest) {
 			longest = curlen;
-		for (y = 0; y < SHOW_TRANS; y++) {
-			if (!(AST_FORMAT_AUDIO_MASK & (1LL << (y))))
-				continue;
-			if (tr_matrix[x][y].cost > pow(10, magnitude[x])) {
-				magnitude[y] = floor(log10(tr_matrix[x][y].cost));
-			}
 		}
 	}
 	for (x = -1; x < SHOW_TRANS; x++) {
@@ -751,14 +737,12 @@
 				continue;
 			if (y >= 0)
 				curlen = strlen(ast_getformatname(1LL << (y)));
-			if (y >= 0 && magnitude[y] + 1 > curlen) {
-				curlen = magnitude[y] + 1;
-			}
 			if (curlen < 5)
 				curlen = 5;
+
 			if (x >= 0 && y >= 0 && tr_matrix[x][y].step) {
 				/* Actual codec output */
-				ast_str_append(&out, -1, "%*d", curlen + 1, tr_matrix[x][y].cost);
+				ast_str_append(&out, -1, "%*d", curlen + 1, (tr_matrix[x][y].table_cost/100));
 			} else if (x == -1 && y >= 0) {
 				/* Top row - use a dynamic size */
 				ast_str_append(&out, -1, "%*s", curlen + 1, ast_getformatname(1LL << (y)) );
@@ -800,12 +784,13 @@
 		ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
 		return -1;
 	}
+	if (!t->table_cost && !(t->table_cost = generate_table_cost(t->srcfmt, t->dstfmt))) {
+		ast_log(LOG_WARNING, "Table cost could not be generated for %s, "
+			"Please set table_cost variable on translator.\n", t->name);
+		return -1;
+	}
 
 	t->module = mod;
-
-	if (!t->cost) {
-		t->cost = generate_cost_val(t->srcfmt, t->dstfmt);
-	}
 	t->srcfmt = powerof(t->srcfmt);
 	t->dstfmt = powerof(t->dstfmt);
 	t->active = 1;
@@ -837,12 +822,12 @@
 
 	if (t->frameout == NULL)
 		t->frameout = default_frameout;
-  
-	calc_cost(t, 1);
+ 
+	generate_computational_cost(t, 1);
 
 	ast_verb(2, "Registered translator '%s' from format %s to %s, cost %d\n",
 			    term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
-			    ast_getformatname(1LL << t->srcfmt), ast_getformatname(1LL << t->dstfmt), t->cost);
+			    ast_getformatname(1LL << t->srcfmt), ast_getformatname(1LL << t->dstfmt), t->comp_cost);
 
 	if (!added_cli) {
 		ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
@@ -852,11 +837,11 @@
 	AST_RWLIST_WRLOCK(&translators);
 
 	/* find any existing translators that provide this same srcfmt/dstfmt,
-	   and put this one in order based on cost */
+	   and put this one in order based on computational cost */
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
 		if ((u->srcfmt == t->srcfmt) &&
 		    (u->dstfmt == t->dstfmt) &&
-		    (u->cost > t->cost)) {
+		    (u->comp_cost > t->comp_cost)) {
 			AST_RWLIST_INSERT_BEFORE_CURRENT(t, list);
 			t = NULL;
 			break;
@@ -922,10 +907,8 @@
 format_t ast_translator_best_choice(format_t *dst, format_t *srcs)
 {
 	int x,y;
-	int better = 0;
-	int besttime = INT_MAX;
+	int besttablecost = INT_MAX;
 	int beststeps = INT_MAX;
-	unsigned int best_rate_change = INT_MAX;
 	format_t best = -1;
 	format_t bestdst = 0;
 	format_t cur, cursrc;
@@ -961,26 +944,12 @@
 				if (!(*srcs & cursrc) || !tr_matrix[x][y].step) {
 					continue;
 				}
-
-				/* This is a better choice if any of the following are true.
-				 * 1. The sample rate conversion is better than the current pick.
-				 * 2. the sample rate conversion is no worse than the current pick and the cost or multistep is better
-				 */
-				better = 0;
-				if (tr_matrix[x][y].rate_change < best_rate_change) {
-					better = 1; /* this match has a better rate conversion */
-				}
-				if ((tr_matrix[x][y].rate_change <= best_rate_change) &&
-					(tr_matrix[x][y].cost < besttime || tr_matrix[x][y].multistep < beststeps)) {
-					better = 1; /* this match has no worse rate conversion and the conversion cost is less */
-				}
-				if (better) {
+				if ((tr_matrix[x][y].table_cost < besttablecost || tr_matrix[x][y].multistep < beststeps)) {
 					/* better than what we have so far */
 					best = cursrc;
 					bestdst = cur;
-					besttime = tr_matrix[x][y].cost;
+					besttablecost = tr_matrix[x][y].table_cost;
 					beststeps = tr_matrix[x][y].multistep;
-					best_rate_change = tr_matrix[x][y].rate_change;
 				}
 			}
 		}
@@ -1103,60 +1072,4 @@
 	return res;
 }
 
-/*!
- * \internal
- *
- * \brief If no cost value was pre set by the translator.  An attempt is made to
- * automatically generate that cost value from the cost table based on our src and
- * dst formats.
- *
- * \note This function allows older translators built before the translation cost
- * changed away from computational time to continue to be registered correctly.
- *
- * \note This function is safe to use on any formats that used to be defined in the
- * first 32 bits of the old bit field codec representation.
- */
-static int generate_cost_val(format_t src, format_t dst)
-{
-	int src_rate = ast_format_rate(src);
-	int src_ll = 0;
-	int dst_rate = ast_format_rate(dst);
-	int dst_ll = 0;
-
-	if ((src == AST_FORMAT_SLINEAR) || (src == AST_FORMAT_SLINEAR16)) {
-		src_ll = 1;
-	}
-	if ((dst == AST_FORMAT_SLINEAR) || (dst == AST_FORMAT_SLINEAR16)) {
-		dst_ll = 1;
-	}
-
-	if (src_ll) {
-		if (dst_ll && (src_rate == dst_rate)) {
-			return AST_TRANS_COST_LL_LL_ORIGSAMP;
-		} else if (!dst_ll && (src_rate == dst_rate)) {
-			return AST_TRANS_COST_LL_LY_ORIGSAMP;
-		} else if (dst_ll && (src_rate < dst_rate)) {
-			return AST_TRANS_COST_LL_LL_UPSAMP;
-		} else if (!dst_ll && (src_rate < dst_rate)) {
-			return AST_TRANS_COST_LL_LY_UPSAMP;
-		} else if (dst_ll && (src_rate > dst_rate)) {
-			return AST_TRANS_COST_LL_LL_DOWNSAMP;
-		} else {
-			return AST_TRANS_COST_LL_LY_DOWNSAMP;
-		}
-	} else {
-		if (dst_ll && (src_rate == dst_rate)) {
-			return AST_TRANS_COST_LY_LL_ORIGSAMP;
-		} else if (!dst_ll && (src_rate == dst_rate)) {
-			return AST_TRANS_COST_LY_LY_ORIGSAMP;
-		} else if (dst_ll && (src_rate < dst_rate)) {
-			return AST_TRANS_COST_LY_LL_UPSAMP;
-		} else if (!dst_ll && (src_rate < dst_rate)) {
-			return AST_TRANS_COST_LY_LY_UPSAMP;
-		} else if (dst_ll && (src_rate > dst_rate)) {
-			return AST_TRANS_COST_LY_LL_DOWNSAMP;
-		} else {
-			return AST_TRANS_COST_LY_LY_DOWNSAMP;
-		}
-	}
-}
+




More information about the asterisk-commits mailing list