[asterisk-commits] file: branch group/media_formats r408266 - in /team/group/media_formats: apps...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 17 07:32:01 CST 2014


Author: file
Date: Mon Feb 17 07:31:59 2014
New Revision: 408266

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408266
Log:
Move res_speech over.

Modified:
    team/group/media_formats/apps/app_speech_utils.c
    team/group/media_formats/include/asterisk/speech.h
    team/group/media_formats/res/res_speech.c

Modified: team/group/media_formats/apps/app_speech_utils.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_speech_utils.c?view=diff&rev=408266&r1=408265&r2=408266
==============================================================================
--- team/group/media_formats/apps/app_speech_utils.c (original)
+++ team/group/media_formats/apps/app_speech_utils.c Mon Feb 17 07:31:59 2014
@@ -702,7 +702,7 @@
 	oldreadformat = ast_format_copy(ast_channel_readformat(chan));
 
 	/* Change read format to be signed linear */
-	if (ast_set_read_format(chan, &speech->format))
+	if (ast_set_read_format(chan, speech->format))
 		return -1;
 
 	if (!ast_strlen_zero(args.soundfile)) {

Modified: team/group/media_formats/include/asterisk/speech.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/speech.h?view=diff&rev=408266&r1=408265&r2=408266
==============================================================================
--- team/group/media_formats/include/asterisk/speech.h (original)
+++ team/group/media_formats/include/asterisk/speech.h Mon Feb 17 07:31:59 2014
@@ -58,7 +58,7 @@
 	/*! Current state of structure */
 	int state;
 	/*! Expected write format */
-	struct ast_format format;
+	struct ast_format *format;
 	/*! Data for speech engine */
 	void *data;
 	/*! Cached results */

Modified: team/group/media_formats/res/res_speech.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_speech.c?view=diff&rev=408266&r1=408265&r2=408266
==============================================================================
--- team/group/media_formats/res/res_speech.c (original)
+++ team/group/media_formats/res/res_speech.c Mon Feb 17 07:31:59 2014
@@ -38,7 +38,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
 #include "asterisk/speech.h"
-
+#include "asterisk/format_cache.h"
 
 static AST_RWLIST_HEAD_STATIC(engines, ast_speech_engine);
 static struct ast_speech_engine *default_engine = NULL;
@@ -183,26 +183,34 @@
 {
 	struct ast_speech_engine *engine = NULL;
 	struct ast_speech *new_speech = NULL;
-	struct ast_format_cap *joint = NULL;
-	struct ast_format best;
-
-	ast_format_set(&best, AST_FORMAT_SLINEAR, 0);
-
+	struct ast_format_cap *joint;
+	struct ast_format *best;
 	/* Try to find the speech recognition engine that was requested */
 	if (!(engine = find_engine(engine_name)))
 		return NULL;
 
-	/* 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 ((joint = ast_format_cap_joint(engine->formats, cap))) {
-		ast_best_codec(joint, &best);
-		joint = ast_format_cap_destroy(joint);
-	} else if (!ast_format_cap_iscompatible(engine->formats, &best)) {
+	joint = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!joint) {
 		return NULL;
 	}
 
+	ast_format_cap_get_compatible(engine->formats, cap, joint);
+	best = ast_format_cap_get_format(joint, 0);
+	ao2_ref(joint, -1);
+
+	if (!best) {
+		if (ast_format_cap_iscompatible_format(engine->formats, ast_format_slin)) {
+			best = ast_format_copy(ast_format_slin);
+		} else {
+			return NULL;
+		}
+	}
+
 	/* Allocate our own speech structure, and try to allocate a structure from the engine too */
-	if (!(new_speech = ast_calloc(1, sizeof(*new_speech))))
+	if (!(new_speech = ast_calloc(1, sizeof(*new_speech)))) {
+		ao2_ref(best, -1);
 		return NULL;
+	}
 
 	/* Initialize the lock */
 	ast_mutex_init(&new_speech->lock);
@@ -214,14 +222,15 @@
 	new_speech->engine = engine;
 
 	/* Can't forget the format audio is going to be in */
-	ast_format_copy(&new_speech->format, &best);
+	new_speech->format = best;
 
 	/* We are not ready to accept audio yet */
 	ast_speech_change_state(new_speech, AST_SPEECH_STATE_NOT_READY);
 
 	/* Pass ourselves to the engine so they can set us up some more and if they error out then do not create a structure */
-	if (engine->create(new_speech, &best)) {
+	if (engine->create(new_speech, best)) {
 		ast_mutex_destroy(&new_speech->lock);
+		ao2_ref(best, -1);
 		ast_free(new_speech);
 		new_speech = NULL;
 	}
@@ -247,6 +256,8 @@
 	/* If a processing sound is set - free the memory used by it */
 	if (speech->processing_sound)
 		ast_free(speech->processing_sound);
+
+	ao2_ref(speech->format, -1);
 
 	/* Aloha we are done */
 	ast_free(speech);




More information about the asterisk-commits mailing list