[Freeswitch-svn] [commit] r5794 - in freeswitch/trunk/src: . include mod/applications/mod_dptools
Freeswitch SVN
anthm at freeswitch.org
Thu Oct 4 11:09:44 EDT 2007
Author: anthm
Date: Thu Oct 4 11:09:44 2007
New Revision: 5794
Modified:
freeswitch/trunk/src/include/switch_ivr.h
freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
freeswitch/trunk/src/switch_ivr.c
Log:
add delay_echo application
Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h (original)
+++ freeswitch/trunk/src/include/switch_ivr.h Thu Oct 4 11:09:44 2007
@@ -699,6 +699,7 @@
SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session, char *macro_name, char *data, char *lang,
switch_input_args_t *args);
+SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms);
/** @} */
SWITCH_END_EXTERN_C
Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Thu Oct 4 11:09:44 2007
@@ -231,6 +231,20 @@
}
}
+SWITCH_STANDARD_APP(delay_function)
+{
+ uint32_t len = 0;
+
+ if (switch_strlen_zero(data)) {
+ len = 1000;
+ } else {
+ len = atoi(data);
+ }
+
+ switch_ivr_delay_echo(session, len);
+
+}
+
SWITCH_STANDARD_APP(eval_function)
{
return;
@@ -1243,6 +1257,7 @@
SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_NONE);
+ SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "strftime", NULL, NULL, strftime_function, NULL, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "phrase", "Say a Phrase", "Say a Phrase", phrase_function, "<macro_name>,<data>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "eval", "Do Nothing", "Do Nothing", eval_function, "", SAF_SUPPORT_NOMEDIA);
Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c (original)
+++ freeswitch/trunk/src/switch_ivr.c Thu Oct 4 11:09:44 2007
@@ -34,8 +34,7 @@
*/
#include <switch.h>
#include <switch_ivr.h>
-
-
+#include "stfu.h"
SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms)
{
@@ -1510,6 +1509,55 @@
return SWITCH_STATUS_FALSE;
}
+SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms)
+{
+ stfu_instance_t *jb;
+ int qlen = 0;
+ switch_codec_t *read_codec;
+ stfu_frame_t *jb_frame;
+ switch_frame_t *read_frame, write_frame = { 0 };
+ switch_status_t status;
+ switch_channel_t *channel;
+ uint32_t interval, samples;
+ uint32_t ts = 0;
+
+ if (delay_ms < 100 || delay_ms > 10000) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Jitterbuffer spec [%d] myst be between 100 and 10000\n", delay_ms);
+ return;
+ }
+
+ read_codec = switch_core_session_get_read_codec(session);
+ interval = read_codec->implementation->microseconds_per_frame / 1000;
+ samples = switch_bytes_per_frame(read_codec->implementation->samples_per_second, interval);
+
+ qlen = delay_ms / (interval);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting delay to %dms (%d frames)\n", delay_ms, qlen);
+ jb = stfu_n_init(qlen);
+
+ channel = switch_core_session_get_channel(session);
+ write_frame.codec = read_codec;
+
+ while(switch_channel_ready(channel)) {
+ status = switch_core_session_read_frame(session, &read_frame, -1, 0);
+ if (!SWITCH_READ_ACCEPTABLE(status)) {
+ break;
+ }
+
+ stfu_n_eat(jb, ts, read_frame->data, read_frame->datalen);
+ ts += interval;
+
+ if ((jb_frame = stfu_n_read_a_frame(jb))) {
+ write_frame.data = jb_frame->data;
+ write_frame.datalen = jb_frame->dlen;
+ status = switch_core_session_write_frame(session, &write_frame, -1, 0);
+ if (!SWITCH_READ_ACCEPTABLE(status)) {
+ break;
+ }
+ }
+ }
+
+ stfu_n_destroy(&jb);
+}
/* For Emacs:
More information about the Freeswitch-svn
mailing list