[asterisk-commits] dvossel: branch dvossel/improved_hd_audio_translation_paths r280738 - /team/d...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 3 13:38:20 CDT 2010
Author: dvossel
Date: Tue Aug 3 13:38:17 2010
New Revision: 280738
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=280738
Log:
fixes a few issues with the first hd translation path patches
Modified:
team/dvossel/improved_hd_audio_translation_paths/main/translate.c
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=280738&r1=280737&r2=280738
==============================================================================
--- team/dvossel/improved_hd_audio_translation_paths/main/translate.c (original)
+++ team/dvossel/improved_hd_audio_translation_paths/main/translate.c Tue Aug 3 13:38:17 2010
@@ -420,7 +420,6 @@
int src_rate = ast_format_rate(src);
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;
@@ -442,6 +441,7 @@
{
struct ast_translator *t;
int new_rate_change;
+ int newcost;
int x; /* source format index */
int y; /* intermediate format index */
int z; /* destination format index */
@@ -486,15 +486,12 @@
*/
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 */
continue;
-
for (z = 0; z < MAX_FORMAT; z++) { /* dst format */
- int newcost;
- int better_rate_conversion = 0;
-
if (z == x || z == y) /* skip null conversions */
continue;
if (!tr_matrix[x][y].step) /* no path from x to y */
@@ -511,22 +508,32 @@
continue;
}
- /* is x->y->z a better rate confersion that the current x->z? */
- better_rate_conversion = (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)) ? 1 : 0;
-
+ /* 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 more expensive the the existing path?
- * A higher quality sample rate conversion will always beat
- * a cost improvement though. */
- if (!better_rate_conversion && tr_matrix[x][z].step && (newcost >= tr_matrix[x][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 */
+ 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;
@@ -545,7 +552,6 @@
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));
@@ -655,14 +661,13 @@
}
AST_RWLIST_RDLOCK(&translators);
- ast_cli(a->fd, "--- Translation paths SRC Codec \"%s\" sample rate %d ---\n", a->argv[4], ast_format_rate(src));
+ ast_cli(a->fd, "--- Translation paths SRC Codec \"%s\" sample rate %d ---\n", a->argv[4], ast_format_rate(input_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));
@@ -911,37 +916,65 @@
format_t ast_translator_best_choice(format_t *dst, format_t *srcs)
{
int x,y;
+ int better = 0;
+ int besttime = 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;
- int besttime = INT_MAX;
- int beststeps = INT_MAX;
format_t common = ((*dst) & (*srcs)) & AST_FORMAT_AUDIO_MASK; /* are there common formats ? */
if (common) { /* yes, pick one and return */
for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
- if (cur & common) /* guaranteed to find one */
- break;
+ if (!(cur & common)) {
+ continue;
+ }
+
+ /* We are guaranteed to find one common format. */
+ if (best == -1) {
+ best = cur;
+ continue;
+ }
+ /* If there are multiple common formats, pick the one with the highest sample rate */
+ if (ast_format_rate(best) < ast_format_rate(cur)) {
+ best = cur;
+ continue;
+ }
}
/* We are done, this is a common format to both. */
- *srcs = *dst = cur;
+ *srcs = *dst = best;
return 0;
- } else { /* No, we will need to translate */
+ } else { /* No, we will need to translate */
AST_RWLIST_RDLOCK(&translators);
for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
- if (! (cur & *dst))
+ if (! (cur & *dst)) {
continue;
+ }
for (cursrc = 1, x = 0; x <= MAX_AUDIO_FORMAT; cursrc <<= 1, x++) {
- if (!(*srcs & cursrc) || !tr_matrix[x][y].step ||
- tr_matrix[x][y].cost > besttime)
- continue; /* not existing or no better */
- if (tr_matrix[x][y].cost < besttime ||
- tr_matrix[x][y].multistep < beststeps) {
+ 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) {
/* better than what we have so far */
best = cursrc;
bestdst = cur;
besttime = tr_matrix[x][y].cost;
beststeps = tr_matrix[x][y].multistep;
+ best_rate_change = tr_matrix[x][y].rate_change;
}
}
}
More information about the asterisk-commits
mailing list