[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step2 r299396 - /team/dvossel/fixt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 21 19:06:46 UTC 2010


Author: dvossel
Date: Tue Dec 21 13:06:41 2010
New Revision: 299396

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299396
Log:
add index to format conversion functions

Modified:
    team/dvossel/fixtheworld_phase1_step2/main/translate.c

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=299396&r1=299395&r2=299396
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/translate.c Tue Dec 21 13:06:41 2010
@@ -69,8 +69,11 @@
  * the existing converter to play with it.
  */
 
-/*! \brief returns the index of the lowest bit set */
-static force_inline int powerof(format_t d)
+/*!
+ * \internal
+ * \brief converts format id to index value.
+ */
+static force_inline int format2index(format_t d)
 {
 	int x = ffsll(d);
 
@@ -80,6 +83,14 @@
 	ast_log(LOG_WARNING, "No bits set? %llu\n", (unsigned long long) d);
 
 	return -1;
+}
+/*! 
+ * \internal
+ * \brief converts index value back to format id
+ */
+static force_inline format_t index2format(int index)
+{
+	return 1LL << index;
 }
 
 /*
@@ -196,7 +207,7 @@
 	}
 
 	f->frametype = AST_FRAME_VOICE;
-	f->subclass.codec = 1LL << (pvt->t->dstfmt);
+	f->subclass.codec = index2format(pvt->t->dstfmt);
 	f->mallocd = 0;
 	f->offset = AST_FRIENDLY_OFFSET;
 	f->src = pvt->t->name;
@@ -226,8 +237,8 @@
 {
 	struct ast_trans_pvt *head = NULL, *tail = NULL;
 	
-	source = powerof(source);
-	dest = powerof(dest);
+	source = format2index(source);
+	dest = format2index(dest);
 
 	if (source == -1 || dest == -1) {
 		ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", source == -1 ? "starting" : "ending");
@@ -547,7 +558,7 @@
 						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));
+						  ast_getformatname(index2format(x)), ast_getformatname(index2format(z)), ast_getformatname(index2format(y)));
 					}
 
 				}
@@ -567,11 +578,11 @@
 		return "";
 	}
 
-	ast_str_set(str, 0, "%s", ast_getformatname(1LL << p->t->srcfmt));
+	ast_str_set(str, 0, "%s", ast_getformatname(index2format(p->t->srcfmt)));
 
 	while ( (p = pn) ) {
 		pn = p->next;
-		ast_str_append(str, 0, "->%s", ast_getformatname(1LL << p->t->dstfmt));
+		ast_str_append(str, 0, "->%s", ast_getformatname(index2format(p->t->dstfmt)));
 	}
 
 	return ast_str_buffer(*str);
@@ -661,18 +672,18 @@
 			if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK) || (format_list[i].bits == input_src)) {
 				continue;
 			}
-			dst = powerof(format_list[i].bits);
-			src = powerof(input_src);
+			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(1LL << tr_matrix[src][dst].step->srcfmt));
+				ast_str_append(&str, 0, "%s", ast_getformatname(index2format(tr_matrix[src][dst].step->srcfmt)));
 				while (src != dst) {
 					step = tr_matrix[src][dst].step;
 					if (!step) {
 						ast_str_reset(str);
 						break;
 					}
-					ast_str_append(&str, 0, "->%s", ast_getformatname(1LL << step->dstfmt));
+					ast_str_append(&str, 0, "->%s", ast_getformatname(index2format(step->dstfmt)));
 					src = step->dstfmt;
 				}
 			}
@@ -712,9 +723,9 @@
 	/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
 	for (x = 0; x < SHOW_TRANS; x++) {
 		/* translation only applies to audio right now. */
-		if (!(AST_FORMAT_AUDIO_MASK & (1LL << (x))))
-			continue;
-		curlen = strlen(ast_getformatname(1LL << (x)));
+		if (!(AST_FORMAT_AUDIO_MASK & (index2format(x))))
+			continue;
+		curlen = strlen(ast_getformatname(index2format(x)));
 		if (curlen > longest) {
 			longest = curlen;
 		}
@@ -722,21 +733,21 @@
 	for (x = -1; x < SHOW_TRANS; x++) {
 		struct ast_str *out = ast_str_alloca(256);
 		/* translation only applies to audio right now. */
-		if (x >= 0 && !(AST_FORMAT_AUDIO_MASK & (1LL << (x))))
+		if (x >= 0 && !(AST_FORMAT_AUDIO_MASK & (index2format(x))))
 			continue;
 		/*Go ahead and move to next iteration if dealing with an unknown codec*/
-		if(x >= 0 && !strcmp(ast_getformatname(1LL << (x)), "unknown"))
+		if(x >= 0 && !strcmp(ast_getformatname(index2format(x)), "unknown"))
 			continue;
 		ast_str_set(&out, -1, " ");
 		for (y = -1; y < SHOW_TRANS; y++) {
 			/* translation only applies to audio right now. */
-			if (y >= 0 && !(AST_FORMAT_AUDIO_MASK & (1LL << (y))))
+			if (y >= 0 && !(AST_FORMAT_AUDIO_MASK & (index2format(y))))
 				continue;
 			/*Go ahead and move to next iteration if dealing with an unknown codec*/
-			if (y >= 0 && !strcmp(ast_getformatname(1LL << (y)), "unknown"))
+			if (y >= 0 && !strcmp(ast_getformatname(index2format(y)), "unknown"))
 				continue;
 			if (y >= 0)
-				curlen = strlen(ast_getformatname(1LL << (y)));
+				curlen = strlen(ast_getformatname(index2format(y)));
 			if (curlen < 5)
 				curlen = 5;
 
@@ -745,10 +756,10 @@
 				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)) );
