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

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


Author: dvossel
Date: Tue Dec 21 16:38:27 2010
New Revision: 299403

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299403
Log:
Translation formatting and documentation cleanup

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=299403&r1=299402&r2=299403
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/translate.c Tue Dec 21 16:38:27 2010
@@ -209,17 +209,17 @@
 {
 	struct ast_frame *f = &pvt->f;
 
-	if (samples)
+	if (samples) {
 		f->samples = samples;
-	else {
+	} else {
 		if (pvt->samples == 0)
 			return NULL;
 		f->samples = pvt->samples;
 		pvt->samples = 0;
 	}
-	if (datalen)
+	if (datalen) {
 		f->datalen = datalen;
-	else {
+	} else {
 		f->datalen = pvt->datalen;
 		pvt->datalen = 0;
 	}
@@ -277,15 +277,17 @@
 		if (!(cur = newpvt(t))) {
 			ast_log(LOG_WARNING, "Failed to build translator step from %s to %s\n",
 				ast_getformatname(source), ast_getformatname(dest));
-			if (head)
-				ast_translator_free_path(head);	
+			if (head) {
+				ast_translator_free_path(head);
+			}
 			AST_RWLIST_UNLOCK(&translators);
 			return NULL;
 		}
-		if (!head)
+		if (!head) {
 			head = cur;
-		else
+		} else {
 			tail->next = cur;
+		}
 		tail = cur;
 		cur->nextin = cur->nextout = ast_tv(0, 0);
 		/* Keep going if this isn't the final destination */
@@ -300,7 +302,7 @@
 struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume)
 {
 	struct ast_trans_pvt *p = path;
-	struct ast_frame *out = f;
+	struct ast_frame *out;
 	struct timeval delivery;
 	int has_timing_info;
 	long ts;
@@ -312,7 +314,6 @@
 	len = f->len;
 	seqno = f->seqno;
 
-	/* XXX hmmm... check this below */
 	if (!ast_tvzero(f->delivery)) {
 		if (!ast_tvzero(path->nextin)) {
 			/* Make sure this is in line with what we were expecting */
@@ -335,21 +336,25 @@
 		path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_format_rate(f->subclass.codec)));
 	}
 	delivery = f->delivery;
-	for ( ; out && p ; p = p->next) {
+	for (out = f; out && p ; p = p->next) {
 		framein(p, out);
-		if (out != f)
+		if (out != f) {
 			ast_frfree(out);
+		}
 		out = p->t->frameout(p);
 	}
-	if (consume)
+	if (consume) {
 		ast_frfree(f);
-	if (out == NULL)
+	}
+	if (out == NULL) {
 		return NULL;
+	}
 	/* we have a frame, play with times */
 	if (!ast_tvzero(delivery)) {
 		/* Regenerate prediction after a discontinuity */
-		if (ast_tvzero(path->nextout))
+		if (ast_tvzero(path->nextout)) {
 			path->nextout = ast_tvnow();
+		}
 
 		/* Use next predicted outgoing timestamp */
 		out->delivery = path->nextout;
@@ -367,8 +372,9 @@
 		}
 	}
 	/* Invalidate prediction if we're entering a silence period */
-	if (out->frametype == AST_FRAME_CNG)
+	if (out->frametype == AST_FRAME_CNG) {
 		path->nextout = ast_tv(0, 0);
+	}
 	return out;
 }
 
@@ -389,8 +395,9 @@
 	int cost;
 	int out_rate = ast_format_rate(t->dstfmt);
 
-	if (!seconds)
+	if (!seconds) {
 		seconds = 1;
+	}
 
 	/* If they don't make samples, give them a terrible score */
 	if (!t->sample) {
@@ -434,8 +441,9 @@
 
 	t->comp_cost = cost / seconds;
 
-	if (!t->comp_cost)
+	if (!t->comp_cost) {
 		t->comp_cost = 1;
+	}
 }
 
 /*!
@@ -522,8 +530,9 @@
 
 	/* first, compute all direct costs */
 	AST_RWLIST_TRAVERSE(&translators, t, list) {
-		if (!t->active)
-			continue;
+		if (!t->active) {
+			continue;
+		}
 
 		x = t->srcfmt;
 		z = t->dstfmt;
@@ -556,29 +565,33 @@
 	for (;;) {
 		int changed = 0;
 		for (x = 0; x < cur_max_index; x++) {      /* source format */
-			for (y = 0; y < cur_max_index; y++) {    /* intermediate format */
-				if (x == y)                     /* skip ourselves */
+			for (y = 0; y < cur_max_index; y++) {  /* intermediate format */
+				if (x == y) {                      /* skip ourselves */
 					continue;
+				}
 				for (z = 0; z < cur_max_index; z++) {  /* dst format */
-					if (z == x || z == y)       /* skip null conversions */
+					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 */
 						continue;
-					if (!tr_matrix[x][y].step)  /* no path from x to y */
-						continue;
-					if (!tr_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;
 
+					/* 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;
 						changed++;
-						ast_debug(3, "Discovered %d cost path from %s to %s, via %s\n", tr_matrix[x][z].table_cost,
-						  ast_getformatname(index2format(x)), ast_getformatname(index2format(z)), ast_getformatname(index2format(y)));
+						ast_debug(3, "Discovered %d cost path from %s to %s, via %s\n",
+							tr_matrix[x][z].table_cost,
+							ast_getformatname(index2format(x)),
+							ast_getformatname(index2format(z)),
+							ast_getformatname(index2format(y)));
 					}
-
 				}
 			}
 		}
@@ -654,6 +667,7 @@
 	AST_RWLIST_RDLOCK(&translators);
 	ast_cli(a->fd, "         Translation times between formats (in microseconds) for one second of data\n");
 	ast_cli(a->fd, "          Source Format (Rows) Destination Format (Columns)\n\n");
+
 	/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
 	for (x = 0; x < cur_max_index; x++) {
 		/* translation only applies to audio right now. */
@@ -664,26 +678,33 @@
 			longest = curlen;
 		}
 	}
+
 	for (x = -1; x < cur_max_index; x++) {
 		struct ast_str *out = ast_str_alloca(256);
 		/* translation only applies to audio right now. */
-		if (x >= 0 && !(AST_FORMAT_AUDIO_MASK & (index2format(x))))
-			continue;
+		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(index2format(x)), "unknown"))
-			continue;
+		if (x >= 0 && !strcmp(ast_getformatname(index2format(x)), "unknown")) {
+			continue;
+		}
 		ast_str_set(&out, -1, " ");
 		for (y = -1; y < cur_max_index; y++) {
 			/* translation only applies to audio right now. */
-			if (y >= 0 && !(AST_FORMAT_AUDIO_MASK & (index2format(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(index2format(y)), "unknown"))
+			if (y >= 0 && !strcmp(ast_getformatname(index2format(y)), "unknown")) {
 				continue;
-			if (y >= 0)
+			}
+			if (y >= 0) {
 				curlen = strlen(ast_getformatname(index2format(y)));
-			if (curlen < 5)
+			}
+			if (curlen < 5) {
 				curlen = 5;
+			}
 
 			if (x >= 0 && y >= 0 && tr_matrix[x][y].step) {
 				/* Actual codec output */
@@ -863,8 +884,9 @@
 		t->buf_size = ((t->buf_size + align - 1) / align) * align;
 	}
 
-	if (t->frameout == NULL)
+	if (t->frameout == NULL) {
 		t->frameout = default_frameout;
+	}
 
 	generate_computational_cost(t, 1);
 
@@ -894,8 +916,9 @@
 
 	/* if no existing translator was found for this format combination,
 	   add it to the beginning of the list */
-	if (t)
+	if (t) {
 		AST_RWLIST_INSERT_HEAD(&translators, t, list);
+	}
 
 	rebuild_matrix(0);
 
@@ -915,15 +938,19 @@
 	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(index2format(t->srcfmt)), ast_getformatname(index2format(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;
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 
-	if (found)
+	if (found) {
 		rebuild_matrix(0);
+	}
 
 	AST_RWLIST_UNLOCK(&translators);
 
@@ -1020,8 +1047,9 @@
 	}
 	AST_RWLIST_RDLOCK(&translators);
 
-	if (tr_matrix[src][dest].step)
+	if (tr_matrix[src][dest].step) {
 		res = tr_matrix[src][dest].multistep + 1;
+	}
 
 	AST_RWLIST_UNLOCK(&translators);
 
@@ -1038,16 +1066,19 @@
 
 	/* if we don't have a source format, we just have to try all
 	   possible destination formats */
-	if (!src)
+	if (!src) {
 		return dest;
+	}
 
 	/* If we have a source audio format, get its format index */
-	if (src_audio)
+	if (src_audio) {
 		src_audio = format2index(src_audio);
+	}
 
 	/* If we have a source video format, get its format index */
-	if (src_video)
+	if (src_video) {
 		src_video = format2index(src_video);
+	}
 
 	AST_RWLIST_RDLOCK(&translators);
 
@@ -1062,13 +1093,15 @@
 		}
 
 		/* if this is not a desired format, nothing to do */
-		if (!(dest & tmp_fmt))
-			continue;
+		if (!(dest & tmp_fmt)) {
+			continue;
+		}
 
 		/* if the source is supplying this format, then
 		   we can leave it in the result */
-		if (src & tmp_fmt)
-			continue;
+		if (src & tmp_fmt) {
+			continue;
+		}
 
 		/* if we don't have a translation path from the src
 		   to this format, remove it from the result */
@@ -1078,8 +1111,9 @@
 		}
 
 		/* now check the opposite direction */
-		if (!tr_matrix[index][src_audio].step)
+		if (!tr_matrix[index][src_audio].step) {
 			res &= tmp_fmt;
+		}
 	}
 
 	/* For a given source video format, traverse the list of
@@ -1093,13 +1127,15 @@
 		}
 
 		/* if this is not a desired format, nothing to do */
-		if (!(dest & tmp_fmt))
-			continue;
+		if (!(dest & tmp_fmt)) {
+			continue;
+		}
 
 		/* if the source is supplying this format, then
 		   we can leave it in the result */
-		if (src & tmp_fmt)
-			continue;
+		if (src & tmp_fmt) {
+			continue;
+		}
 
 		/* if we don't have a translation path from the src
 		   to this format, remove it from the result */
@@ -1109,8 +1145,9 @@
 		}
 
 		/* now check the opposite direction */
-		if (!tr_matrix[index][src_video].step)
+		if (!tr_matrix[index][src_video].step) {
 			res &= ~tmp_fmt;
+		}
 	}
 
 	AST_RWLIST_UNLOCK(&translators);




More information about the asterisk-commits mailing list