diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-10-24 23:45:19 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-10-24 23:45:19 +0000 |
commit | 7867ef4b6a4a669457bb7a8b4f0e4ba3c6ac0513 (patch) | |
tree | ff842870c5bafcfdcbaa4f251d9b9c3e45b9c000 /main/translate.c | |
parent | 3ffb3ce9b3e8760e723c7bb73826ecde4a5894a8 (diff) |
if multiple translators are registered for the same source/dest combination, ensure that the lowest-cost one is always inserted earlier in the list
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@46152 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/translate.c')
-rw-r--r-- | main/translate.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/main/translate.c b/main/translate.c index 7b5ad0fc5..7cfd851a6 100644 --- a/main/translate.c +++ b/main/translate.c @@ -644,6 +644,7 @@ static struct ast_cli_entry cli_translate[] = { 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 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) 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 @@ int ast_unregister_translator(struct ast_translator *t) break; } } - AST_LIST_TRAVERSE_SAFE_END + AST_LIST_TRAVERSE_SAFE_END; rebuild_matrix(0); AST_LIST_UNLOCK(&translators); return (u ? 0 : -1); |