[asterisk-commits] kpfleming: branch 1.4 r46152 -
/branches/1.4/main/translate.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Oct 24 16:45:19 MST 2006
Author: kpfleming
Date: Tue Oct 24 18:45:19 2006
New Revision: 46152
URL: http://svn.digium.com/view/asterisk?rev=46152&view=rev
Log:
if multiple translators are registered for the same source/dest combination, ensure that the lowest-cost one is always inserted earlier in the list
Modified:
branches/1.4/main/translate.c
Modified: branches/1.4/main/translate.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/translate.c?rev=46152&r1=46151&r2=46152&view=diff
==============================================================================
--- branches/1.4/main/translate.c (original)
+++ branches/1.4/main/translate.c Tue Oct 24 18:45:19 2006
@@ -644,6 +644,7 @@
int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
{
static int added_cli = 0;
+ struct ast_translator *u;
if (!mod) {
ast_log(LOG_WARNING, "Missing module pointer, you need to supply one\n");
@@ -701,7 +702,24 @@
ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry));
added_cli++;
}
- AST_LIST_INSERT_HEAD(&translators, t, list);
+
+ /* find any existing translators that provide this same srcfmt/dstfmt,
+ and put this one in order based on cost */
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
+ if ((u->srcfmt == t->srcfmt) &&
+ (u->dstfmt == t->dstfmt) &&
+ (u->cost > t->cost)) {
+ AST_LIST_INSERT_BEFORE_CURRENT(&translators, t, list);
+ t = NULL;
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+
+ /* if no existing translator was found for this format combination,
+ add it to the beginning of the list */
+ if (t)
+ AST_LIST_INSERT_HEAD(&translators, t, list);
+
rebuild_matrix(0);
AST_LIST_UNLOCK(&translators);
return 0;
@@ -721,7 +739,7 @@
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
+ AST_LIST_TRAVERSE_SAFE_END;
rebuild_matrix(0);
AST_LIST_UNLOCK(&translators);
return (u ? 0 : -1);
More information about the asterisk-commits
mailing list