+				ast_str_append(&out, -1, "%*s", curlen + 1, ast_getformatname(index2format(y)) );
 			} else if (y == -1 && x >= 0) {
 				/* Left column - use a static size. */
-				ast_str_append(&out, -1, "%*s", longest, ast_getformatname(1LL << (x)) );
+				ast_str_append(&out, -1, "%*s", longest, ast_getformatname(index2format(x)) );
 			} else if (x >= 0 && y >= 0) {
 				/* Codec not supported */
 				ast_str_append(&out, -1, "%*s", curlen + 1, "-");
@@ -791,8 +802,8 @@
 	}
 
 	t->module = mod;
-	t->srcfmt = powerof(t->srcfmt);
-	t->dstfmt = powerof(t->dstfmt);
+	t->srcfmt = format2index(t->srcfmt);
+	t->dstfmt = format2index(t->dstfmt);
 	t->active = 1;
 
 	if (t->srcfmt == -1 || t->dstfmt == -1) {
@@ -827,7 +838,7 @@
 
 	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->comp_cost);
+			    ast_getformatname(index2format(t->srcfmt)), ast_getformatname(index2format(t->dstfmt)), t->comp_cost);
 
 	if (!added_cli) {
 		ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
@@ -872,7 +883,7 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
 		if (u == t) {
 			AST_RWLIST_REMOVE_CURRENT(list);
-			ast_verb(2, "Unregistered translator '%s' from format %s to %s\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1LL << t->srcfmt), ast_getformatname(1LL << t->dstfmt));
+			ast_verb(2, "Unregistered translator '%s' from format %s to %s\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(index2format(t->srcfmt)), ast_getformatname(index2format(t->dstfmt)));
 			found = 1;
 			break;
 		}
@@ -968,8 +979,8 @@
 	unsigned int res = -1;
 
 	/* convert bitwise format numbers into array indices */
-	src = powerof(src);
-	dest = powerof(dest);
+	src = format2index(src);
+	dest = format2index(dest);
 
 	if (src == -1 || dest == -1) {
 		ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", src == -1 ? "starting" : "ending");
@@ -999,11 +1010,11 @@
 
 	/* If we have a source audio format, get its format index */
 	if (src_audio)
-		src_audio = powerof(src_audio);
+		src_audio = format2index(src_audio);
 
 	/* If we have a source video format, get its format index */
 	if (src_video)
-		src_video = powerof(src_video);
+		src_video = format2index(src_video);
 
 	AST_RWLIST_RDLOCK(&translators);
 
@@ -1027,13 +1038,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][powerof(x)].step) {
+		if (!tr_matrix[src_audio][format2index(x)].step) {
 			res &= ~x;
 			continue;
 		}
 
 		/* now check the opposite direction */
-		if (!tr_matrix[powerof(x)][src_audio].step)
+		if (!tr_matrix[format2index(x)][src_audio].step)
 			res &= ~x;
 	}
 
@@ -1057,13 +1068,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][powerof(x)].step) {
+		if (!tr_matrix[src_video][format2index(x)].step) {
 			res &= ~x;
 			continue;
 		}
 
 		/* now check the opposite direction */
-		if (!tr_matrix[powerof(x)][src_video].step)
+		if (!tr_matrix[format2index(x)][src_video].step)
 			res &= ~x;
 	}
 




More information about the asterisk-commits mailing list