mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-07 10:28:32 +00:00
factor the number of translation steps required into translation path decisions, so that equal cost paths that require fewer translations are preferred
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@11089 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
27
translate.c
27
translate.c
@@ -454,14 +454,14 @@ int ast_translator_best_choice(int *dst, int *srcs)
|
|||||||
int bestdst = 0;
|
int bestdst = 0;
|
||||||
int cur = 1;
|
int cur = 1;
|
||||||
int besttime = INT_MAX;
|
int besttime = INT_MAX;
|
||||||
|
int beststeps = INT_MAX;
|
||||||
int common;
|
int common;
|
||||||
|
|
||||||
if ((common = (*dst) & (*srcs))) {
|
if ((common = (*dst) & (*srcs))) {
|
||||||
/* We have a format in common */
|
/* We have a format in common */
|
||||||
for (y=0; y < MAX_FORMAT; y++) {
|
for (y = 0; y < MAX_FORMAT; y++) {
|
||||||
if (cur & common) {
|
if (cur & common) {
|
||||||
/* This is a common format to both. Pick it if we don't have one already */
|
/* This is a common format to both. Pick it if we don't have one already */
|
||||||
besttime = 0;
|
|
||||||
bestdst = cur;
|
bestdst = cur;
|
||||||
best = cur;
|
best = cur;
|
||||||
}
|
}
|
||||||
@@ -470,25 +470,38 @@ int ast_translator_best_choice(int *dst, int *srcs)
|
|||||||
} else {
|
} else {
|
||||||
/* We will need to translate */
|
/* We will need to translate */
|
||||||
ast_mutex_lock(&list_lock);
|
ast_mutex_lock(&list_lock);
|
||||||
for (y=0; y < MAX_FORMAT; y++) {
|
for (y = 0; y < MAX_FORMAT; y++) {
|
||||||
if (cur & *dst)
|
if (!(cur & *dst))
|
||||||
for (x=0; x < MAX_FORMAT; x++) {
|
continue;
|
||||||
|
|
||||||
|
for (x = 0; x < MAX_FORMAT; x++) {
|
||||||
if ((*srcs & (1 << x)) && /* x is a valid source format */
|
if ((*srcs & (1 << x)) && /* x is a valid source format */
|
||||||
tr_matrix[x][y].step && /* There's a step */
|
tr_matrix[x][y].step) { /* There's a step */
|
||||||
(tr_matrix[x][y].cost < besttime)) { /* It's better than what we have so far */
|
if (tr_matrix[x][y].cost > besttime)
|
||||||
|
continue; /* It's more expensive, skip it */
|
||||||
|
|
||||||
|
if (tr_matrix[x][y].cost == besttime &&
|
||||||
|
tr_matrix[x][y].multistep >= beststeps)
|
||||||
|
continue; /* It requires the same (or more) steps,
|
||||||
|
skip it */
|
||||||
|
|
||||||
|
/* It's better than what we have so far */
|
||||||
best = 1 << x;
|
best = 1 << x;
|
||||||
bestdst = cur;
|
bestdst = cur;
|
||||||
besttime = tr_matrix[x][y].cost;
|
besttime = tr_matrix[x][y].cost;
|
||||||
|
beststeps = tr_matrix[x][y].multistep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = cur << 1;
|
cur = cur << 1;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&list_lock);
|
ast_mutex_unlock(&list_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best > -1) {
|
if (best > -1) {
|
||||||
*srcs = best;
|
*srcs = best;
|
||||||
*dst = bestdst;
|
*dst = bestdst;
|
||||||
best = 0;
|
best = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user