[asterisk-commits] file: trunk r74570 - in /trunk: apps/ include/asterisk/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 11 11:19:01 CDT 2007


Author: file
Date: Wed Jul 11 11:19:00 2007
New Revision: 74570

URL: http://svn.digium.com/view/asterisk?view=rev&rev=74570
Log:
Allow the native formats of a channel to influence the audio that is going to the engine. The best format will try to be chosen with an ultimate fallback to signed linear if possible.

Modified:
    trunk/apps/app_speech_utils.c
    trunk/include/asterisk/speech.h
    trunk/res/res_speech.c

Modified: trunk/apps/app_speech_utils.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_speech_utils.c?view=diff&rev=74570&r1=74569&r2=74570
==============================================================================
--- trunk/apps/app_speech_utils.c (original)
+++ trunk/apps/app_speech_utils.c Wed Jul 11 11:19:00 2007
@@ -352,7 +352,7 @@
 	u = ast_module_user_add(chan);
 
 	/* Request a speech object */
-	speech = ast_speech_new(data, AST_FORMAT_SLINEAR);
+	speech = ast_speech_new(data, chan->nativeformats);
 	if (speech == NULL) {
 		/* Not available */
 		pbx_builtin_setvar_helper(chan, "ERROR", "1");
@@ -572,7 +572,7 @@
         oldreadformat = chan->readformat;
 
         /* Change read format to be signed linear */
-        if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) {
+        if (ast_set_read_format(chan, speech->format)) {
                 ast_module_user_remove(u);
                 return -1;
         }

Modified: trunk/include/asterisk/speech.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/speech.h?view=diff&rev=74570&r1=74569&r2=74570
==============================================================================
--- trunk/include/asterisk/speech.h (original)
+++ trunk/include/asterisk/speech.h Wed Jul 11 11:19:00 2007
@@ -128,7 +128,7 @@
 /*! \brief Indicate to the speech engine that audio is now going to start being written */
 void ast_speech_start(struct ast_speech *speech);
 /*! \brief Create a new speech structure */
-struct ast_speech *ast_speech_new(char *engine_name, int format);
+struct ast_speech *ast_speech_new(char *engine_name, int formats);
 /*! \brief Destroy a speech structure */
 int ast_speech_destroy(struct ast_speech *speech);
 /*! \brief Write audio to the speech engine */

Modified: trunk/res/res_speech.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_speech.c?view=diff&rev=74570&r1=74569&r2=74570
==============================================================================
--- trunk/res/res_speech.c (original)
+++ trunk/res/res_speech.c Wed Jul 11 11:19:00 2007
@@ -159,17 +159,22 @@
 }
 
 /*! \brief Create a new speech structure using the engine specified */
-struct ast_speech *ast_speech_new(char *engine_name, int format)
+struct ast_speech *ast_speech_new(char *engine_name, int formats)
 {
 	struct ast_speech_engine *engine = NULL;
 	struct ast_speech *new_speech = NULL;
+	int format = AST_FORMAT_SLINEAR;
 
 	/* Try to find the speech recognition engine that was requested */
 	if (!(engine = find_engine(engine_name)))
 		return NULL;
 
-	/* Make sure the requested format fits */
-	if (!(engine->formats & format))
+	/* Before even allocating the memory below do some codec negotiation, we choose the best codec possible and fall back to signed linear if possible */
+	if ((format = (engine->formats & formats)))
+		format = ast_best_codec(format);
+	else if ((engine->formats & AST_FORMAT_SLINEAR))
+		format = AST_FORMAT_SLINEAR;
+	else
 		return NULL;
 
 	/* Allocate our own speech structure, and try to allocate a structure from the engine too */




More information about the asterisk-commits mailing list