libfreeswitch_la-switch_mutex.lo \
libfreeswitch_la-switch_utils.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)
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
src/include/switch_caller.h \
src/include/switch_buffer.h \
src/include/switch_event.h \
+src/include/switch_ivr.h\
src/switch_buffer.c \
src/switch_caller.c \
src/switch_channel.c \
src/switch_mutex.c \
src/switch_utils.c \
src/switch_event.c \
-src/switch_resample.c
+src/switch_resample.c \
+src/switch_ivr.c
#bindir = $(PREFIX)/bin
src/include/switch_caller.h \
src/include/switch_buffer.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
libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g
@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_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_mutex.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_resample.Plo@am__quote@
@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
+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
@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
*
*/
#include <switch.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <switch_ivr.h>
-static const char modname[] = "mod_playback";
+static const char modname[] = "mod_playback";
-void playback_function(switch_core_session *session, char *data)
+/*
+ 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_channel *channel;
- short buf[960];
- char dtmf[128];
- int interval = 0, samples = 0;
- size_t len = 0, ilen = 0;
- switch_frame write_frame;
- switch_timer timer;
- switch_core_thread_session thread_session;
- 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);
- assert(channel != NULL);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Digits %s\n", dtmf);
- if (switch_core_file_open(&fh,
- data,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
- switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_channel_hangup(channel);
- return;
+ if (*dtmf == '*') {
+ return SWITCH_STATUS_FALSE;
}
+
+ return SWITCH_STATUS_SUCCESS;
+}
- 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;
+void playback_function(switch_core_session *session, char *data)
+{
+ switch_channel *channel;
+ char *timer_name = NULL;
+ char *file_name = NULL;
- codec_name = "L16";
+ file_name = switch_core_session_strdup(session, data);
- 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 ((timer_name = strchr(file_name, ' '))) {
+ *timer_name++ = '\0';
}
- 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);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- /* 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;
- }
+ if (switch_ivr_play_file(session, file_name, timer_name, on_dtmf) != SWITCH_STATUS_SUCCESS) {
+ switch_channel_hangup(channel);
}
-
- 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 = {