IVR groundwork (move playback into the core and add timing option)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@447 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
02c67ad8b8
commit
613060fd29
|
@ -55,6 +55,7 @@ src/include/switch_utils.h \
|
||||||
src/include/switch_caller.h \
|
src/include/switch_caller.h \
|
||||||
src/include/switch_buffer.h \
|
src/include/switch_buffer.h \
|
||||||
src/include/switch_event.h \
|
src/include/switch_event.h \
|
||||||
|
src/include/switch_ivr.h\
|
||||||
src/switch_buffer.c \
|
src/switch_buffer.c \
|
||||||
src/switch_caller.c \
|
src/switch_caller.c \
|
||||||
src/switch_channel.c \
|
src/switch_channel.c \
|
||||||
|
@ -65,7 +66,8 @@ src/switch_loadable_module.c \
|
||||||
src/switch_mutex.c \
|
src/switch_mutex.c \
|
||||||
src/switch_utils.c \
|
src/switch_utils.c \
|
||||||
src/switch_event.c \
|
src/switch_event.c \
|
||||||
src/switch_resample.c
|
src/switch_resample.c \
|
||||||
|
src/switch_ivr.c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +88,8 @@ library_include_HEADERS = src/include/switch.h \
|
||||||
src/include/switch_caller.h \
|
src/include/switch_caller.h \
|
||||||
src/include/switch_buffer.h \
|
src/include/switch_buffer.h \
|
||||||
src/include/switch_event.h \
|
src/include/switch_event.h \
|
||||||
src/include/switch_resample.h
|
src/include/switch_resample.h \
|
||||||
|
src/include/switch_ivr.h
|
||||||
|
|
||||||
|
|
||||||
lib_LTLIBRARIES = libfreeswitch.la
|
lib_LTLIBRARIES = libfreeswitch.la
|
||||||
|
|
18
Makefile.in
18
Makefile.in
|
@ -79,7 +79,8 @@ am_libfreeswitch_la_OBJECTS = libfreeswitch_la-switch_buffer.lo \
|
||||||
libfreeswitch_la-switch_mutex.lo \
|
libfreeswitch_la-switch_mutex.lo \
|
||||||
libfreeswitch_la-switch_utils.lo \
|
libfreeswitch_la-switch_utils.lo \
|
||||||
libfreeswitch_la-switch_event.lo \
|
libfreeswitch_la-switch_event.lo \
|
||||||
libfreeswitch_la-switch_resample.lo
|
libfreeswitch_la-switch_resample.lo \
|
||||||
|
libfreeswitch_la-switch_ivr.lo
|
||||||
libfreeswitch_la_OBJECTS = $(am_libfreeswitch_la_OBJECTS)
|
libfreeswitch_la_OBJECTS = $(am_libfreeswitch_la_OBJECTS)
|
||||||
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
|
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
|
||||||
PROGRAMS = $(bin_PROGRAMS)
|
PROGRAMS = $(bin_PROGRAMS)
|
||||||
|
@ -263,6 +264,7 @@ src/include/switch_utils.h \
|
||||||
src/include/switch_caller.h \
|
src/include/switch_caller.h \
|
||||||
src/include/switch_buffer.h \
|
src/include/switch_buffer.h \
|
||||||
src/include/switch_event.h \
|
src/include/switch_event.h \
|
||||||
|
src/include/switch_ivr.h\
|
||||||
src/switch_buffer.c \
|
src/switch_buffer.c \
|
||||||
src/switch_caller.c \
|
src/switch_caller.c \
|
||||||
src/switch_channel.c \
|
src/switch_channel.c \
|
||||||
|
@ -273,7 +275,8 @@ src/switch_loadable_module.c \
|
||||||
src/switch_mutex.c \
|
src/switch_mutex.c \
|
||||||
src/switch_utils.c \
|
src/switch_utils.c \
|
||||||
src/switch_event.c \
|
src/switch_event.c \
|
||||||
src/switch_resample.c
|
src/switch_resample.c \
|
||||||
|
src/switch_ivr.c
|
||||||
|
|
||||||
|
|
||||||
#bindir = $(PREFIX)/bin
|
#bindir = $(PREFIX)/bin
|
||||||
|
@ -293,7 +296,8 @@ library_include_HEADERS = src/include/switch.h \
|
||||||
src/include/switch_caller.h \
|
src/include/switch_caller.h \
|
||||||
src/include/switch_buffer.h \
|
src/include/switch_buffer.h \
|
||||||
src/include/switch_event.h \
|
src/include/switch_event.h \
|
||||||
src/include/switch_resample.h
|
src/include/switch_resample.h \
|
||||||
|
src/include/switch_ivr.h
|
||||||
|
|
||||||
lib_LTLIBRARIES = libfreeswitch.la
|
lib_LTLIBRARIES = libfreeswitch.la
|
||||||
libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g
|
libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g
|
||||||
|
@ -436,6 +440,7 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_console.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_console.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_core.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_core.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_event.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_event.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_ivr.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_loadable_module.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_loadable_module.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_mutex.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_mutex.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_resample.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_resample.Plo@am__quote@
|
||||||
|
@ -539,6 +544,13 @@ libfreeswitch_la-switch_resample.lo: src/switch_resample.c
|
||||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_resample.lo `test -f 'src/switch_resample.c' || echo '$(srcdir)/'`src/switch_resample.c
|
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_resample.lo `test -f 'src/switch_resample.c' || echo '$(srcdir)/'`src/switch_resample.c
|
||||||
|
|
||||||
|
libfreeswitch_la-switch_ivr.lo: src/switch_ivr.c
|
||||||
|
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -MT libfreeswitch_la-switch_ivr.lo -MD -MP -MF "$(DEPDIR)/libfreeswitch_la-switch_ivr.Tpo" -c -o libfreeswitch_la-switch_ivr.lo `test -f 'src/switch_ivr.c' || echo '$(srcdir)/'`src/switch_ivr.c; \
|
||||||
|
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libfreeswitch_la-switch_ivr.Tpo" "$(DEPDIR)/libfreeswitch_la-switch_ivr.Plo"; else rm -f "$(DEPDIR)/libfreeswitch_la-switch_ivr.Tpo"; exit 1; fi
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/switch_ivr.c' object='libfreeswitch_la-switch_ivr.lo' libtool=yes @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_ivr.lo `test -f 'src/switch_ivr.c' || echo '$(srcdir)/'`src/switch_ivr.c
|
||||||
|
|
||||||
freeswitch-switch.o: src/switch.c
|
freeswitch-switch.o: src/switch.c
|
||||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(freeswitch_CFLAGS) $(CFLAGS) -MT freeswitch-switch.o -MD -MP -MF "$(DEPDIR)/freeswitch-switch.Tpo" -c -o freeswitch-switch.o `test -f 'src/switch.c' || echo '$(srcdir)/'`src/switch.c; \
|
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(freeswitch_CFLAGS) $(CFLAGS) -MT freeswitch-switch.o -MD -MP -MF "$(DEPDIR)/freeswitch-switch.Tpo" -c -o freeswitch-switch.o `test -f 'src/switch.c' || echo '$(srcdir)/'`src/switch.c; \
|
||||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/freeswitch-switch.Tpo" "$(DEPDIR)/freeswitch-switch.Po"; else rm -f "$(DEPDIR)/freeswitch-switch.Tpo"; exit 1; fi
|
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/freeswitch-switch.Tpo" "$(DEPDIR)/freeswitch-switch.Po"; else rm -f "$(DEPDIR)/freeswitch-switch.Tpo"; exit 1; fi
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
[extensions]
|
[extensions]
|
||||||
|
|
||||||
1000 => playback /tmp/siriusraw.raw
|
1000 => playback /tmp/siriusraw.raw
|
||||||
888 => bridge woomera/888@10.200.68.194
|
|
||||||
|
; to time from a timer instead of from the input stream use
|
||||||
|
; 1000 => playback /tmp/siriusraw.raw soft
|
||||||
|
|
||||||
|
; call the freeswitch conference
|
||||||
|
888 => bridge iax/guest@10.200.68.194/888
|
||||||
|
|
|
@ -45,6 +45,18 @@ extern "C" {
|
||||||
#define SWITCH_MAX_CODECS 30
|
#define SWITCH_MAX_CODECS 30
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\enum switch_ivr_option_t
|
||||||
|
\brief Possible options related to ivr functions
|
||||||
|
<pre>
|
||||||
|
SWITCH_IVR_OPTION_SYNC - synchronous (do everyting in the forground)
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
SWITCH_IVR_OPTION_SYNC = (1 << 0)
|
||||||
|
} switch_ivr_option_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\enum switch_core_session_message_t
|
\enum switch_core_session_message_t
|
||||||
\brief Possible types of messages for inter-session communication
|
\brief Possible types of messages for inter-session communication
|
||||||
|
@ -354,6 +366,7 @@ typedef switch_status (*switch_waitfor_read_hook)(switch_core_session *, int, in
|
||||||
typedef switch_status (*switch_waitfor_write_hook)(switch_core_session *, int, int);
|
typedef switch_status (*switch_waitfor_write_hook)(switch_core_session *, int, int);
|
||||||
typedef switch_status (*switch_send_dtmf_hook)(switch_core_session *, char *);
|
typedef switch_status (*switch_send_dtmf_hook)(switch_core_session *, char *);
|
||||||
typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen);
|
typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen);
|
||||||
|
typedef switch_status (*switch_dtmf_callback_function)(switch_core_session *session, char *dtmf);
|
||||||
|
|
||||||
/* things we don't deserve to know about */
|
/* things we don't deserve to know about */
|
||||||
|
|
||||||
|
|
|
@ -30,151 +30,47 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <sys/types.h>
|
#include <switch_ivr.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
|
|
||||||
static const char modname[] = "mod_playback";
|
static const char modname[] = "mod_playback";
|
||||||
|
|
||||||
|
/*
|
||||||
|
dtmf handler function you can hook up to be executed when a digit is dialed during playback
|
||||||
|
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
|
||||||
|
*/
|
||||||
|
static switch_status on_dtmf(switch_core_session *session, char *dtmf)
|
||||||
|
{
|
||||||
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Digits %s\n", dtmf);
|
||||||
|
|
||||||
|
if (*dtmf == '*') {
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void playback_function(switch_core_session *session, char *data)
|
void playback_function(switch_core_session *session, char *data)
|
||||||
{
|
{
|
||||||
switch_channel *channel;
|
switch_channel *channel;
|
||||||
short buf[960];
|
char *timer_name = NULL;
|
||||||
char dtmf[128];
|
char *file_name = NULL;
|
||||||
int interval = 0, samples = 0;
|
|
||||||
size_t len = 0, ilen = 0;
|
file_name = switch_core_session_strdup(session, data);
|
||||||
switch_frame write_frame;
|
|
||||||
switch_timer timer;
|
if ((timer_name = strchr(file_name, ' '))) {
|
||||||
switch_core_thread_session thread_session;
|
*timer_name++ = '\0';
|
||||||
switch_codec codec;
|
}
|
||||||
switch_memory_pool *pool = switch_core_session_get_pool(session);
|
|
||||||
switch_file_handle fh;
|
|
||||||
char *codec_name;
|
|
||||||
int x;
|
|
||||||
int stream_id;
|
|
||||||
|
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
assert(channel != NULL);
|
assert(channel != NULL);
|
||||||
|
|
||||||
if (switch_core_file_open(&fh,
|
if (switch_ivr_play_file(session, file_name, timer_name, on_dtmf) != SWITCH_STATUS_SUCCESS) {
|
||||||
data,
|
|
||||||
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
|
|
||||||
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_channel_hangup(channel);
|
switch_channel_hangup(channel);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_answer(channel);
|
|
||||||
|
|
||||||
write_frame.data = buf;
|
|
||||||
write_frame.buflen = sizeof(buf);
|
|
||||||
|
|
||||||
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s %dhz %d channels\n", data, fh.samplerate, fh.channels);
|
|
||||||
|
|
||||||
interval = 20;
|
|
||||||
samples = (fh.samplerate / 50) * fh.channels;
|
|
||||||
len = samples * 2;
|
|
||||||
|
|
||||||
codec_name = "L16";
|
|
||||||
|
|
||||||
if (switch_core_codec_init(&codec,
|
|
||||||
codec_name,
|
|
||||||
fh.samplerate,
|
|
||||||
interval,
|
|
||||||
fh.channels,
|
|
||||||
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
|
|
||||||
NULL, pool) == SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
|
|
||||||
write_frame.codec = &codec;
|
|
||||||
} else {
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n",
|
|
||||||
codec_name, fh.samplerate, fh.channels, interval);
|
|
||||||
switch_core_file_close(&fh);
|
|
||||||
switch_channel_hangup(channel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n");
|
|
||||||
switch_core_codec_destroy(&codec);
|
|
||||||
switch_core_file_close(&fh);
|
|
||||||
switch_channel_hangup(channel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
write_frame.rate = fh.samplerate;
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
|
|
||||||
|
|
||||||
/* start a thread to absorb incoming audio */
|
|
||||||
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
|
|
||||||
switch_core_service_session(session, &thread_session, stream_id);
|
|
||||||
}
|
|
||||||
ilen = samples;
|
|
||||||
while (switch_channel_get_state(channel) == CS_EXECUTE) {
|
|
||||||
int done = 0;
|
|
||||||
|
|
||||||
if (switch_channel_has_dtmf(channel)) {
|
|
||||||
switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF [%s]\n", dtmf);
|
|
||||||
|
|
||||||
switch (*dtmf) {
|
|
||||||
case '*':
|
|
||||||
done = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_core_file_read(&fh, buf, &ilen);
|
|
||||||
|
|
||||||
if (ilen <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
write_frame.datalen = ilen * 2;
|
|
||||||
write_frame.samples = (int) ilen;
|
|
||||||
#ifdef SWAP_LINEAR
|
|
||||||
switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
|
|
||||||
if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n");
|
|
||||||
done = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((x = switch_core_timer_next(&timer)) < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "done playing file\n");
|
|
||||||
switch_core_file_close(&fh);
|
|
||||||
|
|
||||||
//switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
|
|
||||||
|
|
||||||
switch_core_timer_destroy(&timer);
|
|
||||||
|
|
||||||
switch_core_codec_destroy(&codec);
|
|
||||||
|
|
||||||
//switch_channel_hangup(channel);
|
|
||||||
|
|
||||||
/* End the audio absorbing thread */
|
|
||||||
switch_core_thread_session_end(&thread_session);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const switch_application_interface playback_application_interface = {
|
static const switch_application_interface playback_application_interface = {
|
||||||
|
|
Loading…
Reference in New Issue