[asterisk-commits] dvossel: branch dvossel/improved_hd_audio_translation_paths r280705 - in /tea...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 2 17:57:36 CDT 2010


Author: dvossel
Date: Mon Aug  2 17:57:33 2010
New Revision: 280705

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=280705
Log:
addition of 'core show translator path [codec]' cli option

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

Modified: team/dvossel/improved_hd_audio_translation_paths/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/improved_hd_audio_translation_paths/include/asterisk/translate.h?view=diff&rev=280705&r1=280704&r2=280705
==============================================================================
--- team/dvossel/improved_hd_audio_translation_paths/include/asterisk/translate.h (original)
+++ team/dvossel/improved_hd_audio_translation_paths/include/asterisk/translate.h Mon Aug  2 17:57:33 2010
@@ -258,7 +258,7 @@
  * \brief Puts a string representation of the translation path into outbuf
  * \retval on success, pointer to beginning of outbuf. on failure returns "".
  */
-char *ast_translate_path_to_str(struct ast_trans_pvt *t, char *outbuf, size_t outlen);
+char *ast_translate_path_to_str(struct ast_trans_pvt *t, struct ast_str **str);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/dvossel/improved_hd_audio_translation_paths/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/improved_hd_audio_translation_paths/main/cli.c?view=diff&rev=280705&r1=280704&r2=280705
==============================================================================
--- team/dvossel/improved_hd_audio_translation_paths/main/cli.c (original)
+++ team/dvossel/improved_hd_audio_translation_paths/main/cli.c Mon Aug  2 17:57:33 2010
@@ -1343,7 +1343,9 @@
 	struct timeval now;
 	struct ast_str *out = ast_str_thread_get(&ast_str_thread_global_buf, 16);
 	char cdrtime[256];
-	char nf[256], wf[256], rf[256], write_transpath[256], read_transpath[256];
+	char nf[256], wf[256], rf[256];
+	struct ast_str *write_transpath = ast_str_alloca(256);
+	struct ast_str *read_transpath = ast_str_alloca(256);
 	long elapsed_seconds=0;
 	int hour=0, min=0, sec=0;
 #ifdef CHANNEL_TRACE
@@ -1427,9 +1429,9 @@
 		ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), 
 		ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
 		c->writetrans ? "Yes" : "No",
-		ast_translate_path_to_str(c->writetrans, write_transpath, sizeof(write_transpath)),
+		ast_translate_path_to_str(c->writetrans, &write_transpath),
 		c->readtrans ? "Yes" : "No",
-		ast_translate_path_to_str(c->readtrans, read_transpath, sizeof(read_transpath)),
+		ast_translate_path_to_str(c->readtrans, &read_transpath),
 		c->fds[0],
 		c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
 		c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",

Modified: team/dvossel/improved_hd_audio_translation_paths/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/improved_hd_audio_translation_paths/main/translate.c?view=diff&rev=280705&r1=280704&r2=280705
==============================================================================
--- team/dvossel/improved_hd_audio_translation_paths/main/translate.c (original)
+++ team/dvossel/improved_hd_audio_translation_paths/main/translate.c Mon Aug  2 17:57:33 2010
@@ -558,64 +558,135 @@
 	}
 }
 
