diff options
author | Kevin P. Fleming <kpfleming@digium.com> | 2006-10-31 22:19:08 +0000 |
---|---|---|
committer | Kevin P. Fleming <kpfleming@digium.com> | 2006-10-31 22:19:08 +0000 |
commit | 39a47000475f9b5dae0b5962a8e526363190a4e1 (patch) | |
tree | 4600fef53179e600e5f1780a42345b1f9704590f /main/translate.c | |
parent | 8b9ef26a4508205525dbee3c3f260be3bfe8d662 (diff) |
Merged revisions 46714 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r46714 | kpfleming | 2006-10-31 15:47:48 -0600 (Tue, 31 Oct 2006) | 2 lines
add an API so that translators can activate/deactivate themselves when needed
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@46719 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/translate.c')
-rw-r--r-- | main/translate.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/main/translate.c b/main/translate.c index df79c5a22..a576c811b 100644 --- a/main/translate.c +++ b/main/translate.c @@ -427,6 +427,9 @@ static void rebuild_matrix(int samples) /* first, compute all direct costs */ AST_LIST_TRAVERSE(&translators, t, list) { + if (!t->active) + continue; + x = t->srcfmt; z = t->dstfmt; @@ -582,6 +585,11 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) } t->module = mod; + + t->srcfmt = powerof(t->srcfmt); + t->dstfmt = powerof(t->dstfmt); + t->active = 1; + if (t->plc_samples) { if (t->buffer_samples < t->plc_samples) { ast_log(LOG_WARNING, "plc_samples %d buffer_samples %d\n", @@ -592,17 +600,16 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) ast_log(LOG_WARNING, "plc_samples %d format %x\n", t->plc_samples, t->dstfmt); } - t->srcfmt = powerof(t->srcfmt); - t->dstfmt = powerof(t->dstfmt); - /* XXX maybe check that it is not existing yet ? */ if (t->srcfmt >= MAX_FORMAT) { ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt)); return -1; } + if (t->dstfmt >= MAX_FORMAT) { ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt)); return -1; } + if (t->buf_size) { /* * Align buf_size properly, rounding up to the machine-specific @@ -610,24 +617,30 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) */ 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); + 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); + 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) { @@ -646,7 +659,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; } @@ -677,6 +692,22 @@ int ast_unregister_translator(struct ast_translator *t) return (u ? 0 : -1); } +void ast_translator_activate(struct ast_translator *t) +{ + AST_LIST_LOCK(&translators); + t->active = 1; + rebuild_matrix(0); + AST_LIST_UNLOCK(&translators); +} + +void ast_translator_deactivate(struct ast_translator *t) +{ + AST_LIST_LOCK(&translators); + t->active = 0; + rebuild_matrix(0); + AST_LIST_UNLOCK(&translators); +} + /*! \brief Calculate our best translator source format, given costs, and a desired destination */ int ast_translator_best_choice(int *dst, int *srcs) { |