Freeswitch-trunk
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
August 2007
- 6 participants
- 110 discussions
19 Aug '07
Author: mikej
Date: Sun Aug 19 01:01:08 2007
New Revision: 5610
Added:
freeswitch/trunk/src/include/switch_version.h.template
Removed:
freeswitch/trunk/src/include/switch_version.h.in
Modified:
freeswitch/trunk/Makefile.am
freeswitch/trunk/configure.in
freeswitch/trunk/w32/Library/FreeSwitchCore.vcproj
Log:
modify how we build switch_version.h so we can better handle releases
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Sun Aug 19 01:01:08 2007
@@ -161,13 +161,20 @@
touch .version
src/include/switch_version.h: $(top_srcdir)/src/include/switch_version.h.in .version $(libfreeswitch_la_SOURCES) $(library_include_HEADERS)
- @force=0 ; \
- version=`svnversion . -n || echo hacked` ; \
- oldversion=`cat .version 2>/dev/null || echo "0"` ; \
- test ! -f src/include/switch_version.h || grep "@SVN_VERSION@" src/include/switch_version.h && force=1 ; \
- if test "$$oldversion" != "$$version" || test $$force = 1 ; then \
- cat src/include/switch_version.h.in | sed "s/@SVN_VERSION@/$$version/g" > src/include/switch_version.h ; \
- echo $$version > .version ; \
+ @have_version=1 ; \
+ force=0 ; \
+ grep "@SWITCH_VERSION_REVISION@" src/include/switch_version.h.in > /dev/null && have_version=0 ; \
+ test ! -f src/include/switch_version.h || grep "@SWITCH_VERSION_REVISION@" src/include/switch_version.h > /dev/null && force=1 ; \
+ if test $$have_version = 1 ; then \
+ cat src/include/switch_version.h.in > src/include/switch_version.h ; \
+ touch .version ; \
+ else \
+ version=`svnversion . -n || echo hacked` ; \
+ oldversion=`cat .version 2>/dev/null || echo "0"` ; \
+ if test "$$oldversion" != "$$version" || test $$force = 1 ; then \
+ cat src/include/switch_version.h.in | sed "s/@SWITCH_VERSION_REVISION@/$$version/g" > src/include/switch_version.h ; \
+ echo $$version > .version ; \
+ fi ; \
fi ;
update:
Modified: freeswitch/trunk/configure.in
==============================================================================
--- freeswitch/trunk/configure.in (original)
+++ freeswitch/trunk/configure.in Sun Aug 19 01:01:08 2007
@@ -1,8 +1,16 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
+# Must change all of the below together
+# For a release, set revision for that tagged release as well and uncomment
+AC_INIT([freeswitch], [1.0.pre1], BUG-REPORT-ADDRESS)
+AC_SUBST(SWITCH_VERSION_MAJOR, [1])
+AC_SUBST(SWITCH_VERSION_MINOR, [0])
+AC_SUBST(SWITCH_VERSION_MICRO, [pre1])
+#AC_SUBST(SWITCH_VERSION_REVISION, [svn-revision-here])
+
+AC_CONFIG_FILES([src/include/switch_version.h.in:src/include/switch_version.h.template])
-AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_AUX_DIR(build/config)
AM_INIT_AUTOMAKE(libfreeswitch,0.1)
AC_CONFIG_SRCDIR([src/switch.c])
Added: freeswitch/trunk/src/include/switch_version.h.template
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/include/switch_version.h.template Sun Aug 19 01:01:08 2007
@@ -0,0 +1,50 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct(a)yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct(a)yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Anthony Minessale II <anthmct(a)yahoo.com>
+ * Michael Jerris <mike(a)jerris.com>
+ *
+ * switch_version.h -- Version Number Header
+ *
+ */
+
+#ifndef SWITCH_VERSION_H
+#define SWITCH_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SWITCH_VERSION_MAJOR "@SWITCH_VERSION_MAJOR@"
+#define SWITCH_VERSION_MINOR "@SWITCH_VERSION_MINOR@"
+#define SWITCH_VERSION_MICRO "@SWITCH_VERSION_MICRO@"
+#define SWITCH_VERSION_REVISION "@SWITCH_VERSION_REVISION@"
+#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO " (" SWITCH_VERSION_REVISION ")"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Modified: freeswitch/trunk/w32/Library/FreeSwitchCore.vcproj
==============================================================================
--- freeswitch/trunk/w32/Library/FreeSwitchCore.vcproj (original)
+++ freeswitch/trunk/w32/Library/FreeSwitchCore.vcproj Sun Aug 19 01:01:08 2007
@@ -576,7 +576,7 @@
Name="Generated Header Files"
>
<File
- RelativePath="..\..\src\include\switch_am_config.h.in"
+ RelativePath="..\..\src\include\switch_am_config.h.template"
>
<FileConfiguration
Name="Debug|Win32"
@@ -596,7 +596,7 @@
</FileConfiguration>
</File>
<File
- RelativePath="..\..\src\include\switch_version.h.in"
+ RelativePath="..\..\src\include\switch_version.h.template"
>
<FileConfiguration
Name="Debug|Win32"
@@ -604,7 +604,7 @@
<Tool
Name="VCCustomBuildTool"
Description="Generating switch_version.h"
- CommandLine="cscript /nologo "$(ProjectDir)..\..\libs\win32\util.vbs" Version "$(ProjectDir)" "$(ProjectDir)..\..\" "$(ProjectDir)..\..\src\include\switch_version.h.in" "$(ProjectDir)..\..\src\include\switch_version.h"
"
+ CommandLine="cscript /nologo "$(ProjectDir)..\..\libs\win32\util.vbs" Version "$(ProjectDir)" "$(ProjectDir)..\..\" "$(ProjectDir)..\..\src\include\switch_version.h.template" "$(ProjectDir)..\..\src\include\switch_version.h"
"
AdditionalDependencies="..\..\src\include\switch.h;..\..\src\include\switch_apr.h;..\..\src\include\switch_buffer.h;..\..\src\include\switch_caller.h;..\..\src\include\switch_channel.h;..\..\src\include\switch_console.h;..\..\src\include\switch_core.h;..\..\src\include\switch_event.h;..\..\src\include\switch_frame.h;..\..\src\include\switch_ivr.h;..\..\src\include\switch_loadable_module.h;..\..\src\include\switch_log.h;..\..\src\include\switch_module_interfaces.h;..\..\src\include\switch_platform.h;..\..\src\include\switch_resample.h;..\..\src\include\switch_rtp.h;..\..\src\include\switch_sqlite.h;..\..\src\include\switch_stun.h;..\..\src\include\switch_types.h;..\..\src\include\switch_utils.h;..\..\src\include\switch_xml.h;..\..\src\switch_buffer.c;..\..\src\switch_caller.c;..\..\src\switch_channel.c;..\..\src\switch_config.c;..\..\src\switch_console.c;..\..\src\switch_core.c;..\..\src\switch_event.c;..\..\src\switch_ivr.c;..\..\src\switch_loadable_module.c;..\..\src\switch_log.c;..\..\src\switch_resample.c;..\..\src\switch_rtp.c;..\..\src\switch_stun.c;..\..\src\switch_utils.c;..\..\src\switch_xml.c"
Outputs="..\..\src\include\switch_version.h;lastversion"
/>
@@ -615,7 +615,7 @@
<Tool
Name="VCCustomBuildTool"
Description="Generating switch_version.h"
- CommandLine="cscript /nologo "$(ProjectDir)..\..\libs\win32\util.vbs" Version "$(ProjectDir)" "$(ProjectDir)..\..\" "$(ProjectDir)..\..\src\include\switch_version.h.in" "$(ProjectDir)..\..\src\include\switch_version.h"
"
+ CommandLine="cscript /nologo "$(ProjectDir)..\..\libs\win32\util.vbs" Version "$(ProjectDir)" "$(ProjectDir)..\..\" "$(ProjectDir)..\..\src\include\switch_version.h.template" "$(ProjectDir)..\..\src\include\switch_version.h"
"
AdditionalDependencies="..\..\src\include\switch.h;..\..\src\include\switch_apr.h;..\..\src\include\switch_buffer.h;..\..\src\include\switch_caller.h;..\..\src\include\switch_channel.h;..\..\src\include\switch_console.h;..\..\src\include\switch_core.h;..\..\src\include\switch_event.h;..\..\src\include\switch_frame.h;..\..\src\include\switch_ivr.h;..\..\src\include\switch_loadable_module.h;..\..\src\include\switch_log.h;..\..\src\include\switch_module_interfaces.h;..\..\src\include\switch_platform.h;..\..\src\include\switch_resample.h;..\..\src\include\switch_rtp.h;..\..\src\include\switch_sqlite.h;..\..\src\include\switch_stun.h;..\..\src\include\switch_types.h;..\..\src\include\switch_utils.h;..\..\src\include\switch_xml.h;..\..\src\switch_buffer.c;..\..\src\switch_caller.c;..\..\src\switch_channel.c;..\..\src\switch_config.c;..\..\src\switch_console.c;..\..\src\switch_core.c;..\..\src\switch_event.c;..\..\src\switch_ivr.c;..\..\src\switch_loadable_module.c;..\..\src\switch_log.c;..\..\src\switch_resample.c;..\..\src\switch_rtp.c;..\..\src\switch_stun.c;..\..\src\switch_utils.c;..\..\src\switch_xml.c"
Outputs="..\..\src\include\switch_version.h;lastversion"
/>
1
0
Author: mikej
Date: Sat Aug 18 21:00:34 2007
New Revision: 5609
Modified:
freeswitch/trunk/src/include/switch_version.h.in
Log:
Make version string have major, minor, and micro version.
Modified: freeswitch/trunk/src/include/switch_version.h.in
==============================================================================
--- freeswitch/trunk/src/include/switch_version.h.in (original)
+++ freeswitch/trunk/src/include/switch_version.h.in Sat Aug 18 21:00:34 2007
@@ -39,8 +39,9 @@
#define SWITCH_VERSION_MAJOR "1"
#define SWITCH_VERSION_MINOR "0"
+#define SWITCH_VERSION_MICRO "pre1"
#define SWITCH_VERSION_REVISION "@SVN_VERSION@"
-#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_REVISION
+#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO " (" SWITCH_VERSION_REVISION ")"
#ifdef __cplusplus
}
1
0
19 Aug '07
Author: mikej
Date: Sat Aug 18 20:18:34 2007
New Revision: 5608
Modified:
freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
Log:
line endings.
Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Sat Aug 18 20:18:34 2007
@@ -1281,51 +1281,51 @@
return SWITCH_STATUS_SUCCESS;
}
-#define SETVAR_SYNTAX "<uuid> <var> <value>"
-SWITCH_STANDARD_API(uuid_setvar_function)
-{
- switch_core_session_t *psession = NULL;
- char *mycmd = NULL, *argv[3] = { 0 };
- int argc = 0;
-
- if (session) {
- return SWITCH_STATUS_FALSE;
- }
-
- if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
- argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- if (argc == 3) {
- char *uuid = argv[0];
- char *var_name = argv[1];
- char *var_value = argv[2];
-
- if ((psession = switch_core_session_locate(uuid))) {
- switch_channel_t *channel;
- channel = switch_core_session_get_channel(psession);
-
- assert(channel != NULL);
-
- if (switch_strlen_zero(var_name)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var_name, var_value ? var_value : "UNDEF");
- switch_channel_set_variable(channel, var_name, var_value);
- }
-
- switch_core_session_rwunlock(psession);
-
- } else {
- stream->write_function(stream, "No Such Channel!\n");
- }
- goto done;
- }
- }
-
- stream->write_function(stream, "USAGE: %s\n", SETVAR_SYNTAX);
-
-done:
- switch_safe_free(mycmd);
- return SWITCH_STATUS_SUCCESS;
+#define SETVAR_SYNTAX "<uuid> <var> <value>"
+SWITCH_STANDARD_API(uuid_setvar_function)
+{
+ switch_core_session_t *psession = NULL;
+ char *mycmd = NULL, *argv[3] = { 0 };
+ int argc = 0;
+
+ if (session) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+ argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ if (argc == 3) {
+ char *uuid = argv[0];
+ char *var_name = argv[1];
+ char *var_value = argv[2];
+
+ if ((psession = switch_core_session_locate(uuid))) {
+ switch_channel_t *channel;
+ channel = switch_core_session_get_channel(psession);
+
+ assert(channel != NULL);
+
+ if (switch_strlen_zero(var_name)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var_name, var_value ? var_value : "UNDEF");
+ switch_channel_set_variable(channel, var_name, var_value);
+ }
+
+ switch_core_session_rwunlock(psession);
+
+ } else {
+ stream->write_function(stream, "No Such Channel!\n");
+ }
+ goto done;
+ }
+ }
+
+ stream->write_function(stream, "USAGE: %s\n", SETVAR_SYNTAX);
+
+done:
+ switch_safe_free(mycmd);
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
1
0
18 Aug '07
Author: achaloyan
Date: Sat Aug 18 16:18:29 2007
New Revision: 5607
Modified:
freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
Log:
no blocking wait, requests and events are called async, the only sync call is channel creation yet.
Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c (original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c Sat Aug 18 16:18:29 2007
@@ -62,8 +62,8 @@
#include "mrcp_recognizer.h"
#include "mrcp_synthesizer.h"
#include "mrcp_generic_header.h"
+#include "mrcp_resource_set.h"
-#include <apr_hash.h>
#include <switch.h>
#define OPENMRCP_WAIT_TIMEOUT 5000
@@ -75,24 +75,6 @@
SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load,
mod_openmrcp_shutdown, NULL);
-typedef enum {
- OPENMRCP_EVENT_NONE,
- OPENMRCP_EVENT_SESSION_INITIATE,
- OPENMRCP_EVENT_SESSION_TERMINATE,
- OPENMRCP_EVENT_CHANNEL_CREATE,
- OPENMRCP_EVENT_CHANNEL_DESTROY,
- OPENMRCP_EVENT_CHANNEL_MODIFY
-} openmrcp_event_t;
-
-static const char *openmrcp_event_names[] = {
- "NONE",
- "SESSION_INITIATE",
- "SESSION_TERMINATE",
- "CHANNEL_CREATE",
- "CHANNEL_DESTROY",
- "CHANNEL_MODIFY",
-};
-
typedef struct {
char *name;
openmrcp_client_options_t *mrcp_options;
@@ -103,21 +85,21 @@
typedef struct {
openmrcp_profile_t *profile;
mrcp_session_t *client_session;
- mrcp_client_channel_t *tts_channel;
- mrcp_client_channel_t *asr_channel;
+ mrcp_client_channel_t *control_channel;
mrcp_audio_channel_t *audio_channel;
- switch_queue_t *event_queue;
mrcp_message_t *mrcp_message_last_rcvd;
apr_pool_t *pool;
switch_speech_flag_t flags;
switch_mutex_t *flag_mutex;
+ switch_thread_cond_t *wait_object;
} openmrcp_session_t;
typedef enum {
- FLAG_HAS_TEXT = (1 << 0),
- FLAG_BARGE = (1 << 1),
- FLAG_READY = (1 << 2),
- FLAG_SPEAK_COMPLETE = (1 << 3)
+ FLAG_HAS_TEXT = (1 << 0),
+ FLAG_BARGE = (1 << 1),
+ FLAG_READY = (1 << 2),
+ FLAG_SPEAK_COMPLETE = (1 << 3),
+ FLAG_FEED_STARTED = (1 << 4)
} mrcp_flag_t;
typedef struct {
@@ -150,16 +132,15 @@
openmrcp_session->pool = session_pool;
openmrcp_session->profile = profile;
openmrcp_session->client_session = NULL;
- openmrcp_session->asr_channel = NULL;
- openmrcp_session->tts_channel = NULL;
+ openmrcp_session->control_channel = NULL;
openmrcp_session->audio_channel = NULL;
openmrcp_session->mrcp_message_last_rcvd = NULL;
- openmrcp_session->event_queue = NULL;
- /* create an event queue */
- if (switch_queue_create(&openmrcp_session->event_queue, 1000, openmrcp_session->pool)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "event queue creation failed\n");
- }
+ switch_mutex_init(&openmrcp_session->flag_mutex, SWITCH_MUTEX_NESTED, openmrcp_session->pool);
+
+ if (switch_thread_cond_create(&openmrcp_session->wait_object, openmrcp_session->pool)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "wait object creation failed\n");
+ }
openmrcp_session->client_session = mrcp_client_context_session_create(openmrcp_session->profile->mrcp_context,openmrcp_session);
if (!openmrcp_session->client_session) {
@@ -174,104 +155,15 @@
static void openmrcp_session_destroy(openmrcp_session_t *openmrcp_session)
{
if(openmrcp_session && openmrcp_session->pool) {
+ mrcp_client_context_session_destroy(openmrcp_session->profile->mrcp_context,openmrcp_session->client_session);
apr_pool_destroy(openmrcp_session->pool);
}
}
-
-static mrcp_status_t wait_for_event(switch_queue_t *event_queue, openmrcp_event_t openmrcp_event, size_t timeout)
-{
-
- openmrcp_event_t *popped_event = NULL;
- size_t sleep_ms = 100;
-
- if(event_queue) {
- if (switch_queue_trypop(event_queue, (void *) &popped_event)) {
- // most likely this failed because queue is empty. sleep for timeout seconds and try again?
- if (timeout > 0) {
- if (timeout < sleep_ms) {
- switch_sleep(timeout * 1000); // ms->us
- timeout = 0;
- }
- else {
- switch_sleep(sleep_ms * 1000); // ms->us
- timeout -= sleep_ms;
- }
-
- // call recursively
- // TODO: This is going to end up in a lot of recursion and
- // maybe blow the stack .. rethink this approach
- return wait_for_event(event_queue, openmrcp_event, timeout);
-
- }
- else {
- // nothing in queue, no timeout left, return failure
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "nothing in queue, no timeout left, return failure\n");
- return MRCP_STATUS_FAILURE;
- }
-
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "popped event\n");
- // check if popped event matches the event we are looking for
- if (*popped_event == openmrcp_event) {
- // just what we were waiting for!
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "just what we were waiting for! rturn success\n");
- return MRCP_STATUS_SUCCESS;
- }
- else {
- // nothing popped, but maybe there's other things in queue, or something will arrive
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "popped unexpected\n");
- if (!popped_event) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "popped NULL!!\n");
- }
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "popped: %d\n", *popped_event);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "popped name: %s\n", openmrcp_event_names[*popped_event]);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "popped [%s] but was expecting [%s], but maybe there's other things in queue, or something will arrive\n", openmrcp_event_names[*popped_event], openmrcp_event_names[openmrcp_event]);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "calling recursively\n");
- return wait_for_event(event_queue, openmrcp_event, timeout);
- }
-
- }
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "event queue is null\n");
- return MRCP_STATUS_FAILURE;
- }
-
-}
-
-
-static mrcp_status_t openmrcp_session_signal_event(openmrcp_session_t *openmrcp_session, openmrcp_event_t openmrcp_event)
-{
- mrcp_status_t status = MRCP_STATUS_SUCCESS;
-
- // allocate memory for event
- openmrcp_event_t *event2queue = (openmrcp_event_t *) switch_core_alloc(openmrcp_session->pool, sizeof(openmrcp_event_t));
- *event2queue = openmrcp_event;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got event: %s\n", openmrcp_event_names[openmrcp_event]);
-
- // add it to queue
- if (switch_queue_trypush(openmrcp_session->event_queue, (void *) event2queue)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "could not push event to queue\n");
- status = SWITCH_STATUS_GENERR;
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "pushed event to queue: %s\n", openmrcp_event_names[*event2queue]);
- }
-
- return status;
-}
-
-
static mrcp_status_t openmrcp_on_session_initiate(mrcp_client_context_t *context, mrcp_session_t *session)
{
- openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_session_initiate called\n");
- if(!openmrcp_session) {
- return MRCP_STATUS_FAILURE;
- }
- return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_SESSION_INITIATE);
+ return MRCP_STATUS_SUCCESS;
}
static mrcp_status_t openmrcp_on_session_terminate(mrcp_client_context_t *context, mrcp_session_t *session)
@@ -281,7 +173,8 @@
if(!openmrcp_session) {
return MRCP_STATUS_FAILURE;
}
- return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_SESSION_TERMINATE);
+ openmrcp_session_destroy(openmrcp_session);
+ return MRCP_STATUS_SUCCESS;
}
static mrcp_status_t openmrcp_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
@@ -291,18 +184,18 @@
if(!openmrcp_session) {
return MRCP_STATUS_FAILURE;
}
+ switch_mutex_lock(openmrcp_session->flag_mutex);
+ openmrcp_session->control_channel = control_channel;
openmrcp_session->audio_channel = audio_channel;
- return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_CHANNEL_CREATE);
+ switch_thread_cond_signal(openmrcp_session->wait_object);
+ switch_mutex_unlock(openmrcp_session->flag_mutex);
+ return MRCP_STATUS_SUCCESS;
}
static mrcp_status_t openmrcp_on_channel_remove(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel)
{
- openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_channel_remove called\n");
- if(!openmrcp_session) {
- return MRCP_STATUS_FAILURE;
- }
- return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_CHANNEL_DESTROY);
+ return MRCP_STATUS_SUCCESS;
}
/** this is called by the mrcp core whenever an mrcp message is received from
@@ -311,40 +204,48 @@
{
openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_channel_modify called\n");
- if(!openmrcp_session) {
+ if (!openmrcp_session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "!openmrcp_session\n");
return MRCP_STATUS_FAILURE;
}
+ if (!mrcp_message) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "!mrcp_message\n");
+ return MRCP_STATUS_FAILURE;
+ }
+
+ if (mrcp_message->start_line.message_type != MRCP_MESSAGE_TYPE_EVENT) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ignoring mrcp response\n");
+ return MRCP_STATUS_SUCCESS;
+ }
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mrcp msg body: %s\n", mrcp_message->body);
- if(openmrcp_session->asr_channel) {
- if (!strcmp(mrcp_message->start_line.method_name,"RECOGNITION-COMPLETE")) {
+ if (mrcp_message->channel_id.resource_id == MRCP_RESOURCE_RECOGNIZER) {
+ if (mrcp_message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_HAS_TEXT\n");
switch_set_flag_locked(openmrcp_session, FLAG_HAS_TEXT);
}
- else if (!strcmp(mrcp_message->start_line.method_name,"START-OF-SPEECH")) {
+ else if (mrcp_message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_BARGE\n");
switch_set_flag_locked(openmrcp_session, FLAG_BARGE);
}
else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring method: %s\n", mrcp_message->start_line.method_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring event: %s\n", mrcp_message->start_line.method_name);
}
}
- else if(openmrcp_session->tts_channel) {
- if (mrcp_message->start_line.method_name) {
- if (!strcmp(mrcp_message->start_line.method_name,"SPEAK-COMPLETE")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setting FLAG_SPEAK_COMPLETE\n");
- switch_set_flag_locked(openmrcp_session, FLAG_SPEAK_COMPLETE);
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring method: %s\n", mrcp_message->start_line.method_name);
- }
+ else if(mrcp_message->channel_id.resource_id == MRCP_RESOURCE_SYNTHESIZER) {
+ if (mrcp_message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setting FLAG_SPEAK_COMPLETE\n");
+ switch_set_flag_locked(openmrcp_session, FLAG_SPEAK_COMPLETE);
+ }
+ else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring event: %s\n", mrcp_message->start_line.method_name);
}
}
- return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_CHANNEL_MODIFY);
+ return MRCP_STATUS_SUCCESS;
}
/** Read in the grammar and construct an MRCP Recognize message that has
@@ -359,7 +260,7 @@
char *buf1;
apr_size_t bytes2read = 0;
- mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context, asr_session->client_session, asr_session->asr_channel, RECOGNIZER_RECOGNIZE);
+ mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context, asr_session->client_session, asr_session->control_channel, RECOGNIZER_RECOGNIZE);
if(!mrcp_message) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not create mrcp msg\n");
@@ -402,6 +303,7 @@
static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags)
{
openmrcp_session_t *asr_session;
+ mrcp_client_channel_t *asr_channel;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_open called, codec: %s, rate: %d\n", codec, rate);
@@ -420,10 +322,28 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_session creation FAILED\n");
return SWITCH_STATUS_GENERR;
}
-
+
+ /* create recognizer channel, also starts outgoing rtp media */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Create Recognizer Channel\n");
+ asr_channel = mrcp_client_recognizer_channel_create(asr_session->profile->mrcp_context, asr_session->client_session, NULL);
+ if (!asr_channel) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create recognizer channel\n");
+ return SWITCH_STATUS_FALSE;
+ }
+
+ mrcp_client_context_channel_add(asr_session->profile->mrcp_context, asr_session->client_session, asr_channel, NULL);
+
+ switch_mutex_lock(asr_session->flag_mutex);
+ if(switch_thread_cond_timedwait(asr_session->wait_object,asr_session->flag_mutex,5000*1000) != APR_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No response from client stack\n");
+ }
+ switch_mutex_unlock(asr_session->flag_mutex);
+ if(!asr_session->control_channel) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No recognizer channel available\n");
+ return SWITCH_STATUS_FALSE;
+ }
+
asr_session->flags = *flags;
- switch_mutex_init(&asr_session->flag_mutex, SWITCH_MUTEX_NESTED, asr_session->pool);
-
ah->private_info = asr_session;
return SWITCH_STATUS_SUCCESS;
}
@@ -440,39 +360,11 @@
openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
mrcp_client_context_t *context = asr_session->profile->mrcp_context;
- /* create recognizer channel, also starts outgoing rtp media */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loading grammar\n");
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Create Recognizer Channel\n");
- asr_session->asr_channel = mrcp_client_recognizer_channel_create(context, asr_session->client_session, NULL);
- if (!asr_session->asr_channel) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create recognizer channel\n");
- return SWITCH_STATUS_FALSE;
- }
-
- mrcp_client_context_channel_add(context, asr_session->client_session, asr_session->asr_channel, NULL);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Start Recognizer\n");
+ openmrcp_recog_start(context, asr_session, path);
- /* wait for recognizer channel creation */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "WAITING FOR CHAN CREATE\n");
- if(wait_for_event(asr_session->event_queue, OPENMRCP_EVENT_CHANNEL_CREATE, OPENMRCP_WAIT_TIMEOUT) == MRCP_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got channel creation event\n");
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "WAITING FOR NONE\n");
- if (wait_for_event(asr_session->event_queue,OPENMRCP_EVENT_NONE,200) == MRCP_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "GOT NONE EVENT\n");
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NEVER GOT NONE EVENT\n");
- }
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Start Recognizer\n");
- openmrcp_recog_start(context, asr_session, path);
-
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "never got channel creation event\n");
- }
-
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Finished loading grammar\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -498,7 +390,7 @@
media_frame.codec_frame.buffer = (char*)media_frame.codec_frame.buffer + media_frame.codec_frame.size;
}
if(len > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not framed alligned data len [%d]\n",len);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "None frame alligned data len [%d]\n",len);
}
return SWITCH_STATUS_SUCCESS;
}
@@ -543,33 +435,10 @@
// TODO!! should we do a switch_pool_clear(switch_memory_pool_t *p) on the pool held
// by asr_session?
- // destroy channel
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Going to DESTROY CHANNEL\n");
- mrcp_client_context_channel_destroy(context, asr_session->client_session, asr_session->asr_channel);
- if (wait_for_event(asr_session->event_queue,OPENMRCP_EVENT_CHANNEL_DESTROY,10000) == MRCP_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPENMRCP_EVENT_CHANNEL_DESTROY received\n");
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "timed out waiting for OPENMRCP_EVENT_CHANNEL_DESTROY\n");
- }
-
// terminate client session
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Going to TERMINATE SESSION\n");
mrcp_client_context_session_terminate(context, asr_session->client_session);
- if (wait_for_event(asr_session->event_queue,OPENMRCP_EVENT_SESSION_TERMINATE,10000) == MRCP_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPENMRCP_EVENT_SESSION_TERMINATE recevied\n");
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "timed out waiting for OPENMRCP_EVENT_SESSION_TERMINATE\n");
- }
- // destroy client session (NOTE: this sends a BYE to the other side)
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Going to DESTROY SESSION\n");
- mrcp_client_context_session_destroy(context, asr_session->client_session);
-
- // destroys the asr_session struct
- openmrcp_session_destroy(asr_session);
-
switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED);
return SWITCH_STATUS_SUCCESS;
@@ -661,7 +530,7 @@
strcat(text2speak, text);
strcat(text2speak, xml_tail);
- mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->tts_channel,SYNTHESIZER_SPEAK);
+ mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->control_channel,SYNTHESIZER_SPEAK);
if(!mrcp_message) {
return MRCP_STATUS_FAILURE;
}
@@ -680,7 +549,7 @@
static mrcp_status_t synth_stop(mrcp_client_context_t *context, openmrcp_session_t *tts_session)
{
- mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->tts_channel,SYNTHESIZER_STOP);
+ mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->control_channel,SYNTHESIZER_STOP);
if(!mrcp_message) {
return MRCP_STATUS_FAILURE;
}
@@ -692,6 +561,7 @@
static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, char *voice_name, int rate, switch_speech_flag_t *flags)
{
openmrcp_session_t *tts_session;
+ mrcp_client_channel_t *tts_channel;
/* create session */
tts_session = openmrcp_session_create(openmrcp_module.tts_profile);
@@ -699,9 +569,27 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "tts_session creation FAILED\n");
return SWITCH_STATUS_GENERR;
}
+
+ /* create synthesizer channel */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Create Synthesizer Channel\n");
+ tts_channel = mrcp_client_synthesizer_channel_create(tts_session->profile->mrcp_context, tts_session->client_session, NULL);
+ if (!tts_channel) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create synthesizer channel\n");
+ return SWITCH_STATUS_FALSE;
+ }
+ mrcp_client_context_channel_add(tts_session->profile->mrcp_context, tts_session->client_session, tts_channel, NULL);
+
+ switch_mutex_lock(tts_session->flag_mutex);
+ if(switch_thread_cond_timedwait(tts_session->wait_object,tts_session->flag_mutex,5000*1000) != APR_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No response from client stack\n");
+ }
+ switch_mutex_unlock(tts_session->flag_mutex);
+ if(!tts_session->control_channel) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No synthesizer channel available\n");
+ return SWITCH_STATUS_FALSE;
+ }
+
tts_session->flags = *flags;
- switch_mutex_init(&tts_session->flag_mutex, SWITCH_MUTEX_NESTED, tts_session->pool);
-
sh->private_info = tts_session;
return SWITCH_STATUS_SUCCESS;
}
@@ -711,21 +599,9 @@
openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
mrcp_client_context_t *context = tts_session->profile->mrcp_context;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "synth_stop\n");
- synth_stop(context,tts_session); // TODO
- wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_CHANNEL_MODIFY,5000);
-
/* terminate tts session */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Terminate tts_session\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "terminate tts_session\n");
mrcp_client_context_session_terminate(context,tts_session->client_session);
- /* wait for tts session termination */
- wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_SESSION_TERMINATE,10000);
-
- /* destroy demo session */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "destroy tts_session\n");
- mrcp_client_context_session_destroy(context,tts_session->client_session);
- openmrcp_session_destroy(tts_session);
-
return SWITCH_STATUS_SUCCESS;
}
@@ -734,30 +610,14 @@
openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
mrcp_client_context_t *context = tts_session->profile->mrcp_context;
- /* create synthesizer channel */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Create Synthesizer Channel\n");
- tts_session->tts_channel = mrcp_client_synthesizer_channel_create(context,tts_session->client_session,NULL);
- if (!tts_session->tts_channel) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create synthesizer channel\n");
+ if(!tts_session->control_channel) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no synthesizer channel too feed tts\n");
return SWITCH_STATUS_FALSE;
}
-
- mrcp_client_context_channel_add(context, tts_session->client_session, tts_session->tts_channel, NULL);
- /* wait for synthesizer channel creation */
- if(wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_CHANNEL_CREATE,5000) == MRCP_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got channel create event\n");
- wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_NONE,1000); // XXX: what are we waiting for??
- /* speak */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Going to speak\n");
- synth_speak(context, tts_session, text);
-
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Never got channel create event.\n");
- return SWITCH_STATUS_FALSE;
- }
-
+ synth_speak(context, tts_session, text);
+
+ switch_clear_flag(tts_session,FLAG_FEED_STARTED);
return SWITCH_STATUS_SUCCESS;
}
@@ -785,6 +645,13 @@
return SWITCH_STATUS_BREAK;
}
+ if (!switch_test_flag(tts_session, FLAG_FEED_STARTED)) {
+ switch_set_flag(tts_session, FLAG_FEED_STARTED);
+ if(audio_source->method_set->open) {
+ audio_source->method_set->open(audio_source);
+ }
+ }
+
/* sampling rate and frame size should be retrieved from audio source */
*rate = 8000;
media_frame.codec_frame.size = 160;
@@ -803,7 +670,11 @@
static void openmrcp_flush_tts(switch_speech_handle_t *sh)
{
+ openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
+ mrcp_client_context_t *context = tts_session->profile->mrcp_context;
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "flush_tts called\n");
+ synth_stop(context,tts_session); // TODO
}
static void openmrcp_text_param_tts(switch_speech_handle_t *sh, char *param, char *val)
1
0
17 Aug '07
Author: greenlizard
Date: Fri Aug 17 17:52:42 2007
New Revision: 5606
Modified:
freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
Log:
throw errors when configuration is invalid. check for null point in asr_feed to prevent segfault when testing against certain asr servers.
Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c (original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c Fri Aug 17 17:52:42 2007
@@ -24,6 +24,7 @@
* Contributor(s):
*
* Traun Leyden <tleyden(a)branchcut.com>
+ * Arsen Chaloyan <achaloyan(a)yahoo.com>
*
* Module which acts as an MRCP client to an MRCP speech recognition
* server. In other words it bridges freeswitch to an external speech
@@ -404,19 +405,6 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_open called, codec: %s, rate: %d\n", codec, rate);
- /*!
- NOTE: According to the current FS media bugs design, the media bug can only feed audio
- data in SLIN (L16) format. So we dont need to worry about other codecs.
-
- NOTE: forcing MRCP to use 20 as the CODEC_FRAME_TIME_BASE effectively ensures
- that it matches with 16-bit audio at 8kz with 320 byte frames. in testing, leaving
- CODEC_FRAME_TIME_BASE at 10 and using pop (instead of trypop) in
- openmrcp_recognizer_read_frame() actually produces clean audio, however it causes
- other problems as the full channel/session cleanup never completes in openmrcp, most
- likely due to a thread being blocked on a pop call from audio queue. but with trypop
- (to avoid the cleanup problem), it only produces clean audio when CODEC_FRAME_TIME_BASE
- is set to 20.
- */
if (strcmp(codec,"L16")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only L16 codec supported\n");
return SWITCH_STATUS_GENERR;
@@ -501,6 +489,9 @@
media_frame.codec_frame.size = 160;
media_frame.codec_frame.buffer = data;
while(len >= media_frame.codec_frame.size) {
+ if (!audio_sink) {
+ return SWITCH_STATUS_GENERR;
+ }
audio_sink->method_set->write_frame(audio_sink,&media_frame);
len -= (unsigned int)media_frame.codec_frame.size;
@@ -653,7 +644,6 @@
mrcp_generic_header_t *generic_header;
mrcp_message_t *mrcp_message;
- //buffer = (switch_byte_t *) switch_core_alloc(asr_session->pool, sizeof(switch_byte_t)*len);
char *text2speak;
const char xml_head[] =
"<?xml version=\"1.0\"?>\r\n"
@@ -899,6 +889,9 @@
}
}
}
+ else {
+ goto error;
+ }
if ((profiles = switch_xml_child(cfg, "profiles"))) {
for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
const char *profile_name = switch_xml_attr_soft(xprofile, "name");
@@ -963,10 +956,18 @@
}
}
}
+ else {
+ goto error;
+ }
switch_xml_free(xml);
-
return SWITCH_STATUS_SUCCESS;
+
+ error:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load module configuration\n");
+ switch_xml_free(xml);
+ return SWITCH_STATUS_TERM;
+
}
static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile)
@@ -1015,7 +1016,9 @@
switch_core_hash_init(&openmrcp_module.profile_hash,openmrcp_module.pool);
/* read config */
- do_config();
+ if (do_config() != SWITCH_STATUS_SUCCESS) {
+ return SWITCH_STATUS_FALSE;
+ }
/* run default asr/tts profiles */
if(openmrcp_module.asr_profile) {
@@ -1036,7 +1039,9 @@
mrcp_global_init();
/* initialize openmrcp */
- openmrcp_init();
+ if (openmrcp_init() != SWITCH_STATUS_SUCCESS) {
+ return SWITCH_STATUS_FALSE;
+ }
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
1
0
17 Aug '07
Author: achaloyan
Date: Fri Aug 17 17:00:56 2007
New Revision: 5605
Modified:
freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
Log:
added support for multiple mrcp profiles; using unified mrcp session for asr, tts channels
Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c (original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c Fri Aug 17 17:00:56 2007
@@ -62,6 +62,7 @@
#include "mrcp_synthesizer.h"
#include "mrcp_generic_header.h"
+#include <apr_hash.h>
#include <switch.h>
#define OPENMRCP_WAIT_TIMEOUT 5000
@@ -73,22 +74,6 @@
SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load,
mod_openmrcp_shutdown, NULL);
-static struct {
- char *asr_client_ip;
- char *asr_server_ip;
- uint32_t asr_proto_version;
- apr_port_t asr_client_port;
- apr_port_t asr_server_port;
- char *tts_client_ip;
- char *tts_server_ip;
- uint32_t tts_proto_version;
- apr_port_t tts_client_port;
- apr_port_t tts_server_port;
- apr_port_t rtp_port_min;
- apr_port_t rtp_port_max;
-} globals;
-
-
typedef enum {
OPENMRCP_EVENT_NONE,
OPENMRCP_EVENT_SESSION_INITIATE,
@@ -107,28 +92,25 @@
"CHANNEL_MODIFY",
};
-typedef struct asr_session_t asr_session_t;
-struct asr_session_t {
- mrcp_session_t *client_session;
- mrcp_client_channel_t *channel;
- mrcp_audio_channel_t *audio_channel;
- switch_queue_t *event_queue;
- mrcp_message_t *mrcp_message_last_rcvd;
- apr_pool_t *pool;
- uint32_t flags;
- switch_mutex_t *flag_mutex;
-};
+typedef struct {
+ char *name;
+ openmrcp_client_options_t *mrcp_options;
+ mrcp_client_t *mrcp_client;
+ mrcp_client_context_t *mrcp_context;
+} openmrcp_profile_t;
-typedef struct tts_session_t tts_session_t;
-struct tts_session_t {
+typedef struct {
+ openmrcp_profile_t *profile;
mrcp_session_t *client_session;
- mrcp_client_channel_t *channel;
+ mrcp_client_channel_t *tts_channel;
+ mrcp_client_channel_t *asr_channel;
mrcp_audio_channel_t *audio_channel;
switch_queue_t *event_queue;
+ mrcp_message_t *mrcp_message_last_rcvd;
apr_pool_t *pool;
switch_speech_flag_t flags;
switch_mutex_t *flag_mutex;
-};
+} openmrcp_session_t;
typedef enum {
FLAG_HAS_TEXT = (1 << 0),
@@ -138,92 +120,61 @@
} mrcp_flag_t;
typedef struct {
- mrcp_client_t *asr_client;
- mrcp_client_context_t *asr_client_context;
- mrcp_client_t *tts_client;
- mrcp_client_context_t *tts_client_context;
+ switch_memory_pool_t *pool;
+ switch_hash_t *profile_hash;
+
+ openmrcp_profile_t *asr_profile;
+ openmrcp_profile_t *tts_profile;
} openmrcp_module_t;
static openmrcp_module_t openmrcp_module;
-static asr_session_t* asr_session_create()
+
+static openmrcp_session_t* openmrcp_session_create(openmrcp_profile_t *profile)
{
- asr_session_t *asr_session;
+ openmrcp_session_t *openmrcp_session;
apr_pool_t *session_pool;
- if(apr_pool_create(&session_pool,NULL) != APR_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to create session_pool\n");
+ if(!profile) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no profile specified\n");
return NULL;
}
- asr_session = apr_palloc(session_pool,sizeof(asr_session_t));
- asr_session->pool = session_pool;
- asr_session->client_session = NULL;
- asr_session->channel = NULL;
- asr_session->audio_channel = NULL;
- asr_session->event_queue = NULL;
-
-
- /* create an event queue */
- if (switch_queue_create(&asr_session->event_queue, 1000, asr_session->pool)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "event queue creation failed\n");
- }
-
- return asr_session;
-}
-
-
-static tts_session_t* tts_session_create()
-{
- tts_session_t *tts_session;
- apr_pool_t *session_pool;
-
if(apr_pool_create(&session_pool,NULL) != APR_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to create session_pool\n");
return NULL;
}
- tts_session = apr_palloc(session_pool,sizeof(tts_session_t));
- tts_session->pool = session_pool;
- tts_session->client_session = NULL;
- tts_session->channel = NULL;
- tts_session->audio_channel = NULL;
- tts_session->event_queue = NULL;
+ openmrcp_session = apr_palloc(session_pool,sizeof(openmrcp_session_t));
+ openmrcp_session->pool = session_pool;
+ openmrcp_session->profile = profile;
+ openmrcp_session->client_session = NULL;
+ openmrcp_session->asr_channel = NULL;
+ openmrcp_session->tts_channel = NULL;
+ openmrcp_session->audio_channel = NULL;
+ openmrcp_session->mrcp_message_last_rcvd = NULL;
+ openmrcp_session->event_queue = NULL;
/* create an event queue */
- if (switch_queue_create(&tts_session->event_queue, 1000, tts_session->pool)) {
+ if (switch_queue_create(&openmrcp_session->event_queue, 1000, openmrcp_session->pool)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "event queue creation failed\n");
}
- return tts_session;
-}
-
-
-static mrcp_status_t asr_session_destroy(asr_session_t *asr_session)
-{
- if(!asr_session) {
- return MRCP_STATUS_FAILURE;
+ openmrcp_session->client_session = mrcp_client_context_session_create(openmrcp_session->profile->mrcp_context,openmrcp_session);
+ if (!openmrcp_session->client_session) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "session creation FAILED\n");
+ apr_pool_destroy(session_pool);
+ return NULL;
}
- if(asr_session->pool) {
- apr_pool_destroy(asr_session->pool);
- asr_session->pool = NULL;
- }
- return MRCP_STATUS_SUCCESS;
+ return openmrcp_session;
}
-
-static mrcp_status_t tts_session_destroy(tts_session_t *tts_session)
+static void openmrcp_session_destroy(openmrcp_session_t *openmrcp_session)
{
- if(!tts_session) {
- return MRCP_STATUS_FAILURE;
- }
-
- if(tts_session->pool) {
- apr_pool_destroy(tts_session->pool);
- tts_session->pool = NULL;
+ if(openmrcp_session && openmrcp_session->pool) {
+ apr_pool_destroy(openmrcp_session->pool);
}
- return MRCP_STATUS_SUCCESS;
}
@@ -290,17 +241,17 @@
}
-static mrcp_status_t asr_session_signal_event(asr_session_t *asr_session, openmrcp_event_t openmrcp_event)
+static mrcp_status_t openmrcp_session_signal_event(openmrcp_session_t *openmrcp_session, openmrcp_event_t openmrcp_event)
{
mrcp_status_t status = MRCP_STATUS_SUCCESS;
// allocate memory for event
- openmrcp_event_t *event2queue = (openmrcp_event_t *) switch_core_alloc(asr_session->pool, sizeof(openmrcp_event_t));
+ openmrcp_event_t *event2queue = (openmrcp_event_t *) switch_core_alloc(openmrcp_session->pool, sizeof(openmrcp_event_t));
*event2queue = openmrcp_event;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got event: %s\n", openmrcp_event_names[openmrcp_event]);
// add it to queue
- if (switch_queue_trypush(asr_session->event_queue, (void *) event2queue)) {
+ if (switch_queue_trypush(openmrcp_session->event_queue, (void *) event2queue)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "could not push event to queue\n");
status = SWITCH_STATUS_GENERR;
}
@@ -312,200 +263,92 @@
}
-static mrcp_status_t asr_on_session_initiate(mrcp_client_context_t *context, mrcp_session_t *session)
+static mrcp_status_t openmrcp_on_session_initiate(mrcp_client_context_t *context, mrcp_session_t *session)
{
- asr_session_t *asr_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_on_session_initiate called\n");
- if(!asr_session) {
+ openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_session_initiate called\n");
+ if(!openmrcp_session) {
return MRCP_STATUS_FAILURE;
}
- return asr_session_signal_event(asr_session,OPENMRCP_EVENT_SESSION_INITIATE);
+ return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_SESSION_INITIATE);
}
-static mrcp_status_t asr_on_session_terminate(mrcp_client_context_t *context, mrcp_session_t *session)
+static mrcp_status_t openmrcp_on_session_terminate(mrcp_client_context_t *context, mrcp_session_t *session)
{
- asr_session_t *asr_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_on_session_terminate called\n");
- if(!asr_session) {
+ openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_session_terminate called\n");
+ if(!openmrcp_session) {
return MRCP_STATUS_FAILURE;
}
- return asr_session_signal_event(asr_session,OPENMRCP_EVENT_SESSION_TERMINATE);
+ return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_SESSION_TERMINATE);
}
-static mrcp_status_t asr_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
+static mrcp_status_t openmrcp_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
{
- asr_session_t *asr_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_on_channel_add called\n");
- if(!asr_session) {
+ openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_channel_add called\n");
+ if(!openmrcp_session) {
return MRCP_STATUS_FAILURE;
}
- asr_session->audio_channel = audio_channel;
- return asr_session_signal_event(asr_session,OPENMRCP_EVENT_CHANNEL_CREATE);
+ openmrcp_session->audio_channel = audio_channel;
+ return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_CHANNEL_CREATE);
}
-static mrcp_status_t asr_on_channel_remove(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *channel)
+static mrcp_status_t openmrcp_on_channel_remove(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel)
{
- asr_session_t *asr_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_on_channel_remove called\n");
- if(!asr_session) {
+ openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_channel_remove called\n");
+ if(!openmrcp_session) {
return MRCP_STATUS_FAILURE;
}
- return asr_session_signal_event(asr_session,OPENMRCP_EVENT_CHANNEL_DESTROY);
+ return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_CHANNEL_DESTROY);
}
/** this is called by the mrcp core whenever an mrcp message is received from
the other side. */
-static mrcp_status_t asr_on_channel_modify(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_message_t *mrcp_message)
+static mrcp_status_t openmrcp_on_channel_modify(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_message_t *mrcp_message)
{
- asr_session_t *asr_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_on_channel_modify called\n");
- if(!asr_session) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "!asr_session\n");
+ openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_channel_modify called\n");
+ if(!openmrcp_session) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "!openmrcp_session\n");
return MRCP_STATUS_FAILURE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mrcp msg body: %s\n", mrcp_message->body);
- if (!strcmp(mrcp_message->start_line.method_name,"RECOGNITION-COMPLETE")) {
- asr_session->mrcp_message_last_rcvd = mrcp_message;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_HAS_TEXT\n");
- switch_set_flag_locked(asr_session, FLAG_HAS_TEXT);
- }
- else if (!strcmp(mrcp_message->start_line.method_name,"START-OF-SPEECH")) {
- asr_session->mrcp_message_last_rcvd = mrcp_message;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_BARGE\n");
- switch_set_flag_locked(asr_session, FLAG_BARGE);
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring method: %s\n", mrcp_message->start_line.method_name);
- }
-
- return asr_session_signal_event(asr_session,OPENMRCP_EVENT_CHANNEL_MODIFY);
-}
-
-
-
-static mrcp_status_t tts_session_signal_event(tts_session_t *tts_session, openmrcp_event_t openmrcp_event)
-{
- mrcp_status_t status = MRCP_STATUS_SUCCESS;
-
- // allocate memory for event
- openmrcp_event_t *event2queue = (openmrcp_event_t *) switch_core_alloc(tts_session->pool, sizeof(openmrcp_event_t));
- *event2queue = openmrcp_event;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got event: %s\n", openmrcp_event_names[openmrcp_event]);
-
- // add it to queue
- if (switch_queue_trypush(tts_session->event_queue, (void *) event2queue)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "could not push event to queue\n");
- status = SWITCH_STATUS_GENERR;
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "pushed event to queue: %s\n", openmrcp_event_names[*event2queue]);
- }
-
- return status;
-}
-
-static mrcp_status_t tts_on_session_initiate(mrcp_client_context_t *context, mrcp_session_t *session)
-{
- tts_session_t *tts_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tts_on_session_initiate called\n");
- if(!tts_session) {
- return MRCP_STATUS_FAILURE;
- }
- return tts_session_signal_event(tts_session,OPENMRCP_EVENT_SESSION_INITIATE);
-}
-
-static mrcp_status_t tts_on_session_terminate(mrcp_client_context_t *context, mrcp_session_t *session)
-{
- tts_session_t *tts_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tts_on_session_terminate called\n");
- if(!tts_session) {
- return MRCP_STATUS_FAILURE;
- }
- return tts_session_signal_event(tts_session,OPENMRCP_EVENT_SESSION_TERMINATE);
-}
-
-static mrcp_status_t tts_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
-{
- tts_session_t *tts_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tts_on_channel_add called\n");
- if(!tts_session) {
- return MRCP_STATUS_FAILURE;
- }
- tts_session->audio_channel = audio_channel;
- return tts_session_signal_event(tts_session,OPENMRCP_EVENT_CHANNEL_CREATE);
-}
-
-static mrcp_status_t tts_on_channel_remove(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *channel)
-{
- tts_session_t *tts_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tts_on_channel_remove called\n");
- if(!tts_session) {
- return MRCP_STATUS_FAILURE;
- }
- return tts_session_signal_event(tts_session,OPENMRCP_EVENT_CHANNEL_DESTROY);
-}
-
-/** this is called by the mrcp core whenever an mrcp message is received from
- the other side. */
-static mrcp_status_t tts_on_channel_modify(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_message_t *mrcp_message)
-{
- tts_session_t *tts_session = mrcp_client_context_session_object_get(session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "tts_on_channel_modify called\n");
- if(!tts_session) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "!tts_session\n");
- return MRCP_STATUS_FAILURE;
- }
-
- if (mrcp_message->start_line.method_name) {
- if (!strcmp(mrcp_message->start_line.method_name,"SPEAK-COMPLETE")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setting FLAG_SPEAK_COMPLETE\n");
- switch_set_flag_locked(tts_session, FLAG_SPEAK_COMPLETE);
+ if(openmrcp_session->asr_channel) {
+ if (!strcmp(mrcp_message->start_line.method_name,"RECOGNITION-COMPLETE")) {
+ openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_HAS_TEXT\n");
+ switch_set_flag_locked(openmrcp_session, FLAG_HAS_TEXT);
+ }
+ else if (!strcmp(mrcp_message->start_line.method_name,"START-OF-SPEECH")) {
+ openmrcp_session->mrcp_message_last_rcvd = mrcp_message;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "setting FLAG_BARGE\n");
+ switch_set_flag_locked(openmrcp_session, FLAG_BARGE);
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring method: %s\n", mrcp_message->start_line.method_name);
}
}
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mrcp msg body: %s\n", mrcp_message->body);
+ else if(openmrcp_session->tts_channel) {
+ if (mrcp_message->start_line.method_name) {
+ if (!strcmp(mrcp_message->start_line.method_name,"SPEAK-COMPLETE")) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setting FLAG_SPEAK_COMPLETE\n");
+ switch_set_flag_locked(openmrcp_session, FLAG_SPEAK_COMPLETE);
+ }
+ else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ignoring method: %s\n", mrcp_message->start_line.method_name);
+ }
+ }
+ }
-
-
- return tts_session_signal_event(tts_session,OPENMRCP_EVENT_CHANNEL_MODIFY);
-}
-
-
-
-static apr_status_t set_default_asr_options(openmrcp_client_options_t *options)
-{
- mrcp_logger.priority = MRCP_PRIO_INFO;
- options->proto_version = globals.asr_proto_version;
- options->client_ip = globals.asr_client_ip;
- options->server_ip = globals.asr_server_ip;
- options->client_port = globals.asr_client_port;
- options->server_port = globals.asr_server_port;
- options->rtp_port_min = globals.rtp_port_min;
- options->rtp_port_max = globals.rtp_port_max;
- return APR_SUCCESS;
-}
-
-
-static apr_status_t set_default_tts_options(openmrcp_client_options_t *options)
-{
- mrcp_logger.priority = MRCP_PRIO_INFO;
- options->proto_version = globals.tts_proto_version;
- options->client_ip = globals.tts_client_ip;
- options->server_ip = globals.tts_server_ip;
- options->client_port = globals.tts_client_port;
- options->server_port = globals.tts_server_port;
- options->rtp_port_min = globals.rtp_port_min;
- options->rtp_port_max = globals.rtp_port_max;
- return APR_SUCCESS;
+ return openmrcp_session_signal_event(openmrcp_session,OPENMRCP_EVENT_CHANNEL_MODIFY);
}
/** Read in the grammar and construct an MRCP Recognize message that has
The grammar attached as the payload */
-static mrcp_status_t openmrcp_recog_start(mrcp_client_context_t *context, asr_session_t *asr_session, char *path)
+static mrcp_status_t openmrcp_recog_start(mrcp_client_context_t *context, openmrcp_session_t *asr_session, char *path)
{
mrcp_generic_header_t *generic_header;
apr_status_t rv;
@@ -515,7 +358,7 @@
char *buf1;
apr_size_t bytes2read = 0;
- mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context, asr_session->client_session, asr_session->channel, RECOGNIZER_RECOGNIZE);
+ mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context, asr_session->client_session, asr_session->asr_channel, RECOGNIZER_RECOGNIZE);
if(!mrcp_message) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not create mrcp msg\n");
@@ -557,8 +400,7 @@
*/
static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags)
{
- mrcp_client_context_t *asr_client_context = openmrcp_module.asr_client_context ;
- asr_session_t *asr_session;
+ openmrcp_session_t *asr_session;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_open called, codec: %s, rate: %d\n", codec, rate);
@@ -585,22 +427,16 @@
return SWITCH_STATUS_GENERR;
}
/* create session */
- asr_session = asr_session_create();
+ asr_session = openmrcp_session_create(openmrcp_module.asr_profile);
if (!asr_session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_session creation FAILED\n");
return SWITCH_STATUS_GENERR;
}
- asr_session->client_session = mrcp_client_context_session_create(asr_client_context,asr_session);
- if (!asr_session->client_session) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_session creation FAILED\n");
- return SWITCH_STATUS_GENERR;
- }
-
+
asr_session->flags = *flags;
switch_mutex_init(&asr_session->flag_mutex, SWITCH_MUTEX_NESTED, asr_session->pool);
-
+
ah->private_info = asr_session;
-
return SWITCH_STATUS_SUCCESS;
}
@@ -613,20 +449,20 @@
TODO: - how does DEFINE-GRAMMAR fit into the picture here? (if at all)
*/
- asr_session_t *asr_session = (asr_session_t *) ah->private_info;
- mrcp_client_context_t *asr_client_context = openmrcp_module.asr_client_context;
+ openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
+ mrcp_client_context_t *context = asr_session->profile->mrcp_context;
/* create recognizer channel, also starts outgoing rtp media */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loading grammar\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Create Recognizer Channel\n");
- asr_session->channel = mrcp_client_recognizer_channel_create(asr_client_context, asr_session->client_session, NULL);
- if (!asr_session->channel) {
+ asr_session->asr_channel = mrcp_client_recognizer_channel_create(context, asr_session->client_session, NULL);
+ if (!asr_session->asr_channel) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create recognizer channel\n");
return SWITCH_STATUS_FALSE;
}
- mrcp_client_context_channel_add(asr_client_context, asr_session->client_session, asr_session->channel, NULL);
+ mrcp_client_context_channel_add(context, asr_session->client_session, asr_session->asr_channel, NULL);
/* wait for recognizer channel creation */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "WAITING FOR CHAN CREATE\n");
@@ -642,7 +478,7 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Start Recognizer\n");
- openmrcp_recog_start(asr_client_context, asr_session, path);
+ openmrcp_recog_start(context, asr_session, path);
}
else {
@@ -656,7 +492,7 @@
/*! function to feed audio to the ASR*/
static switch_status_t openmrcp_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
- asr_session_t *asr_session = (asr_session_t *) ah->private_info;
+ openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
media_frame_t media_frame;
audio_sink_t *audio_sink = mrcp_client_audio_sink_get(asr_session->audio_channel);
@@ -708,8 +544,8 @@
*/
static switch_status_t openmrcp_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
- asr_session_t *asr_session = (asr_session_t *) ah->private_info;
- mrcp_client_context_t *context = openmrcp_module.asr_client_context;
+ openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
+ mrcp_client_context_t *context = asr_session->profile->mrcp_context;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "openmrcp_asr_close()\n");
@@ -718,7 +554,7 @@
// destroy channel
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Going to DESTROY CHANNEL\n");
- mrcp_client_context_channel_destroy(context, asr_session->client_session, asr_session->channel);
+ mrcp_client_context_channel_destroy(context, asr_session->client_session, asr_session->asr_channel);
if (wait_for_event(asr_session->event_queue,OPENMRCP_EVENT_CHANNEL_DESTROY,10000) == MRCP_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPENMRCP_EVENT_CHANNEL_DESTROY received\n");
}
@@ -741,7 +577,7 @@
mrcp_client_context_session_destroy(context, asr_session->client_session);
// destroys the asr_session struct
- asr_session_destroy(asr_session);
+ openmrcp_session_destroy(asr_session);
switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED);
@@ -757,7 +593,7 @@
*/
static switch_status_t openmrcp_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
- asr_session_t *asr_session = (asr_session_t *) ah->private_info;
+ openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
switch_status_t rv = (switch_test_flag(asr_session, FLAG_HAS_TEXT) || switch_test_flag(asr_session, FLAG_BARGE)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
@@ -767,7 +603,7 @@
/*! This will be called after asr_check_results returns SUCCESS */
static switch_status_t openmrcp_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
{
- asr_session_t *asr_session = (asr_session_t *) ah->private_info;
+ openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
switch_status_t ret = SWITCH_STATUS_SUCCESS;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "openmrcp_asr_get_results called\n");
@@ -812,7 +648,7 @@
}
-static mrcp_status_t synth_speak(mrcp_client_context_t *context, tts_session_t *tts_session, char *text)
+static mrcp_status_t synth_speak(mrcp_client_context_t *context, openmrcp_session_t *tts_session, char *text)
{
mrcp_generic_header_t *generic_header;
mrcp_message_t *mrcp_message;
@@ -835,7 +671,7 @@
strcat(text2speak, text);
strcat(text2speak, xml_tail);
- mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->channel,SYNTHESIZER_SPEAK);
+ mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->tts_channel,SYNTHESIZER_SPEAK);
if(!mrcp_message) {
return MRCP_STATUS_FAILURE;
}
@@ -852,9 +688,9 @@
return mrcp_client_context_channel_modify(context,tts_session->client_session,mrcp_message);
}
-static mrcp_status_t synth_stop(mrcp_client_context_t *context, tts_session_t *tts_session)
+static mrcp_status_t synth_stop(mrcp_client_context_t *context, openmrcp_session_t *tts_session)
{
- mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->channel,SYNTHESIZER_STOP);
+ mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context,tts_session->client_session,tts_session->tts_channel,SYNTHESIZER_STOP);
if(!mrcp_message) {
return MRCP_STATUS_FAILURE;
}
@@ -865,69 +701,58 @@
static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, char *voice_name, int rate, switch_speech_flag_t *flags)
{
- tts_session_t *tts_session;
- mrcp_client_context_t *tts_client_context = openmrcp_module.tts_client_context ;
+ openmrcp_session_t *tts_session;
/* create session */
- tts_session = tts_session_create();
+ tts_session = openmrcp_session_create(openmrcp_module.tts_profile);
if (!tts_session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "tts_session creation FAILED\n");
return SWITCH_STATUS_GENERR;
}
- tts_session->client_session = mrcp_client_context_session_create(tts_client_context,tts_session);
- if (!tts_session->client_session) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "tts_session creation FAILED\n");
- return SWITCH_STATUS_GENERR;
- }
-
tts_session->flags = *flags;
switch_mutex_init(&tts_session->flag_mutex, SWITCH_MUTEX_NESTED, tts_session->pool);
-
+
sh->private_info = tts_session;
-
return SWITCH_STATUS_SUCCESS;
-
}
static switch_status_t openmrcp_tts_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags)
{
- tts_session_t *tts_session = (tts_session_t *) sh->private_info;
- mrcp_client_context_t *tts_client_context = openmrcp_module.tts_client_context ;
+ openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
+ mrcp_client_context_t *context = tts_session->profile->mrcp_context;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "synth_stop\n");
- synth_stop(tts_client_context,tts_session); // TODO
+ synth_stop(context,tts_session); // TODO
wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_CHANNEL_MODIFY,5000);
-
-
/* terminate tts session */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Terminate tts_session\n");
- mrcp_client_context_session_terminate(tts_client_context,tts_session->client_session);
+ mrcp_client_context_session_terminate(context,tts_session->client_session);
/* wait for tts session termination */
wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_SESSION_TERMINATE,10000);
/* destroy demo session */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "destroy tts_session\n");
- mrcp_client_context_session_destroy(tts_client_context,tts_session->client_session);
- tts_session_destroy(tts_session);
+ mrcp_client_context_session_destroy(context,tts_session->client_session);
+ openmrcp_session_destroy(tts_session);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t openmrcp_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
{
- tts_session_t *tts_session = (tts_session_t *) sh->private_info;
- mrcp_client_context_t *tts_client_context = openmrcp_module.tts_client_context ;
+ openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
+ mrcp_client_context_t *context = tts_session->profile->mrcp_context;
/* create synthesizer channel */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Create Synthesizer Channel\n");
- tts_session->channel = mrcp_client_synthesizer_channel_create(tts_client_context,tts_session->client_session,NULL);
- if (!tts_session->channel) {
+ tts_session->tts_channel = mrcp_client_synthesizer_channel_create(context,tts_session->client_session,NULL);
+ if (!tts_session->tts_channel) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create synthesizer channel\n");
return SWITCH_STATUS_FALSE;
}
- mrcp_client_context_channel_add(tts_client_context, tts_session->client_session, tts_session->channel, NULL);
+ mrcp_client_context_channel_add(context, tts_session->client_session, tts_session->tts_channel, NULL);
/* wait for synthesizer channel creation */
if(wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_CHANNEL_CREATE,5000) == MRCP_STATUS_SUCCESS) {
@@ -935,7 +760,7 @@
wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_NONE,1000); // XXX: what are we waiting for??
/* speak */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Going to speak\n");
- synth_speak(tts_client_context,tts_session, text);
+ synth_speak(context, tts_session, text);
}
else {
@@ -954,7 +779,7 @@
*/
static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
{
- tts_session_t *tts_session = (tts_session_t *) sh->private_info;
+ openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
size_t return_len=0;
media_frame_t media_frame;
audio_source_t *audio_source;
@@ -1048,47 +873,93 @@
};
-static switch_status_t do_config(void)
+static switch_status_t do_config()
{
char *cf = "mod_openmrcp.conf";
- switch_xml_t cfg, xml, settings, param;
+ const char *asr_profile_name = NULL;
+ const char *tts_profile_name = NULL;
+ switch_xml_t cfg, xml, settings, profiles, xprofile, param;
+ openmrcp_profile_t *mrcp_profile;
+ openmrcp_client_options_t *mrcp_options;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
- memset(&globals,0,sizeof(globals));
-
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
+ const char *var = switch_xml_attr_soft(param, "name");
+ const char *val = switch_xml_attr_soft(param, "value");
- if (!strcasecmp(var, "asr_client_ip")) {
- globals.asr_client_ip = val;
- } else if (!strcasecmp(var, "asr_server_ip")) {
- globals.asr_server_ip = val;
- } else if (!strcasecmp(var, "asr_proto_version")) {
- globals.asr_proto_version =(uint32_t) atoi(val);
- } else if (!strcasecmp(var, "asr_client_port")) {
- globals.asr_client_port = (apr_port_t) atoi(val);
- } else if (!strcasecmp(var, "asr_server_port")) {
- globals.asr_server_port = (apr_port_t) atoi(val);
- } else if (!strcasecmp(var, "tts_client_ip")) {
- globals.tts_client_ip = val;
- } else if (!strcasecmp(var, "tts_server_ip")) {
- globals.tts_server_ip = val;
- } else if (!strcasecmp(var, "tts_proto_version")) {
- globals.tts_proto_version =(uint32_t) atoi(val);
- } else if (!strcasecmp(var, "tts_client_port")) {
- globals.tts_client_port = (apr_port_t) atoi(val);
- } else if (!strcasecmp(var, "tts_server_port")) {
- globals.tts_server_port = (apr_port_t) atoi(val);
- } else if (!strcasecmp(var, "rtp_port_min")) {
- globals.rtp_port_min = (apr_port_t) atoi(val);
- } else if (!strcasecmp(var, "rtp_port_max")) {
- globals.rtp_port_max = (apr_port_t) atoi(val);
+ if (!strcasecmp(var, "asr_default_profile")) {
+ asr_profile_name = val;
+ } else if (!strcasecmp(var, "tts_default_profile")) {
+ tts_profile_name = val;
+ }
+ }
+ }
+ if ((profiles = switch_xml_child(cfg, "profiles"))) {
+ for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
+ const char *profile_name = switch_xml_attr_soft(xprofile, "name");
+ mrcp_profile = switch_core_alloc(openmrcp_module.pool,sizeof(openmrcp_profile_t));
+ mrcp_profile->mrcp_client = NULL;
+ mrcp_profile->mrcp_context = NULL;
+ mrcp_profile->name = "noname";
+ if(profile_name) {
+ mrcp_profile->name = switch_core_strdup(openmrcp_module.pool,profile_name);
+ }
+
+ mrcp_options = openmrcp_client_options_create(openmrcp_module.pool);
+ for (param = switch_xml_child(xprofile, "param"); param; param = param->next) {
+ const char *var = switch_xml_attr_soft(param, "name");
+ const char *val = switch_xml_attr_soft(param, "value");
+
+ if (!strcasecmp(var, "proto_version")) {
+ mrcp_options->proto_version =(mrcp_version_t) atoi(val);
+ }
+ else if (!strcasecmp(var, "client_ip")) {
+ mrcp_options->client_ip = switch_core_strdup(openmrcp_module.pool,val);
+ } else if (!strcasecmp(var, "server_ip")) {
+ mrcp_options->server_ip = switch_core_strdup(openmrcp_module.pool,val);
+ } else if (!strcasecmp(var, "client_port")) {
+ mrcp_options->client_port = (apr_port_t) atoi(val);
+ } else if (!strcasecmp(var, "server_port")) {
+ mrcp_options->server_port = (apr_port_t) atoi(val);
+ } else if (!strcasecmp(var, "rtp_port_min")) {
+ mrcp_options->rtp_port_min = (apr_port_t) atoi(val);
+ } else if (!strcasecmp(var, "rtp_port_max")) {
+ mrcp_options->rtp_port_max = (apr_port_t) atoi(val);
+ }
+ }
+ mrcp_profile->mrcp_options = mrcp_options;
+
+ /* add profile */
+ if (!switch_core_hash_find(openmrcp_module.profile_hash, mrcp_profile->name)) {
+ switch_core_hash_insert(openmrcp_module.profile_hash, mrcp_profile->name, mrcp_profile);
+
+ /* try to set default asr profile */
+ if (!openmrcp_module.asr_profile) {
+ if (asr_profile_name) {
+ if (!strcasecmp(mrcp_profile->name,asr_profile_name)) {
+ openmrcp_module.asr_profile = mrcp_profile;
+ }
+ }
+ else {
+ openmrcp_module.asr_profile = mrcp_profile;
+ }
+ }
+ /* try to set default tts profile */
+ if (!openmrcp_module.tts_profile) {
+ if (tts_profile_name) {
+ if (!strcasecmp(mrcp_profile->name,tts_profile_name)) {
+ openmrcp_module.tts_profile = mrcp_profile;
+ }
+ }
+ else {
+ openmrcp_module.tts_profile = mrcp_profile;
+ }
+ }
}
}
}
@@ -1098,85 +969,61 @@
return SWITCH_STATUS_SUCCESS;
}
-
-static switch_status_t mrcp_init()
+static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile)
{
- mrcp_mem_pool_t *pool;
- mrcp_client_event_handler_t *asr_event_handler;
- mrcp_client_t *asr_client;
- mrcp_client_context_t *asr_client_context;
- openmrcp_client_options_t *asr_options;
- mrcp_client_event_handler_t *tts_event_handler;
- mrcp_client_t *tts_client;
- mrcp_client_context_t *tts_client_context;
- openmrcp_client_options_t *tts_options;
-
+ mrcp_client_event_handler_t *mrcp_event_handler;
+ mrcp_client_t *mrcp_client;
+ mrcp_client_context_t *mrcp_context;
+
/*!
- Perform one-time initialization of asr client library
+ Perform one-time initialization of mrcp client library
*/
- pool = mrcp_global_pool_get();
- asr_options = mrcp_palloc(pool,sizeof(openmrcp_client_options_t));
- asr_event_handler = mrcp_palloc(pool,sizeof(mrcp_client_event_handler_t));
- set_default_asr_options(asr_options);
-
- asr_event_handler->on_session_initiate = asr_on_session_initiate;
- asr_event_handler->on_session_terminate = asr_on_session_terminate;
- asr_event_handler->on_channel_add = asr_on_channel_add;
- asr_event_handler->on_channel_remove = asr_on_channel_remove;
- asr_event_handler->on_channel_modify = asr_on_channel_modify;
-
- // create asr client context, which to must be passed to client engine
- asr_client_context = mrcp_client_context_create(&openmrcp_module,asr_event_handler);
- if(!asr_client_context) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_client_context creation failed\n");
+ mrcp_event_handler = switch_core_alloc(openmrcp_module.pool,sizeof(mrcp_client_event_handler_t));
+ mrcp_event_handler->on_session_initiate = openmrcp_on_session_initiate;
+ mrcp_event_handler->on_session_terminate = openmrcp_on_session_terminate;
+ mrcp_event_handler->on_channel_add = openmrcp_on_channel_add;
+ mrcp_event_handler->on_channel_remove = openmrcp_on_channel_remove;
+ mrcp_event_handler->on_channel_modify = openmrcp_on_channel_modify;
+
+ // create client context, which must be passed to client engine
+ mrcp_context = mrcp_client_context_create(&openmrcp_module,mrcp_event_handler);
+ if(!mrcp_context) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mrcp_client_context creation failed\n");
return SWITCH_STATUS_GENERR;
}
- openmrcp_module.asr_client_context = asr_client_context;
+ profile->mrcp_context = mrcp_context;
// this basically starts a thread that pulls events from the event queue
// and handles them
- asr_client = openmrcp_client_start(asr_options,asr_client_context);
- if(!asr_client) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "openasr_client_start FAILED\n");
- mrcp_client_context_destroy(asr_client_context);
+ mrcp_client = openmrcp_client_start(profile->mrcp_options,mrcp_context);
+ if(!mrcp_client) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "openmrcp_client_start FAILED\n");
+ mrcp_client_context_destroy(mrcp_context);
return SWITCH_STATUS_GENERR;
}
+ profile->mrcp_client = mrcp_client;
+ return SWITCH_STATUS_SUCCESS;
+}
- openmrcp_module.asr_client = asr_client;
- /*!
- Perform one-time initialization of tts client library
- */
-
- pool = mrcp_global_pool_get();
- tts_options = mrcp_palloc(pool,sizeof(openmrcp_client_options_t));
- tts_event_handler = mrcp_palloc(pool,sizeof(mrcp_client_event_handler_t));
- set_default_tts_options(tts_options);
-
- tts_event_handler->on_session_initiate = tts_on_session_initiate;
- tts_event_handler->on_session_terminate = tts_on_session_terminate;
- tts_event_handler->on_channel_add = tts_on_channel_add;
- tts_event_handler->on_channel_remove = tts_on_channel_remove;
- tts_event_handler->on_channel_modify = tts_on_channel_modify;
-
- // create tts client context, which to must be passed to client engine
- tts_client_context = mrcp_client_context_create(&openmrcp_module,tts_event_handler);
- if(!tts_client_context) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "tts_client_context creation failed\n");
- return SWITCH_STATUS_GENERR;
- }
- openmrcp_module.tts_client_context = tts_client_context;
+static switch_status_t openmrcp_init()
+{
+ openmrcp_module.pool = mrcp_global_pool_get();
+ openmrcp_module.asr_profile = NULL;
+ openmrcp_module.tts_profile = NULL;
- // this basically starts a thread that pulls events from the event queue
- // and handles them
- tts_client = openmrcp_client_start(tts_options,tts_client_context);
- if(!tts_client) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "opentts_client_start FAILED\n");
- mrcp_client_context_destroy(tts_client_context);
- return SWITCH_STATUS_GENERR;
- }
+ switch_core_hash_init(&openmrcp_module.profile_hash,openmrcp_module.pool);
- openmrcp_module.tts_client = tts_client;
+ /* read config */
+ do_config();
+
+ /* run default asr/tts profiles */
+ if(openmrcp_module.asr_profile) {
+ openmrcp_profile_run(openmrcp_module.asr_profile);
+ }
+ if(openmrcp_module.tts_profile && openmrcp_module.tts_profile != openmrcp_module.asr_profile) {
+ openmrcp_profile_run(openmrcp_module.tts_profile);
+ }
return SWITCH_STATUS_SUCCESS;
}
@@ -1186,12 +1033,10 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &openmrcp_module_interface;
- /* read config */
- do_config();
+ mrcp_global_init();
/* initialize openmrcp */
- mrcp_global_init();
- mrcp_init();
+ openmrcp_init();
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
1
0
16 Aug '07
Author: mikej
Date: Thu Aug 16 13:19:27 2007
New Revision: 5604
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
Log:
fix registration bug when doing authed calls
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Thu Aug 16 13:19:27 2007
@@ -435,6 +435,10 @@
}
reg:
+ if (regtype != REG_REGISTER) {
+ return 0;
+ }
+
if (exptime) {
if (!sofia_reg_find_reg_url(profile, to_user, to_host, buf, sizeof(buf))) {
sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','%q', '%q', %ld)",
1
0
16 Aug '07
Author: achaloyan
Date: Thu Aug 16 10:20:21 2007
New Revision: 5603
Modified:
freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
Log:
using FS media clock to send/receive audio data within asr/tts feed
Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c (original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c Thu Aug 16 10:20:21 2007
@@ -36,10 +36,6 @@
* TODO
* =======
*
- * - MAJOR DESIGN ISSUE!! It is way too expensive to be calling malloc on every audio frame,
- * this needs to send the packet directly. OpenMrcp will need a way to disable their own
- * timer so that the fs timer is the only one driving the media.
- *
* - There are two memory pools in use. One in asr_session which is managed
* by this module, and one in the switch_asr_handle_t, which is managed by freeswitch.
* These need to be consolidated into one. (basically throw away the one in asr_session)
@@ -50,9 +46,6 @@
* - openmrcp_flush_tts, openmrcp_text_param_tts, openmrcp_numeric_param_tts,
* openmrcp_float_param_tts need to have functionality added
*
- * - fix audio problem with TTS, convert from using queue to using a switch_buffer
- * (in progress)
- *
* - use a regex for extracting xml from raw result received from mrcp recognition
* server
*
@@ -118,10 +111,9 @@
struct asr_session_t {
mrcp_session_t *client_session;
mrcp_client_channel_t *channel;
- switch_queue_t *audio_queue;
+ mrcp_audio_channel_t *audio_channel;
switch_queue_t *event_queue;
mrcp_message_t *mrcp_message_last_rcvd;
- audio_source_t *source;
apr_pool_t *pool;
uint32_t flags;
switch_mutex_t *flag_mutex;
@@ -131,33 +123,13 @@
struct tts_session_t {
mrcp_session_t *client_session;
mrcp_client_channel_t *channel;
- switch_queue_t *audio_queue; // TO BE REMOVED
+ mrcp_audio_channel_t *audio_channel;
switch_queue_t *event_queue;
- switch_mutex_t *audio_lock;
- switch_buffer_t *audio_buffer;
- audio_sink_t *sink;
apr_pool_t *pool;
- switch_speech_flag_t flags;
+ switch_speech_flag_t flags;
switch_mutex_t *flag_mutex;
};
-static apr_status_t openmrcp_recognizer_read_frame(audio_source_t *source, media_frame_t *frame);
-static apr_status_t openmrcp_tts_write_frame(audio_sink_t *sink, media_frame_t *frame);
-
-static const audio_source_method_set_t audio_source_method_set = {
- NULL,
- NULL,
- NULL,
- openmrcp_recognizer_read_frame
-};
-
-static const audio_sink_method_set_t audio_sink_method_set = {
- NULL,
- NULL,
- NULL,
- openmrcp_tts_write_frame
-};
-
typedef enum {
FLAG_HAS_TEXT = (1 << 0),
FLAG_BARGE = (1 << 1),
@@ -188,7 +160,7 @@
asr_session->pool = session_pool;
asr_session->client_session = NULL;
asr_session->channel = NULL;
- asr_session->audio_queue = NULL;
+ asr_session->audio_channel = NULL;
asr_session->event_queue = NULL;
@@ -215,7 +187,7 @@
tts_session->pool = session_pool;
tts_session->client_session = NULL;
tts_session->channel = NULL;
- tts_session->audio_queue = NULL;
+ tts_session->audio_channel = NULL;
tts_session->event_queue = NULL;
/* create an event queue */
@@ -247,8 +219,6 @@
return MRCP_STATUS_FAILURE;
}
- switch_buffer_destroy(&tts_session->audio_buffer);
-
if(tts_session->pool) {
apr_pool_destroy(tts_session->pool);
tts_session->pool = NULL;
@@ -362,13 +332,14 @@
return asr_session_signal_event(asr_session,OPENMRCP_EVENT_SESSION_TERMINATE);
}
-static mrcp_status_t asr_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *channel)
+static mrcp_status_t asr_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
{
asr_session_t *asr_session = mrcp_client_context_session_object_get(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_on_channel_add called\n");
if(!asr_session) {
return MRCP_STATUS_FAILURE;
}
+ asr_session->audio_channel = audio_channel;
return asr_session_signal_event(asr_session,OPENMRCP_EVENT_CHANNEL_CREATE);
}
@@ -454,13 +425,14 @@
return tts_session_signal_event(tts_session,OPENMRCP_EVENT_SESSION_TERMINATE);
}
-static mrcp_status_t tts_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *channel)
+static mrcp_status_t tts_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
{
tts_session_t *tts_session = mrcp_client_context_session_object_get(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "tts_on_channel_add called\n");
if(!tts_session) {
return MRCP_STATUS_FAILURE;
}
+ tts_session->audio_channel = audio_channel;
return tts_session_signal_event(tts_session,OPENMRCP_EVENT_CHANNEL_CREATE);
}
@@ -531,92 +503,10 @@
return APR_SUCCESS;
}
-
-/**
- * Called back by openmrcp client thread every time it receives audio
- * from the TTS server we are connected to. Puts audio in a queueu
- * and it will be pulled out from read_tts
- */
-static apr_status_t openmrcp_tts_write_frame(audio_sink_t *sink, media_frame_t *frame)
-{
- tts_session_t *tts_session = sink->object;
- media_frame_t *media_frame;
- switch_byte_t *buffer;
- size_t len;
-
- len = frame->codec_frame.size;
-
- /* create new media frame */
- media_frame = (media_frame_t *) switch_core_alloc(tts_session->pool, sizeof(media_frame_t));
- if (!media_frame) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "media_frame creation failed\n");
- return SWITCH_STATUS_MEMERR;
- }
-
- /**
- * since *frame might get freed by caller (true or false?), allocate a
- * new buffer and copy *data into it.
- **/
- buffer = (switch_byte_t *) switch_core_alloc(tts_session->pool, sizeof(switch_byte_t)*len);
- if (!buffer) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate buffer\n");
- return SWITCH_STATUS_MEMERR;
- }
- buffer = memcpy(buffer, frame->codec_frame.buffer, len);
- media_frame->codec_frame.buffer = buffer;
- media_frame->codec_frame.size = len;
- media_frame->type = MEDIA_FRAME_TYPE_AUDIO;
-
-
- /* push audio to queue */
- if (switch_queue_trypush(tts_session->audio_queue, (void *) media_frame)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "could not push audio to queue\n");
- return MRCP_STATUS_FAILURE;
- }
-
- return MRCP_STATUS_SUCCESS;
-
-}
-
-
-/**
- * Called back by openmcp client thread every time its ready for more audio to send
- * the recognition server we are connected to. Reads data that was put into a
- * shared fifo queue upon receiving audio frames from asr_feed()
- */
-static apr_status_t openmrcp_recognizer_read_frame(audio_source_t *source, media_frame_t *frame)
-{
- asr_session_t *asr_session = source->object;
- apr_status_t result;
- media_frame_t *queue_frame = NULL;
- frame->type = MEDIA_FRAME_TYPE_NONE;
-
- /* pop next media frame data from incoming queue into frame */
- if(asr_session->audio_queue) {
- if (switch_queue_trypop(asr_session->audio_queue, (void *) &queue_frame)) {
- // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "could not pop from queue\n");
- result = MRCP_STATUS_FAILURE;
- }
- else {
- frame->codec_frame.size = queue_frame->codec_frame.size;
- frame->codec_frame.buffer = queue_frame->codec_frame.buffer;
- frame->type = MEDIA_FRAME_TYPE_AUDIO;
- result = APR_SUCCESS;
- }
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no audio queue\n");
- result = MRCP_STATUS_FAILURE;
- }
-
- return result;
-}
-
/** Read in the grammar and construct an MRCP Recognize message that has
The grammar attached as the payload */
static mrcp_status_t openmrcp_recog_start(mrcp_client_context_t *context, asr_session_t *asr_session, char *path)
{
-
mrcp_generic_header_t *generic_header;
apr_status_t rv;
apr_file_t *fp;
@@ -654,7 +544,6 @@
/* send the MRCP RECOGNIZE message to MRCP server */
return mrcp_client_context_channel_modify(context, asr_session->client_session, mrcp_message);
-
}
@@ -670,7 +559,6 @@
{
mrcp_client_context_t *asr_client_context = openmrcp_module.asr_client_context ;
asr_session_t *asr_session;
- audio_source_t *source;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_open called, codec: %s, rate: %d\n", codec, rate);
@@ -696,15 +584,6 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only 8kz supported\n");
return SWITCH_STATUS_GENERR;
}
-#if 0
- if (CODEC_FRAME_TIME_BASE != 20) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must recompile openmrcp with #define CODEC_FRAME_TIME_BASE 20\n");
- return SWITCH_STATUS_GENERR;
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CODEC_FRAME_TIME_BASE: %d\n", CODEC_FRAME_TIME_BASE);
- }
-#endif
/* create session */
asr_session = asr_session_create();
if (!asr_session) {
@@ -717,29 +596,12 @@
return SWITCH_STATUS_GENERR;
}
- /* create audio source */
- source = mrcp_palloc(asr_session->pool,sizeof(audio_source_t));
- source->method_set = &audio_source_method_set;
- source->object = asr_session;
- asr_session->source = source;
-
- /**
- * create a new fifo queue. incoming audio received from freeswitch
- * will be put into this queue, and it will be later pulled out by
- * the openmrcp client thread.
- */
- if (switch_queue_create(&asr_session->audio_queue, 10000, asr_session->pool)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "audio queue creation failed\n");
- return SWITCH_STATUS_MEMERR;
- }
-
asr_session->flags = *flags;
switch_mutex_init(&asr_session->flag_mutex, SWITCH_MUTEX_NESTED, asr_session->pool);
ah->private_info = asr_session;
return SWITCH_STATUS_SUCCESS;
-
}
/* function to load a grammar to the asr interface */
@@ -753,13 +615,12 @@
asr_session_t *asr_session = (asr_session_t *) ah->private_info;
mrcp_client_context_t *asr_client_context = openmrcp_module.asr_client_context;
- audio_source_t *source = asr_session->source;
/* create recognizer channel, also starts outgoing rtp media */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loading grammar\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Create Recognizer Channel\n");
- asr_session->channel = mrcp_client_recognizer_channel_create(asr_client_context, asr_session->client_session, source);
+ asr_session->channel = mrcp_client_recognizer_channel_create(asr_client_context, asr_session->client_session, NULL);
if (!asr_session->channel) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create recognizer channel\n");
return SWITCH_STATUS_FALSE;
@@ -792,47 +653,26 @@
return SWITCH_STATUS_SUCCESS;
}
-
/*! function to feed audio to the ASR*/
static switch_status_t openmrcp_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
-
asr_session_t *asr_session = (asr_session_t *) ah->private_info;
- media_frame_t *media_frame;
- switch_byte_t *buffer;
-
- /* create new media frame */
- media_frame = (media_frame_t *) switch_core_alloc(asr_session->pool, sizeof(media_frame_t));
- if (!media_frame) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "media_frame creation failed\n");
- return SWITCH_STATUS_MEMERR;
- }
-
- /**
- * since *data buffer might get freed by caller (true or false?), allocate a
- * new buffer and copy *data into it.
- *
- * MAJOR DESIGN ISSUE!! It is way too expensive to be calling malloc on every audio frame,
- * this needs to send the packet directly. OpenMrcp will need a way to disable their own
- * timer so that the fs timer is the only one driving the media.
- **/
- buffer = (switch_byte_t *) switch_core_alloc(asr_session->pool, sizeof(switch_byte_t)*len);
- if (!buffer) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate buffer\n");
- return SWITCH_STATUS_MEMERR;
+ media_frame_t media_frame;
+ audio_sink_t *audio_sink = mrcp_client_audio_sink_get(asr_session->audio_channel);
+
+ media_frame.type = MEDIA_FRAME_TYPE_AUDIO;
+ /* sampling rate and frame size should be retrieved from audio sink */
+ media_frame.codec_frame.size = 160;
+ media_frame.codec_frame.buffer = data;
+ while(len >= media_frame.codec_frame.size) {
+ audio_sink->method_set->write_frame(audio_sink,&media_frame);
+
+ len -= (unsigned int)media_frame.codec_frame.size;
+ media_frame.codec_frame.buffer = (char*)media_frame.codec_frame.buffer + media_frame.codec_frame.size;
}
- buffer = memcpy(buffer, data, len);
-
- media_frame->codec_frame.buffer = buffer;
- media_frame->codec_frame.size = len;
- media_frame->type = MEDIA_FRAME_TYPE_AUDIO;
-
- /* push audio to queue */
- if (switch_queue_trypush(asr_session->audio_queue, (void *) media_frame)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "could not push audio to queue\n");
- return SWITCH_STATUS_GENERR;
+ if(len > 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not framed alligned data len [%d]\n",len);
}
-
return SWITCH_STATUS_SUCCESS;
}
@@ -1025,9 +865,7 @@
static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, char *voice_name, int rate, switch_speech_flag_t *flags)
{
-
tts_session_t *tts_session;
- audio_sink_t *sink;
mrcp_client_context_t *tts_client_context = openmrcp_module.tts_client_context ;
/* create session */
@@ -1042,32 +880,6 @@
return SWITCH_STATUS_GENERR;
}
-
- /* create audio sink */
- sink = mrcp_palloc(tts_session->pool,sizeof(audio_sink_t));
- sink->method_set = &audio_sink_method_set;
- sink->object = tts_session;
- tts_session->sink = sink;
-
-
- /**
- * create a new fifo queue.
- */
- if (switch_queue_create(&tts_session->audio_queue, 10000, tts_session->pool)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "audio queue creation failed\n");
- return SWITCH_STATUS_MEMERR;
- }
-
- /* create mutex that will be used to lock audio buffer */
- switch_mutex_init(&tts_session->audio_lock, SWITCH_MUTEX_NESTED, sh->memory_pool);
-
- /* create audio buffer */
- if (switch_buffer_create_dynamic(&tts_session->audio_buffer, MY_BLOCK_SIZE, MY_BUF_LEN, 0) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write Buffer Creation Failed!\n");
- return SWITCH_STATUS_MEMERR;
- }
-
-
tts_session->flags = *flags;
switch_mutex_init(&tts_session->flag_mutex, SWITCH_MUTEX_NESTED, tts_session->pool);
@@ -1104,14 +916,12 @@
static switch_status_t openmrcp_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
{
-
tts_session_t *tts_session = (tts_session_t *) sh->private_info;
mrcp_client_context_t *tts_client_context = openmrcp_module.tts_client_context ;
- audio_sink_t *sink = tts_session->sink;
/* create synthesizer channel */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Create Synthesizer Channel\n");
- tts_session->channel = mrcp_client_synthesizer_channel_create(tts_client_context,tts_session->client_session,sink);
+ tts_session->channel = mrcp_client_synthesizer_channel_create(tts_client_context,tts_session->client_session,NULL);
if (!tts_session->channel) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create synthesizer channel\n");
return SWITCH_STATUS_FALSE;
@@ -1144,63 +954,34 @@
*/
static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
{
- media_frame_t *queue_frame = NULL;
tts_session_t *tts_session = (tts_session_t *) sh->private_info;
size_t return_len=0;
- size_t amt2copy=0;
- size_t desired = *datalen;
- switch_byte_t *audiodata = (switch_byte_t *) data;
-
- while(return_len < desired) {
-
- if (switch_test_flag(tts_session, FLAG_SPEAK_COMPLETE)) {
- // tell fs we are done
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
- return SWITCH_STATUS_BREAK;
- }
-
- if (switch_queue_pop(tts_session->audio_queue, (void *) &queue_frame)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "could not pop from queue\n");
- if (switch_test_flag(tts_session, FLAG_SPEAK_COMPLETE)) {
- // tell fs we are done
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
- return SWITCH_STATUS_BREAK;
- }
- break;
- }
- else {
- if (switch_test_flag(tts_session, FLAG_SPEAK_COMPLETE)) {
- // tell fs we are done
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
- return SWITCH_STATUS_BREAK;
- }
-
- if (queue_frame->codec_frame.size >= desired) {
- amt2copy = desired;
- }
- else {
- // limit the amt we copy to audiodata to be LTE datalen
- // if the queue frame has _more_, just ignore it (TODO: fix this!)
- amt2copy = queue_frame->codec_frame.size;
- }
- memcpy(audiodata, queue_frame->codec_frame.buffer, amt2copy);
- return_len += amt2copy;
- *datalen = return_len;
- audiodata += amt2copy; // move pointer forward
- *rate = 8000;
- }
-
- }
-
- // double check we actually read something
- if (*datalen == 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no data read from buffer\n");
- return SWITCH_STATUS_FALSE;
- }
- else if (*datalen < desired) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "return_len: (%d) < desired: (%d)\n", return_len, desired);
- }
+ media_frame_t media_frame;
+ audio_source_t *audio_source;
+ if (switch_test_flag(tts_session, FLAG_SPEAK_COMPLETE)) {
+ /* tell fs we are done */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
+ return SWITCH_STATUS_BREAK;
+ }
+
+ audio_source = mrcp_client_audio_source_get(tts_session->audio_channel);
+ if(!audio_source) {
+ return SWITCH_STATUS_BREAK;
+ }
+
+ /* sampling rate and frame size should be retrieved from audio source */
+ *rate = 8000;
+ media_frame.codec_frame.size = 160;
+ while(return_len < *datalen) {
+ media_frame.codec_frame.buffer = (char*)data + return_len;
+ audio_source->method_set->read_frame(audio_source,&media_frame);
+ if(media_frame.type != MEDIA_FRAME_TYPE_AUDIO) {
+ memset(media_frame.codec_frame.buffer,0,media_frame.codec_frame.size);
+ }
+ return_len += media_frame.codec_frame.size;
+ }
+ *datalen = return_len;
return SWITCH_STATUS_SUCCESS;
}
@@ -1248,7 +1029,6 @@
/*.speech_text_param_tts*/ openmrcp_text_param_tts,
/*.speech_numeric_param_tts*/ openmrcp_numeric_param_tts,
/*.speech_float_param_tts*/ openmrcp_float_param_tts,
-
};
static switch_loadable_module_interface_t openmrcp_module_interface = {
@@ -1334,7 +1114,6 @@
/*!
Perform one-time initialization of asr client library
*/
-
pool = mrcp_global_pool_get();
asr_options = mrcp_palloc(pool,sizeof(openmrcp_client_options_t));
asr_event_handler = mrcp_palloc(pool,sizeof(mrcp_client_event_handler_t));
@@ -1404,7 +1183,6 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load)
{
-
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &openmrcp_module_interface;
1
0
14 Aug '07
Author: anthm
Date: Tue Aug 14 15:36:56 2007
New Revision: 5602
Modified:
freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
Log:
revert unintended commit
Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c Tue Aug 14 15:36:56 2007
@@ -1703,6 +1703,7 @@
write_frame.timestamp = timer.samplecount;
switch_core_session_write_frame(member->session, &write_frame, -1, 0);
switch_core_timer_next(&timer);
+
/* forget the conference data we played file node data instead */
switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
@@ -1774,7 +1775,7 @@
switch_mutex_unlock(member->flag_mutex);
if (use_timer) {
- //switch_core_timer_next(&timer);
+ switch_core_timer_next(&timer);
}
} /* Rinse ... Repeat */
1
0
[commit] r5601 - in freeswitch/trunk/src/mod: applications/mod_conference formats/mod_shout
by Freeswitch SVN 14 Aug '07
by Freeswitch SVN 14 Aug '07
14 Aug '07
Author: anthm
Date: Tue Aug 14 15:34:53 2007
New Revision: 5601
Modified:
freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
freeswitch/trunk/src/mod/formats/mod_shout/Makefile
Log:
don't rebuild mod_shout on every make
Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c Tue Aug 14 15:34:53 2007
@@ -1703,7 +1703,6 @@
write_frame.timestamp = timer.samplecount;
switch_core_session_write_frame(member->session, &write_frame, -1, 0);
switch_core_timer_next(&timer);
-
/* forget the conference data we played file node data instead */
switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
@@ -1775,7 +1774,7 @@
switch_mutex_unlock(member->flag_mutex);
if (use_timer) {
- switch_core_timer_next(&timer);
+ //switch_core_timer_next(&timer);
}
} /* Rinse ... Repeat */
Modified: freeswitch/trunk/src/mod/formats/mod_shout/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_shout/Makefile (original)
+++ freeswitch/trunk/src/mod/formats/mod_shout/Makefile Tue Aug 14 15:34:53 2007
@@ -30,6 +30,7 @@
$(LAME_DIR)/Makefile: $(LAME_DIR)
cd $(LAME_DIR) && ./configure $(DEFAULT_ARGS) --disable-decoder
+ $(TOUCH_TARGET)
$(LAMELA): $(LAME_DIR)/Makefile
cd $(LAME_DIR) && $(MAKE)
@@ -40,6 +41,7 @@
$(SHOUT_DIR)/Makefile: $(SHOUT_DIR)
cd $(SHOUT_DIR) && ./configure $(DEFAULT_ARGS) --with-speex=no
+ $(TOUCH_TARGET)
$(SHOUTLA): $(SHOUT_DIR)/Makefile
cd $(SHOUT_DIR) && $(MAKE)
1
0