mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
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:
@@ -108,6 +108,7 @@ struct ast_translator {
|
|||||||
struct ast_module *module; /* opaque reference to the parent module */
|
struct ast_module *module; /* opaque reference to the parent module */
|
||||||
|
|
||||||
int cost; /*!< Cost in milliseconds for encoding/decoding 1 second of sound */
|
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 */
|
AST_LIST_ENTRY(ast_translator) list; /*!< link field */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -650,58 +650,65 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!t->buf_size) {
|
if (!t->seen) {
|
||||||
ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
|
if (!t->buf_size) {
|
||||||
return -1;
|
ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
|
||||||
}
|
|
||||||
|
|
||||||
t->module = mod;
|
|
||||||
if (t->plc_samples) {
|
|
||||||
if (t->buffer_samples < t->plc_samples) {
|
|
||||||
ast_log(LOG_WARNING, "plc_samples %d buffer_samples %d\n",
|
|
||||||
t->plc_samples, t->buffer_samples);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (t->dstfmt != AST_FORMAT_SLINEAR)
|
|
||||||
ast_log(LOG_WARNING, "plc_samples %d format %x\n",
|
t->module = mod;
|
||||||
t->plc_samples, t->dstfmt);
|
if (t->plc_samples) {
|
||||||
}
|
if (t->buffer_samples < t->plc_samples) {
|
||||||
t->srcfmt = powerof(t->srcfmt);
|
ast_log(LOG_WARNING, "plc_samples %d buffer_samples %d\n",
|
||||||
t->dstfmt = powerof(t->dstfmt);
|
t->plc_samples, t->buffer_samples);
|
||||||
/* XXX maybe check that it is not existing yet ? */
|
return -1;
|
||||||
if (t->srcfmt >= MAX_FORMAT) {
|
}
|
||||||
ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
|
if (t->dstfmt != AST_FORMAT_SLINEAR)
|
||||||
return -1;
|
ast_log(LOG_WARNING, "plc_samples %d format %x\n",
|
||||||
}
|
t->plc_samples, t->dstfmt);
|
||||||
if (t->dstfmt >= MAX_FORMAT) {
|
}
|
||||||
ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
|
t->srcfmt = powerof(t->srcfmt);
|
||||||
return -1;
|
t->dstfmt = powerof(t->dstfmt);
|
||||||
}
|
/* XXX maybe check that it is not existing yet ? */
|
||||||
if (t->buf_size) {
|
if (t->srcfmt >= MAX_FORMAT) {
|
||||||
/*
|
ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
|
||||||
* Align buf_size properly, rounding up to the machine-specific
|
return -1;
|
||||||
* alignment for pointers.
|
}
|
||||||
*/
|
if (t->dstfmt >= MAX_FORMAT) {
|
||||||
struct _test_align { void *a, *b; } p;
|
ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
|
||||||
int align = (char *)&p.b - (char *)&p.a;
|
return -1;
|
||||||
t->buf_size = ((t->buf_size + align - 1) / align) * align;
|
}
|
||||||
}
|
if (t->buf_size) {
|
||||||
if (t->frameout == NULL)
|
/*
|
||||||
t->frameout = default_frameout;
|
* Align buf_size properly, rounding up to the machine-specific
|
||||||
|
* alignment for pointers.
|
||||||
|
*/
|
||||||
|
struct _test_align { void *a, *b; } p;
|
||||||
|
int align = (char *)&p.b - (char *)&p.a;
|
||||||
|
t->buf_size = ((t->buf_size + align - 1) / align) * align;
|
||||||
|
}
|
||||||
|
if (t->frameout == NULL)
|
||||||
|
t->frameout = default_frameout;
|
||||||
|
|
||||||
calc_cost(t, 1);
|
calc_cost(t, 1);
|
||||||
|
|
||||||
|
t->seen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (option_verbose > 1) {
|
if (option_verbose > 1) {
|
||||||
char tmp[80];
|
char tmp[80];
|
||||||
ast_verbose(VERBOSE_PREFIX_2 "Registered translator '%s' from format %s to %s, cost %d\n",
|
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)),
|
term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
|
||||||
ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
|
ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
|
||||||
}
|
}
|
||||||
AST_LIST_LOCK(&translators);
|
|
||||||
if (!added_cli) {
|
if (!added_cli) {
|
||||||
ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry));
|
ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry));
|
||||||
added_cli++;
|
added_cli++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AST_LIST_LOCK(&translators);
|
||||||
|
|
||||||
/* find any existing translators that provide this same srcfmt/dstfmt,
|
/* find any existing translators that provide this same srcfmt/dstfmt,
|
||||||
and put this one in order based on cost */
|
and put this one in order based on cost */
|
||||||
AST_LIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
|
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);
|
AST_LIST_INSERT_HEAD(&translators, t, list);
|
||||||
|
|
||||||
rebuild_matrix(0);
|
rebuild_matrix(0);
|
||||||
|
|
||||||
AST_LIST_UNLOCK(&translators);
|
AST_LIST_UNLOCK(&translators);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user