-char *ast_translate_path_to_str(struct ast_trans_pvt *p, char *outbuf, size_t outlen)
+char *ast_translate_path_to_str(struct ast_trans_pvt *p, struct ast_str **str)
 {
 	struct ast_trans_pvt *pn = p;
-	char *orig_out = outbuf;
-	int namelen;
-	int writelen = 0;
-	if (!outbuf || !outlen) {
-		return "";
-	}
-
-	memset(outbuf, 0, outlen);
 
 	if (!p || !p->t) {
 		return "";
 	}
 
-	snprintf(outbuf, (outlen - writelen), "%s", ast_getformatname(1LL << p->t->srcfmt));
-	writelen = strlen(orig_out);
-	outbuf = orig_out + writelen;
-
-	while ( (p = pn) && (outlen > writelen)) {
+	ast_str_set(str, 0, "%s", ast_getformatname(1LL << p->t->srcfmt));
+
+	while ( (p = pn) ) {
 		pn = p->next;
-		namelen = strlen(p->t->name);
-		if ((outlen - writelen) < namelen) {
-			return "";
-		}
-		snprintf(outbuf, (outlen - writelen), "->%s", ast_getformatname(1LL << p->t->dstfmt));
-		writelen = strlen(orig_out);
-		outbuf = orig_out + writelen;
-	}
-
-	return orig_out;
+		ast_str_append(str, 0, "->%s", ast_getformatname(1LL << p->t->dstfmt));
+	}
+
+	return ast_str_buffer(*str);
+}
+
+static char *complete_trans_path_choice(const char *line, const char *word, int pos, int state)
+{
+	int which = 0;
+	int wordlen = strlen(word);
+	int i;
+	char *ret = NULL;
+	size_t len = 0;
+	const struct ast_format_list *format_list = ast_get_format_list(&len);
+
+	for (i = 0; i < len; i++) {
+		if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK)) {
+			continue;
+		}
+		if (!strncasecmp(word, format_list[i].name, wordlen) && ++which > state) {
+			ret = ast_strdup(format_list[i].name);
+			break;
+		}
+	}
+	return ret;
 }
 
 static char *handle_cli_core_show_translation(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 #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, };
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "core show translation [recalc]";
+		e->command = "core show translation";
 		e->usage =
-			"Usage: core show translation [recalc [<recalc seconds>]]\n"
-			"       Displays known codec translators and the cost associated\n"
-			"       with each conversion.  If the argument 'recalc' is supplied along\n"
-			"       with optional number of seconds to test a new test will be performed\n"
-			"       as the chart is being displayed.\n";
+			"Usage: 'core show translation' can be used in two ways.\n"
+			"       1. 'core show translation [recalc [<recalc seconds>]]\n"
+			"          Displays known codec translators and the cost associated\n"
+			"          with each conversion.  If the argument 'recalc' is supplied along\n"
+			"          with optional number of seconds to test a new test will be performed\n"
+			"          as the chart is being displayed.\n"
+			"       2. 'core show translation paths [codec]'\n"
+			"           This will display all the translation paths associated with a codec\n";
 		return NULL;
 	case CLI_GENERATE:
+		if (a->pos == 3) {
+			return ast_cli_complete(a->word, option1, a->n);
+		}
+		if (a->pos == 4 && !strcasecmp(a->argv[3], option1[1])) {
+			return complete_trans_path_choice(a->line, a->word, a->pos, a->n);
+		}
 		return NULL;
 	}
 
 	if (a->argc > 5)
 		return CLI_SHOWUSAGE;
 
-	if (a->argv[3] && !strcasecmp(a->argv[3], "recalc")) {
+	if (a->argv[3] && !strcasecmp(a->argv[3], option1[1]) && a->argc == 5) {
+		format_t input_src = 0;
+		format_t src = 0;
+		size_t len = 0;
+		int dst;
+		int i;
+		const struct ast_format_list *format_list = ast_get_format_list(&len);
+		struct ast_str *str = ast_str_alloca(256);
+		struct ast_translator *step;
+
+		for (i = 0; i < len; i++) {
+			if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK)) {
+				continue;
+			}
+			if (!strncasecmp(format_list[i].name, a->argv[4], strlen(format_list[i].name))) {
+				input_src = format_list[i].bits;
+			}
+		}
+
+		if (!input_src) {
+			ast_cli(a->fd, "Source codec \"%s\" is not found.\n", a->argv[4]);
+			return CLI_FAILURE;
+		}
+
+		AST_RWLIST_RDLOCK(&translators);
+		ast_cli(a->fd, "--- Translation paths SRC Codec \"%s\" sample rate %d ---\n", a->argv[4], ast_format_rate(src));
+		for (i = 0; i < len; i++) {
+			if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK)) {
+				continue;
+			}
+			dst = powerof(format_list[i].bits);
+			src = powerof(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));
+				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));
+					src = step->dstfmt;
+				}
+			}
+
+			if (ast_strlen_zero(ast_str_buffer(str))) {
+				ast_str_set(&str, 0, "No Translation Path");
+			}
+
+			ast_cli(a->fd, "\t%-10.10s To %-10.10s: %-60.60s\n", a->argv[4], format_list[i].name, ast_str_buffer(str));
+		}
+		AST_RWLIST_UNLOCK(&translators);
+
+		return CLI_SUCCESS;
+	} else if (a->argv[3] && !strcasecmp(a->argv[3], "recalc")) {
 		z = a->argv[4] ? atoi(a->argv[4]) : 1;
 
 		if (z <= 0) {




More information about the asterisk-commits mailing list