don't re-do setup operations for translators that can dynamically register themselves

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@46711 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2006-10-31 21:23:06 +00:00
parent 93e3d1157b
commit 59186bb2d2
2 changed files with 50 additions and 40 deletions

View File

@@ -108,6 +108,7 @@ struct ast_translator {
struct ast_module *module; /* opaque reference to the parent module */
int cost; /*!< Cost in milliseconds for encoding/decoding 1 second of sound */
int seen; /*!< If we have seen this translator before (optimize re-registration) */
AST_LIST_ENTRY(ast_translator) list; /*!< link field */
};

View File

@@ -650,6 +650,7 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
return -1;
}
if (!t->seen) {
if (!t->buf_size) {
ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
return -1;
@@ -690,18 +691,24 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
t->frameout = default_frameout;
calc_cost(t, 1);
t->seen = 1;
}
if (option_verbose > 1) {
char tmp[80];
ast_verbose(VERBOSE_PREFIX_2 "Registered translator '%s' from format %s to %s, cost %d\n",
term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
}
AST_LIST_LOCK(&translators);
if (!added_cli) {
ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry));
added_cli++;
}
AST_LIST_LOCK(&translators);
/* 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) {
@@ -720,7 +727,9 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
AST_LIST_INSERT_HEAD(&translators, t, list);
rebuild_matrix(0);
AST_LIST_UNLOCK(&translators);
return 0;
}