[asterisk-commits] kpfleming: trunk r46719 - in /trunk: ./ include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Oct 31 15:19:08 MST 2006


Author: kpfleming
Date: Tue Oct 31 16:19:08 2006
New Revision: 46719

URL: http://svn.digium.com/view/asterisk?rev=46719&view=rev
Log:
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

........

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/translate.h
    trunk/main/translate.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/include/asterisk/translate.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/translate.h?rev=46719&r1=46718&r2=46719&view=diff
==============================================================================
--- trunk/include/asterisk/translate.h (original)
+++ trunk/include/asterisk/translate.h Tue Oct 31 16:19:08 2006
@@ -108,6 +108,7 @@
 	struct ast_module *module;	/* opaque reference to the parent module */
 
 	int cost;			/*!< Cost in milliseconds for encoding/decoding 1 second of sound */
+	int active;			/*!< Whether this translator should be used or not */
 	AST_LIST_ENTRY(ast_translator) list;	/*!< link field */
 };
 
@@ -167,6 +168,24 @@
 int ast_unregister_translator(struct ast_translator *t);
 
 /*!
+ * \brief Activate a previously deactivated translator
+ * \param t translator to activate
+ * \return nothing
+ *
+ * Enables the specified translator for use.
+ */
+void ast_translator_activate(struct ast_translator *t);
+
+/*!
+ * \brief Deactivate a translator
+ * \param t translator to deactivate
+ * \return nothing
+ *
+ * Disables the specified translator from being used.
+ */
+void ast_translator_deactivate(struct ast_translator *t);
+
+/*!
  * \brief Chooses the best translation path
  *
  * Given a list of sources, and a designed destination format, which should

Modified: trunk/main/translate.c
URL: http://svn.digium.com/view/asterisk/trunk/main/translate.c?rev=46719&r1=46718&r2=46719&view=diff
==============================================================================
--- trunk/main/translate.c (original)
+++ trunk/main/translate.c Tue Oct 31 16:19:08 2006
@@ -427,6 +427,9 @@
 
 	/* 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 @@
 	}
 
 	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 @@
 			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,23 +617,29 @@
 		*/
 		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);
-	}
-	AST_LIST_LOCK(&translators);
+			    term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
+			    ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
+	}
+
 	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 */
@@ -646,7 +659,9 @@
 		AST_LIST_INSERT_HEAD(&translators, t, list);
 
 	rebuild_matrix(0);
+
 	AST_LIST_UNLOCK(&translators);
+
 	return 0;
 }
 
@@ -675,6 +690,22 @@
 	AST_LIST_UNLOCK(&translators);
 
 	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 */



More information about the asterisk-commits mailing list