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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 22 20:47:31 UTC 2010


Author: dvossel
Date: Wed Dec 22 14:47:27 2010
New Revision: 299490

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299490
Log:
convert access to translator matrix to a get function

Modified:
    team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h
    team/dvossel/fixtheworld_phase1_step2/main/asterisk.c
    team/dvossel/fixtheworld_phase1_step2/main/translate.c

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=299490&r1=299489&r2=299490
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h Wed Dec 22 14:47:27 2010
@@ -306,6 +306,13 @@
  */
 const char *ast_translate_path_to_str(struct ast_trans_pvt *t, struct ast_str **str);
 
+/*!
+ * \brief Initialize the translation matrix and index to format conversion table.
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+int ast_translate_init(void);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/dvossel/fixtheworld_phase1_step2/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/main/asterisk.c?view=diff&rev=299490&r1=299489&r2=299490
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/asterisk.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/asterisk.c Wed Dec 22 14:47:27 2010
@@ -111,6 +111,7 @@
 #include "asterisk/network.h"
 #include "asterisk/cli.h"
 #include "asterisk/channel.h"
+#include "asterisk/translate.h"
 #include "asterisk/features.h"
 #include "asterisk/ulaw.h"
 #include "asterisk/alaw.h"
@@ -3669,6 +3670,11 @@
 	}
 #endif
 
+	if (ast_translate_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
 	ast_aoc_cli_init();
 
 	ast_makesocket();

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=299490&r1=299489&r2=299490
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/translate.c Wed Dec 22 14:47:27 2010
@@ -42,10 +42,10 @@
 
 #define MAX_RECALC 1000 /* max sample recalc */
 
-/*! This value is used to define how large the tr_matrix and tr_index2format arrays
+/*! This value is used to define how large the matrix( and tr_index2format arrays
  *  are defined to be in memory by default.  Once Asterisk can represent more formats
  *  than this number represents with translation, increase it. */
-#define MAX_INDEX 128
+#define DEFAULT_INDEX_SIZE 128
 
 /*! \brief the list of translators */
 static AST_RWLIST_HEAD_STATIC(translators, ast_translator);
@@ -66,10 +66,10 @@
  * Note: the lock in the 'translators' list is also used to protect
  * this structure.
  */
-static struct translator_path tr_matrix[MAX_INDEX][MAX_INDEX];
+static struct translator_path __matrix[DEFAULT_INDEX_SIZE][DEFAULT_INDEX_SIZE];
 /*! table for converting index to format id values. */
-static format_t tr_index2format[MAX_INDEX];
-/*! the current largest index used by the tr_matrix and tr_index2format tables */
+static format_t tr_index2format[DEFAULT_INDEX_SIZE];
+/*! the current largest index used by the matrix( and tr_index2format tables */
 static int cur_max_index = 0;
 
 /*! \todo
@@ -92,9 +92,8 @@
 		}
 	}
 
-	if (cur_max_index == ARRAY_LEN(tr_index2format)) {
-		ast_log(LOG_WARNING, "All translator matrix index values are in use! Increase size of MAX_INDEX.\n");
-		return -1; /* hit max length. */
+	if (cur_max_index == (DEFAULT_INDEX_SIZE)) {
+		return -1; /* hit max length. todohere, make it grow. */
 	}
 	tr_index2format[cur_max_index] = id;
 	cur_max_index++;
@@ -109,6 +108,12 @@
 static force_inline format_t index2format(int index)
 {
 	return tr_index2format[index];
+}
+
+
+static struct translator_path *matrix(int x, int y)
+{
+	return &__matrix[x][y];
 }
 
 /*
@@ -267,7 +272,7 @@
 
 	while (source != dest) {
 		struct ast_trans_pvt *cur;
-		struct ast_translator *t = tr_matrix[source][dest].step;
+		struct ast_translator *t = matrix(source, dest)->step;
 		if (!t) {
 			ast_log(LOG_WARNING, "No translator path from %s to %s\n", 
 				ast_getformatname(source), ast_getformatname(dest));
@@ -526,7 +531,7 @@
 
 	ast_debug(1, "Resetting translation matrix\n");
 
-	memset(tr_matrix, '\0', sizeof(tr_matrix));
+	memset(__matrix, '\0', sizeof(__matrix));
 
 	/* first, compute all direct costs */
 	AST_RWLIST_TRAVERSE(&translators, t, list) {
@@ -547,12 +552,12 @@
 		 * 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->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].table_cost = t->table_cost;
+		if (!matrix(x, z)->step ||
+			(t->table_cost < matrix(x, z)->step->table_cost) ||
+			(t->comp_cost < matrix(x, z)->step->comp_cost)) {
+
+			matrix(x, z)->step = t;
+			matrix(x, z)->table_cost = t->table_cost;
 		}
 	}
 
@@ -571,23 +576,23 @@
 				}
 				for (z = 0; z < cur_max_index; z++) {  /* dst format */
 					if ((z == x || z == y) ||        /* skip null conversions */
-						!tr_matrix[x][y].step ||   /* no path from x to y */
-						!tr_matrix[y][z].step) {   /* no path from y to z */
+						!matrix(x, y)->step ||   /* no path from x to y */
+						!matrix(y, z)->step) {   /* no path from y to z */
 						continue;
 					}
 
 					/* calculate table cost from x->y->z */
-					newtablecost = tr_matrix[x][y].table_cost + tr_matrix[y][z].table_cost;
+					newtablecost = matrix(x, y)->table_cost + matrix(y, z)->table_cost;
 
 					/* if no step already exists between x and z OR the new cost of using the intermediate
 					 * step is cheaper, use this step. */
-					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;
+					if (!matrix(x, z)->step || (newtablecost < matrix(x, z)->table_cost)) {
+						matrix(x, z)->step = matrix(x, y)->step;
+						matrix(x, z)->table_cost = newtablecost;
+						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,
+							matrix(x, z)->table_cost,
 							ast_getformatname(index2format(x)),
 							ast_getformatname(index2format(z)),
 							ast_getformatname(index2format(y)));
@@ -706,9 +711,9 @@
 				curlen = 5;
 			}
 
-			if (x >= 0 && y >= 0 && tr_matrix[x][y].step) {
+			if (x >= 0 && y >= 0 && matrix(x, y)->step) {
 				/* Actual codec output */
-				ast_str_append(&out, -1, "%*d", curlen + 1, (tr_matrix[x][y].table_cost/100));
+				ast_str_append(&out, -1, "%*d", curlen + 1, (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(index2format(y)) );
@@ -764,10 +769,10 @@
 		dst = format2index(format_list[i].bits);
 		src = format2index(input_src);
 		ast_str_reset(str);
-		if (tr_matrix[src][dst].step) {
-			ast_str_append(&str, 0, "%s", ast_getformatname(index2format(tr_matrix[src][dst].step->srcfmt)));
+		if (matrix(src, dst)->step) {
+			ast_str_append(&str, 0, "%s", ast_getformatname(index2format(matrix(src, dst)->step->srcfmt)));
 			while (src != dst) {
-				step = tr_matrix[src][dst].step;
+				step = matrix(src, dst)->step;
 				if (!step) {
 					ast_str_reset(str);
 					break;
@@ -1011,15 +1016,15 @@
 				continue;
 			}
 			for (cursrc = 1, x = 0; x <= MAX_AUDIO_FORMAT; cursrc <<= 1, x++) {
-				if (!(*srcs & cursrc) || !tr_matrix[x][y].step) {
+				if (!(*srcs & cursrc) || !matrix(x, y)->step) {
 					continue;
 				}
-				if ((tr_matrix[x][y].table_cost < besttablecost || tr_matrix[x][y].multistep < beststeps)) {
+				if ((matrix(x, y)->table_cost < besttablecost || matrix(x, y)->multistep < beststeps)) {
 					/* better than what we have so far */
 					best = cursrc;
 					bestdst = cur;
-					besttablecost = tr_matrix[x][y].table_cost;
-					beststeps = tr_matrix[x][y].multistep;
+					besttablecost = matrix(x, y)->table_cost;
+					beststeps = matrix(x, y)->multistep;
 				}
 			}
 		}
@@ -1047,8 +1052,8 @@
 	}
 	AST_RWLIST_RDLOCK(&translators);
 
-	if (tr_matrix[src][dest].step) {
-		res = tr_matrix[src][dest].multistep + 1;
+	if (matrix(src, dest)->step) {
+		res = matrix(src, dest)->multistep + 1;
 	}
 
 	AST_RWLIST_UNLOCK(&translators);
@@ -1105,13 +1110,13 @@
 
 		/* if we don't have a translation path from the src
 		   to this format, remove it from the result */
-		if (!tr_matrix[src_audio][index].step) {
+		if (!matrix(src_audio, index)->step) {
 			res &= ~tmp_fmt;
 			continue;
 		}
 
 		/* now check the opposite direction */
-		if (!tr_matrix[index][src_audio].step) {
+		if (!matrix(index, src_audio)->step) {
 			res &= tmp_fmt;
 		}
 	}
@@ -1139,13 +1144,13 @@
 
 		/* if we don't have a translation path from the src
 		   to this format, remove it from the result */
-		if (!tr_matrix[src_video][index].step) {
+		if (!matrix(src_video, index)->step) {
 			res &= ~tmp_fmt;
 			continue;
 		}
 
 		/* now check the opposite direction */
-		if (!tr_matrix[index][src_video].step) {
+		if (!matrix(index, src_video)->step) {
 			res &= ~tmp_fmt;
 		}
 	}
@@ -1154,3 +1159,28 @@
 
 	return res;
 }
+
+
+int ast_translate_init(void)
+{
+	//index_size = DEFAULT_INDEX_SIZE;
+	/* 2d array of translator_path structures */
+//	if (!(t = ast_calloc(1, sizeof(struct translator_path) * ((index_size) * (index_size))))) {
+//		return -1;
+//	}
+
+	//for (x = 0; x < index_size; x++) {
+//		if (!(matrix([x] = ast_calloc(1, sizeof(struct translator_path) * (index_size)))) {
+//			/* this will kill Asterisk on startup, so no reason to clean up */
+//			return -1;
+//		}
+//	}
+
+	/* 1d array of format_t IDs */
+//	if (!(tr_index2format = ast_calloc(1, sizeof(format_t) * (index_size)))) {
+//		ast_free(t);
+//		return -1;
+//	}
+	return 0;
+
+}




More information about the asterisk-commits mailing list